PATCH: Fix readelf segment map

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

PATCH: Fix readelf segment map

H.J. Lu-27
http://sourceware.org/ml/binutils/2004-09/msg00227.html

removed .tbss sections from the PT_LOAD segment map where it belongs.
I am checking in this patch to fix it.


H.J.
---
binutils/

2006-02-02  H.J. Lu  <[hidden email]>

        * readelf.c (process_program_headers): Undo the change made on
        2004-09-22.  Match PT_DYNAMIC segment only with SHT_DYNAMIC
        sections.

ld/testsuite/

2006-02-02  H.J. Lu  <[hidden email]>

        * ld-i386/tlsbin.rd: Update for changed segment map.
        * ld-i386/tlsnopic.rd: Likewise.
        * ld-i386/tlspic.rd: Likewise.
        * ld-powerpc/tlsexe.r: Likewise.
        * ld-powerpc/tlsexe32.r: Likewise.
        * ld-powerpc/tlsexetoc.r: Likewise.
        * ld-powerpc/tlsso.r: Likewise.
        * ld-powerpc/tlsso32.r: Likewise.
        * ld-powerpc/tlstocso.r: Likewise.
        * ld-s390/tlsbin.rd: Likewise.
        * ld-s390/tlsbin_64.rd: Likewise.
        * ld-s390/tlspic.rd: Likewise.
        * ld-s390/tlspic_64.rd: Likewise.
        * ld-sh/tlsbin-2.d: Likewise.
        * ld-sh/tlspic-2.d: Likewise.
        * ld-x86-64/tlsbin.rd: Likewise.
        * ld-x86-64/tlspic.rd: Likewise.

--- binutils/binutils/readelf.c.tls 2006-01-20 08:53:54.000000000 -0800
+++ binutils/binutils/readelf.c 2006-02-02 13:38:06.000000000 -0800
@@ -3405,6 +3405,10 @@ process_program_headers (FILE *file)
   for (j = 1; j < elf_header.e_shnum; j++, section++)
     {
       if (section->sh_size > 0
+  /* PT_DYNAMIC segment contains only SHT_DYNAMIC
+     sections.  */
+  && (segment->p_type != PT_DYNAMIC
+      || section->sh_type == SHT_DYNAMIC)
   /* Compare allocated sections by VMA, unallocated
      sections by file offset.  */
   && (section->sh_flags & SHF_ALLOC
@@ -3413,12 +3417,7 @@ process_program_headers (FILE *file)
  <= segment->p_vaddr + segment->p_memsz)
       : ((bfd_vma) section->sh_offset >= segment->p_offset
  && (section->sh_offset + section->sh_size
-     <= segment->p_offset + segment->p_filesz)))
-  /* .tbss is special.  It doesn't contribute memory space
-     to normal segments.  */
-  && (!((section->sh_flags & SHF_TLS) != 0
- && section->sh_type == SHT_NOBITS)
-      || segment->p_type == PT_TLS))
+     <= segment->p_offset + segment->p_filesz))))
  printf ("%s ", SECTION_NAME (section));
     }
 
--- binutils/ld/testsuite/ld-i386/tlsbin.rd.tls 2005-08-24 08:27:16.000000000 -0700
+++ binutils/ld/testsuite/ld-i386/tlsbin.rd 2006-02-02 13:22:11.000000000 -0800
@@ -50,7 +50,7 @@ Program Headers:
    00 +
    01 +.interp *
    02 +.interp .hash .dynsym .dynstr .rel.dyn .rel.plt .plt .text *
-   03 +.tdata .dynamic .got .got.plt *
+   03 +.tdata .tbss .dynamic .got .got.plt *
    04 +.dynamic *
    05 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-i386/tlsbindesc.rd.tls 2006-01-18 13:07:49.000000000 -0800
+++ binutils/ld/testsuite/ld-i386/tlsbindesc.rd 2006-02-02 13:22:05.000000000 -0800
@@ -48,7 +48,7 @@ Program Headers:
    00 +
    01 +.interp *
    02 +.interp .hash .dynsym .dynstr .rel.dyn .text *
-   03 +.tdata .dynamic .got .got.plt *
+   03 +.tdata .tbss .dynamic .got .got.plt *
    04 +.dynamic *
    05 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-i386/tlsdesc.rd.tls 2006-01-18 13:07:49.000000000 -0800
+++ binutils/ld/testsuite/ld-i386/tlsdesc.rd 2006-02-02 13:22:17.000000000 -0800
@@ -43,7 +43,7 @@ Program Headers:
  Section to Segment mapping:
   Segment Sections...
    00 +.hash .dynsym .dynstr .rel.dyn .rel.plt .text *
