ELF: Updated comments for ET_EXEC and ET_DYN

Message ID 20200525182830.744267-1-hjl.tools@gmail.com
State New
Headers show
Series
  • ELF: Updated comments for ET_EXEC and ET_DYN
Related show

Commit Message

include/elf/common.h has

 #define ET_EXEC         2       /* Executable file */
 #define ET_DYN          3       /* Shared object file */

These predate PIE:

https://groups.google.com/forum/#!topic/generic-abi/mBKlSNldFW4

Updated comments to

 #define ET_EXEC         2       /* Position-dependent executable file */
 #define ET_DYN          3       /* Position-independent executable or
                                    shared object file */

	* elf/common.h: Update comments for ET_EXEC and ET_DYN.
---
 include/ChangeLog    | 4 ++++
 include/elf/common.h | 5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)

-- 
2.26.2

Comments

Fangrui Song May 26, 2020, 5:45 p.m. | #1
Looks good. Ali in the generic-abi proposed a more generic form:

#define ET_EXEC 2 /* Position-dependent object */
#define ET_DYN 3 /* Position-independent object */


I just filed https://sourceware.org/bugzilla/show_bug.cgi?id=26047 We
may consider disallowing ET_EXEC as linker input.
Happy to know if there are legitimate cases, though.

On Mon, May 25, 2020 at 11:28 AM H.J. Lu via Binutils
<binutils@sourceware.org> wrote:
>

> include/elf/common.h has

>

>  #define ET_EXEC         2       /* Executable file */

>  #define ET_DYN          3       /* Shared object file */

>

> These predate PIE:

>

> https://groups.google.com/forum/#!topic/generic-abi/mBKlSNldFW4

>

> Updated comments to

>

>  #define ET_EXEC         2       /* Position-dependent executable file */

>  #define ET_DYN          3       /* Position-independent executable or

>                                     shared object file */

>

>         * elf/common.h: Update comments for ET_EXEC and ET_DYN.

> ---

>  include/ChangeLog    | 4 ++++

>  include/elf/common.h | 5 +++--

>  2 files changed, 7 insertions(+), 2 deletions(-)

>

> diff --git a/include/ChangeLog b/include/ChangeLog

> index c309780544..53f50e513f 100644

> --- a/include/ChangeLog

> +++ b/include/ChangeLog

> @@ -1,3 +1,7 @@

> +2020-05-25  H.J. Lu  <hongjiu.lu@intel.com>

> +

> +       * elf/common.h: Update comments for ET_EXEC and ET_DYN.

> +

>  2020-05-20  Nelson Chu  <nelson.chu@sifive.com>

>

>         * opcode/riscv.h: Include "bfd.h" to support bfd_boolean.

> diff --git a/include/elf/common.h b/include/elf/common.h

> index 26e6fbc8e6..4d94c4fd5b 100644

> --- a/include/elf/common.h

> +++ b/include/elf/common.h

> @@ -91,8 +91,9 @@

>

>  #define ET_NONE                0       /* No file type */

>  #define ET_REL         1       /* Relocatable file */

> -#define ET_EXEC                2       /* Executable file */

> -#define ET_DYN         3       /* Shared object file */

> +#define ET_EXEC                2       /* Position-dependent executable file */

> +#define ET_DYN         3       /* Position-independent executable or

> +                                  shared object file */

>  #define ET_CORE                4       /* Core file */

>  #define ET_LOOS                0xFE00  /* Operating system-specific */

>  #define ET_HIOS                0xFEFF  /* Operating system-specific */

> --

> 2.26.2

>
Fangrui Song May 30, 2020, 12:59 a.m. | #2
Does https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d871d478061f10b0879c688e2fa941407e9137aa
start to set DF_1_PIE on non-Solaris platforms (e.g. Linux) as well?

I guess previous versions of binutils don't set the flag.

This flag makes sense to me, because it makes the distinction of
executable/shared object for ET_DYN.

On Tue, May 26, 2020 at 10:45 AM Fangrui Song <i@maskray.me> wrote:
>

> Looks good. Ali in the generic-abi proposed a more generic form:

>

> #define ET_EXEC 2 /* Position-dependent object */

> #define ET_DYN 3 /* Position-independent object */

>

>

> I just filed https://sourceware.org/bugzilla/show_bug.cgi?id=26047 We

> may consider disallowing ET_EXEC as linker input.

> Happy to know if there are legitimate cases, though.

>

> On Mon, May 25, 2020 at 11:28 AM H.J. Lu via Binutils

> <binutils@sourceware.org> wrote:

> >

> > include/elf/common.h has

> >

> >  #define ET_EXEC         2       /* Executable file */

> >  #define ET_DYN          3       /* Shared object file */

> >

> > These predate PIE:

> >

> > https://groups.google.com/forum/#!topic/generic-abi/mBKlSNldFW4

> >

> > Updated comments to

> >

> >  #define ET_EXEC         2       /* Position-dependent executable file */

> >  #define ET_DYN          3       /* Position-independent executable or

> >                                     shared object file */

> >

> >         * elf/common.h: Update comments for ET_EXEC and ET_DYN.

> > ---

> >  include/ChangeLog    | 4 ++++