-   01 +.tdata .dynamic .got .got.plt *
+   01 +.tdata .tbss .dynamic .got .got.plt *
    02 +.dynamic *
    03 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-i386/tlsnopic.rd.tls 2005-08-24 08:27:16.000000000 -0700
+++ binutils/ld/testsuite/ld-i386/tlsnopic.rd 2006-02-02 13:22:51.000000000 -0800
@@ -41,7 +41,7 @@ Program Headers:
  Section to Segment mapping:
   Segment Sections...
    00 +.hash .dynsym .dynstr .rel.dyn .text *
-   01 +.dynamic .got .got.plt *
+   01 +.tbss .dynamic .got .got.plt *
    02 +.dynamic *
    03 +.tbss *
 
--- binutils/ld/testsuite/ld-i386/tlspic.rd.tls 2005-08-24 08:27:16.000000000 -0700
+++ binutils/ld/testsuite/ld-i386/tlspic.rd 2006-02-02 13:23:01.000000000 -0800
@@ -44,7 +44,7 @@ Program Headers:
  Section to Segment mapping:
   Segment Sections...
    00 +.hash .dynsym .dynstr .rel.dyn .rel.plt .plt .text *
-   01 +.tdata .dynamic .got .got.plt *
+   01 +.tdata .tbss .dynamic .got .got.plt *
    02 +.dynamic *
    03 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-powerpc/tlsexe.r.tls 2005-08-24 08:27:18.000000000 -0700
+++ binutils/ld/testsuite/ld-powerpc/tlsexe.r 2006-02-02 13:52:39.000000000 -0800
@@ -47,7 +47,7 @@ Program Headers:
  +0+ +
  +01 +\.interp
  +02 +\.interp \.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +03 +\.tdata \.dynamic \.got \.plt
+ +03 +\.tdata \.tbss \.dynamic \.got \.plt
  +04 +\.dynamic
  +05 +\.tdata \.tbss
 
--- binutils/ld/testsuite/ld-powerpc/tlsexe32.r.tls 2005-08-24 08:27:18.000000000 -0700
+++ binutils/ld/testsuite/ld-powerpc/tlsexe32.r 2006-02-02 13:52:32.000000000 -0800
@@ -46,7 +46,7 @@ Program Headers:
  +00 +
  +01 +\.interp
  +02 +\.interp \.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +03 +\.tdata \.dynamic \.got \.plt
+ +03 +\.tdata \.tbss \.dynamic \.got \.plt
  +04 +\.dynamic
  +05 +\.tdata \.tbss
 
--- binutils/ld/testsuite/ld-powerpc/tlsexetoc.r.tls 2005-08-24 08:27:18.000000000 -0700
+++ binutils/ld/testsuite/ld-powerpc/tlsexetoc.r 2006-02-02 13:52:46.000000000 -0800
@@ -47,7 +47,7 @@ Program Headers:
  +0+ +
  +01 +\.interp
  +02 +\.interp \.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +03 +\.tdata \.dynamic \.got \.plt
+ +03 +\.tdata \.tbss \.dynamic \.got \.plt
  +04 +\.dynamic
  +05 +\.tdata \.tbss
 
--- binutils/ld/testsuite/ld-powerpc/tlsso.r.tls 2005-08-24 08:27:18.000000000 -0700
+++ binutils/ld/testsuite/ld-powerpc/tlsso.r 2006-02-02 13:53:06.000000000 -0800
@@ -40,7 +40,7 @@ Program Headers:
  Section to Segment mapping:
  +Segment Sections\.\.\.
  +0+ +\.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +01 +\.tdata \.dynamic \.got \.plt
+ +01 +\.tdata \.tbss \.dynamic \.got \.plt
  +02 +\.dynamic
  +03 +\.tdata \.tbss
 
--- binutils/ld/testsuite/ld-powerpc/tlsso32.r.tls 2005-08-24 08:27:19.000000000 -0700
+++ binutils/ld/testsuite/ld-powerpc/tlsso32.r 2006-02-02 13:52:53.000000000 -0800
@@ -39,7 +39,7 @@ Program Headers:
  Section to Segment mapping:
  +Segment Sections\.\.\.
  +0+ +\.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +01 +\.tdata \.dynamic \.got \.plt
+ +01 +\.tdata \.tbss \.dynamic \.got \.plt
  +02 +\.dynamic
  +03 +\.tdata \.tbss
 
--- binutils/ld/testsuite/ld-powerpc/tlstocso.r.tls 2005-08-24 08:27:19.000000000 -0700
+++ binutils/ld/testsuite/ld-powerpc/tlstocso.r 2006-02-02 13:53:13.000000000 -0800
@@ -40,7 +40,7 @@ Program Headers:
  Section to Segment mapping:
  +Segment Sections\.\.\.
  +0+ +\.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.text
- +01 +\.tdata \.dynamic \.got \.plt
+ +01 +\.tdata \.tbss \.dynamic \.got \.plt
  +02 +\.dynamic
  +03 +\.tdata \.tbss
 
--- binutils/ld/testsuite/ld-s390/tlsbin.rd.tls 2005-08-24 08:27:19.000000000 -0700
+++ binutils/ld/testsuite/ld-s390/tlsbin.rd 2006-02-02 13:47:34.000000000 -0800
@@ -49,7 +49,7 @@ Program Headers:
    00 *
    01 +.interp *
    02 +.interp .hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
-   03 +.tdata .dynamic .got *
+   03 +.tdata .tbss .dynamic .got *
    04 +.dynamic *
    05 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-s390/tlsbin_64.rd.tls 2005-08-24 08:27:19.000000000 -0700
+++ binutils/ld/testsuite/ld-s390/tlsbin_64.rd 2006-02-02 13:47:27.000000000 -0800
@@ -49,7 +49,7 @@ Program Headers:
    00 *
    01 +.interp *
    02 +.interp .hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
-   03 +.tdata .dynamic .got *
+   03 +.tdata .tbss .dynamic .got *
    04 +.dynamic *
    05 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-s390/tlspic.rd.tls 2005-08-24 08:27:19.000000000 -0700
+++ binutils/ld/testsuite/ld-s390/tlspic.rd 2006-02-02 13:47:46.000000000 -0800
@@ -43,7 +43,7 @@ Program Headers:
  Section to Segment mapping:
   Segment Sections...
  +00 +.hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text
- +01 +.tdata .dynamic .got
+ +01 +.tdata .tbss .dynamic .got
  +02 +.dynamic
  +03 +.tdata .tbss
 
--- binutils/ld/testsuite/ld-s390/tlspic_64.rd.tls 2005-08-24 08:27:19.000000000 -0700
+++ binutils/ld/testsuite/ld-s390/tlspic_64.rd 2006-02-02 13:47:40.000000000 -0800
@@ -43,7 +43,7 @@ Program Headers:
  Section to Segment mapping:
   Segment Sections...
    00 +.hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
-   01 +.tdata .dynamic .got *
+   01 +.tdata .tbss .dynamic .got *
    02 +.dynamic *
    03 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-sh/tlsbin-2.d.tls 2005-08-24 08:27:19.000000000 -0700
+++ binutils/ld/testsuite/ld-sh/tlsbin-2.d 2006-02-02 13:48:47.000000000 -0800
@@ -50,7 +50,7 @@ Program Headers:
    00 +
    01 +\.interp *
    02 +\.interp \.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.plt \.text *
-   03 +\.tdata \.dynamic \.got *
+   03 +\.tdata \.tbss \.dynamic \.got *
    04 +\.dynamic *
    05 +\.tdata \.tbss *
 
--- binutils/ld/testsuite/ld-sh/tlspic-2.d.tls 2005-08-24 08:27:19.000000000 -0700
+++ binutils/ld/testsuite/ld-sh/tlspic-2.d 2006-02-02 13:49:00.000000000 -0800
@@ -44,7 +44,7 @@ Program Headers:
  Section to Segment mapping:
   Segment Sections\.\.\.
    00 +\.hash \.dynsym \.dynstr \.rela\.dyn \.rela\.plt \.plt \.text *
-   01 +\.tdata \.dynamic \.got *
+   01 +\.tdata \.tbss .dynamic \.got *
    02 +\.dynamic *
    03 +\.tdata \.tbss *
 
--- binutils/ld/testsuite/ld-x86-64/tlsbin.rd.tls 2005-08-24 08:27:20.000000000 -0700
+++ binutils/ld/testsuite/ld-x86-64/tlsbin.rd 2006-02-02 13:21:05.000000000 -0800
@@ -50,7 +50,7 @@ Program Headers:
    00 *
    01 +.interp *
    02 +.interp .hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