> >  include/elf/common.h | 5 +++--

> >  2 files changed, 7 insertions(+), 2 deletions(-)

> >

> > diff --git a/include/ChangeLog b/include/ChangeLog

> > index c309780544..53f50e513f 100644

> > --- a/include/ChangeLog

> > +++ b/include/ChangeLog

> > @@ -1,3 +1,7 @@

> > +2020-05-25  H.J. Lu  <hongjiu.lu@intel.com>

> > +

> > +       * elf/common.h: Update comments for ET_EXEC and ET_DYN.

> > +

> >  2020-05-20  Nelson Chu  <nelson.chu@sifive.com>

> >

> >         * opcode/riscv.h: Include "bfd.h" to support bfd_boolean.

> > diff --git a/include/elf/common.h b/include/elf/common.h

> > index 26e6fbc8e6..4d94c4fd5b 100644

> > --- a/include/elf/common.h

> > +++ b/include/elf/common.h

> > @@ -91,8 +91,9 @@

> >

> >  #define ET_NONE                0       /* No file type */

> >  #define ET_REL         1       /* Relocatable file */

> > -#define ET_EXEC                2       /* Executable file */

> > -#define ET_DYN         3       /* Shared object file */

> > +#define ET_EXEC                2       /* Position-dependent executable file */

> > +#define ET_DYN         3       /* Position-independent executable or

> > +                                  shared object file */

> >  #define ET_CORE                4       /* Core file */

> >  #define ET_LOOS                0xFE00  /* Operating system-specific */

> >  #define ET_HIOS                0xFEFF  /* Operating system-specific */

> > --

> > 2.26.2

> >
On Fri, May 29, 2020 at 6:06 PM Fangrui Song <i@maskray.me> wrote:
>

> Does https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d871d478061f10b0879c688e2fa941407e9137aa

> start to set DF_1_PIE on non-Solaris platforms (e.g. Linux) as well?


[hjl@gnu-cfl-2 x86-gcc]$ readelf -h /bin/ld | grep Type
  Type:                              DYN (Shared object file)
[hjl@gnu-cfl-2 x86-gcc]$ readelf -d /bin/ld | grep PIE
 0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE
[hjl@gnu-cfl-2 x86-gcc]$

-- 
H.J.
Fangrui Song May 30, 2020, 5:17 p.m. | #4
I saw https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/testsuite/ld-elf/pie.d;h=d68b962ca328a981dda980848b794ffd639780df;hb=5fe2850dd96483f176858fd75c098313d5b20bc2
It is a deliberate choice on non-Solaris platforms.

On Fri, May 29, 2020 at 6:10 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>

> On Fri, May 29, 2020 at 6:06 PM Fangrui Song <i@maskray.me> wrote:

> >

> > Does https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d871d478061f10b0879c688e2fa941407e9137aa

> > start to set DF_1_PIE on non-Solaris platforms (e.g. Linux) as well?

>

> [hjl@gnu-cfl-2 x86-gcc]$ readelf -h /bin/ld | grep Type

>   Type:                              DYN (Shared object file)

> [hjl@gnu-cfl-2 x86-gcc]$ readelf -d /bin/ld | grep PIE

>  0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE

> [hjl@gnu-cfl-2 x86-gcc]$

>

> --

> H.J.
On 5/30/20 2:10 AM, H.J. Lu via Binutils wrote:
> On Fri, May 29, 2020 at 6:06 PM Fangrui Song <i@maskray.me> wrote:

>>

>> Does https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d871d478061f10b0879c688e2fa941407e9137aa

>> start to set DF_1_PIE on non-Solaris platforms (e.g. Linux) as well?

> 

> [hjl@gnu-cfl-2 x86-gcc]$ readelf -h /bin/ld | grep Type

>   Type:                              DYN (Shared object file)

> [hjl@gnu-cfl-2 x86-gcc]$ readelf -d /bin/ld | grep PIE

>  0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE

> [hjl@gnu-cfl-2 x86-gcc]$

> 


Gold doesn't set it though: https://sourceware.org/bugzilla/show_bug.cgi?id=26039

Thanks,
Pedro Alves

Patch

diff --git a/include/ChangeLog b/include/ChangeLog
index c309780544..53f50e513f 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,7 @@ 
+2020-05-25  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* elf/common.h: Update comments for ET_EXEC and ET_DYN.
+
 2020-05-20  Nelson Chu  <nelson.chu@sifive.com>
 
 	* opcode/riscv.h: Include "bfd.h" to support bfd_boolean.
diff --git a/include/elf/common.h b/include/elf/common.h
index 26e6fbc8e6..4d94c4fd5b 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -91,8 +91,9 @@ 
 
 #define ET_NONE		0	/* No file type */
 #define ET_REL		1	/* Relocatable file */
-#define ET_EXEC		2	/* Executable file */
-#define ET_DYN		3	/* Shared object file */
+#define ET_EXEC		2	/* Position-dependent executable file */
+#define ET_DYN		3	/* Position-independent executable or
+				   shared object file */
 #define ET_CORE		4	/* Core file */
 #define ET_LOOS		0xFE00	/* Operating system-specific */
 #define ET_HIOS		0xFEFF	/* Operating system-specific */