-   03 +.tdata .dynamic .got .got.plt *
+   03 +.tdata .tbss .dynamic .got .got.plt *
    04 +.dynamic *
    05 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-x86-64/tlsbindesc.rd.tls 2006-01-18 13:07:49.000000000 -0800
+++ binutils/ld/testsuite/ld-x86-64/tlsbindesc.rd 2006-02-02 13:20:53.000000000 -0800
@@ -48,7 +48,7 @@ Program Headers:
    00 *
    01 +.interp *
    02 +.interp .hash .dynsym .dynstr .rela.dyn .text *
-   03 +.tdata .dynamic .got .got.plt *
+   03 +.tdata .tbss .dynamic .got .got.plt *
    04 +.dynamic *
    05 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-x86-64/tlsdesc.rd.tls 2006-01-18 13:07:49.000000000 -0800
+++ binutils/ld/testsuite/ld-x86-64/tlsdesc.rd 2006-02-02 13:21:12.000000000 -0800
@@ -44,7 +44,7 @@ Program Headers:
  Section to Segment mapping:
   Segment Sections...
    00 +.hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
-   01 +.tdata .dynamic .got .got.plt *
+   01 +.tdata .tbss .dynamic .got .got.plt *
    02 +.dynamic *
    03 +.tdata .tbss *
 
--- binutils/ld/testsuite/ld-x86-64/tlspic.rd.tls 2005-08-24 08:27:20.000000000 -0700
+++ binutils/ld/testsuite/ld-x86-64/tlspic.rd 2006-02-02 13:21:20.000000000 -0800
@@ -44,7 +44,7 @@ Program Headers:
  Section to Segment mapping:
   Segment Sections...
    00 +.hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
-   01 +.tdata .dynamic .got .got.plt *
+   01 +.tdata .tbss .dynamic .got .got.plt *
    02 +.dynamic *
    03 +.tdata .tbss *
 
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: Fix readelf segment map

H.J. Lu-27
Apparently, I was wrong. I tried to fix

[hjl@gnu-13 strip-4]$ readelf -l a.out

Elf file type is EXEC (Executable file)
Entry point 0x401108
There are 3 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000400000
0x0000000000400000
                 0x00000000000011fc 0x00000000000011fc  R E    100000
  LOAD           0x00000000000011fc 0x00000000005011fc
0x00000000005011fc
                 0x000000000000009c 0x000000000000009c  RW     100000
  TLS            0x00000000000011fc 0x00000000005011fc
0x00000000005011fc
                 0x0000000000000080 0x00000000000000c0  R      1

 Section to Segment mapping:
  Segment Sections...
   00     .text
   01     .tdata .got.plt
   02     .tdata .tbss .got.plt

The last one should be

   02     .tdata .tbss

I backed out my last change.


H.J.
---
On Thu, Feb 02, 2006 at 02:00:53PM -0800, H. J. Lu wrote:

> http://sourceware.org/ml/binutils/2004-09/msg00227.html
>
> removed .tbss sections from the PT_LOAD segment map where it belongs.
> I am checking in this patch to fix it.
>
>
> H.J.
> ---
> binutils/
>
> 2006-02-02  H.J. Lu  <[hidden email]>
>
> * readelf.c (process_program_headers): Undo the change made on
> 2004-09-22.  Match PT_DYNAMIC segment only with SHT_DYNAMIC
> sections.
>
> ld/testsuite/
>
> 2006-02-02  H.J. Lu  <[hidden email]>
>
> * ld-i386/tlsbin.rd: Update for changed segment map.
> * ld-i386/tlsnopic.rd: Likewise.
> * ld-i386/tlspic.rd: Likewise.
> * ld-powerpc/tlsexe.r: Likewise.
> * ld-powerpc/tlsexe32.r: Likewise.
> * ld-powerpc/tlsexetoc.r: Likewise.
> * ld-powerpc/tlsso.r: Likewise.
> * ld-powerpc/tlsso32.r: Likewise.
> * ld-powerpc/tlstocso.r: Likewise.
> * ld-s390/tlsbin.rd: Likewise.
> * ld-s390/tlsbin_64.rd: Likewise.
> * ld-s390/tlspic.rd: Likewise.
> * ld-s390/tlspic_64.rd: Likewise.
> * ld-sh/tlsbin-2.d: Likewise.
> * ld-sh/tlspic-2.d: Likewise.
> * ld-x86-64/tlsbin.rd: Likewise.
> * ld-x86-64/tlspic.rd: Likewise.
>
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: Fix readelf segment map

H.J. Lu-27
On Thu, Feb 02, 2006 at 02:56:11PM -0800, H. J. Lu wrote:

> Apparently, I was wrong. I tried to fix
>
> [hjl@gnu-13 strip-4]$ readelf -l a.out
>
> Elf file type is EXEC (Executable file)
> Entry point 0x401108
> There are 3 program headers, starting at offset 64
>
> Program Headers:
>   Type           Offset             VirtAddr           PhysAddr
>                  FileSiz            MemSiz              Flags  Align
>   LOAD           0x0000000000000000 0x0000000000400000
> 0x0000000000400000
>                  0x00000000000011fc 0x00000000000011fc  R E    100000
>   LOAD           0x00000000000011fc 0x00000000005011fc
> 0x00000000005011fc
>                  0x000000000000009c 0x000000000000009c  RW     100000
>   TLS            0x00000000000011fc 0x00000000005011fc
> 0x00000000005011fc
>                  0x0000000000000080 0x00000000000000c0  R      1
>
>  Section to Segment mapping:
>   Segment Sections...
>    00     .text
>    01     .tdata .got.plt
>    02     .tdata .tbss .got.plt
>
> The last one should be
>
>    02     .tdata .tbss
>
> I backed out my last change.
>

That is the updated patch.


H.J.
---
2006-02-02  H.J. Lu  <[hidden email]>

        * readelf.c (process_program_headers): Match PT_TLS segment
        only with SHT_TLS sections.

--- binutils/readelf.c.tls 2006-02-02 14:53:46.000000000 -0800
+++ binutils/readelf.c 2006-02-02 15:02:03.000000000 -0800
@@ -3405,6 +3405,9 @@ process_program_headers (FILE *file)
   for (j = 1; j < elf_header.e_shnum; j++, section++)
     {
       if (section->sh_size > 0
+  /* PT_TLS segment contains only SHF_TLS sections.  */
+  && (segment->p_type != PT_TLS
+      || (section->sh_flags & SHF_TLS) != 0)
   /* Compare allocated sections by VMA, unallocated
      sections by file offset.  */
   && (section->sh_flags & SHF_ALLOC
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: Fix readelf segment map

H.J. Lu-27
I will check in this patch as an obvious fix.


H.J.
---
On Thu, Feb 02, 2006 at 03:04:46PM -0800, H. J. Lu wrote:

> On Thu, Feb 02, 2006 at 02:56:11PM -0800, H. J. Lu wrote:
> > Apparently, I was wrong. I tried to fix
> >
> > [hjl@gnu-13 strip-4]$ readelf -l a.out
> >
> > Elf file type is EXEC (Executable file)
> > Entry point 0x401108
> > There are 3 program headers, starting at offset 64
> >
> > Program Headers:
> >   Type           Offset             VirtAddr           PhysAddr
> >                  FileSiz            MemSiz              Flags  Align
> >   LOAD           0x0000000000000000 0x0000000000400000
> > 0x0000000000400000
> >                  0x00000000000011fc 0x00000000000011fc  R E    100000
> >   LOAD           0x00000000000011fc 0x00000000005011fc
> > 0x00000000005011fc
> >                  0x000000000000009c 0x000000000000009c  RW     100000
> >   TLS            0x00000000000011fc 0x00000000005011fc
> > 0x00000000005011fc
> >                  0x0000000000000080 0x00000000000000c0  R      1
> >
> >  Section to Segment mapping:
> >   Segment Sections...
> >    00     .text
> >    01     .tdata .got.plt
> >    02     .tdata .tbss .got.plt
> >
> > The last one should be
> >
> >    02     .tdata .tbss
> >
> > I backed out my last change.
> >
>
> That is the updated patch.
>
>
> H.J.
> ---
> 2006-02-02  H.J. Lu  <[hidden email]>
>
> * readelf.c (process_program_headers): Match PT_TLS segment
> only with SHT_TLS sections.
>
> --- binutils/readelf.c.tls 2006-02-02 14:53:46.000000000 -0800
> +++ binutils/readelf.c 2006-02-02 15:02:03.000000000 -0800
> @@ -3405,6 +3405,9 @@ process_program_headers (FILE *file)
>    for (j = 1; j < elf_header.e_shnum; j++, section++)
>      {
>        if (section->sh_size > 0
> +  /* PT_TLS segment contains only SHF_TLS sections.  */
> +  && (segment->p_type != PT_TLS
> +      || (section->sh_flags & SHF_TLS) != 0)
>    /* Compare allocated sections by VMA, unallocated
>       sections by file offset.  */
>    && (section->sh_flags & SHF_ALLOC