This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR binutils/16317: Set SHF_INFO_LINK bit for SHT_REL/SHT_RELA sections sections


On Mon, Dec 16, 2013 at 7:53 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Dec 11, 2013 at 4:34 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>> On Wed, Dec 11, 2013 at 10:18:42AM -0800, H.J. Lu wrote:
>>> Hi,
>>>
>>> This patch adds SHF_INFO_LINK to SHT_RELA/SHT_REL sections generated
>>> by ld.  It makes ld behaves the same as gold.  OK to install?
>>>
>>
>> Turns out we should set the HF_INFO_LINK bit for SHT_RELA/SHT_REL
>> sections only when setting the sh_info field.  Here is the new
>> patch.  Tested on Linux/x86 and Linux/x86-64. OK for trunk?
>>
>> Thanks.
>>
>>
>> H.J.
>> ---
>> bfd/
>>
>> 2013-12-11  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>         PR binutils/16317
>>         * elf.c (assign_section_numbers): Set the SHF_INFO_LINK bit for
>>         SHT_REL/SHT_RELA sections when setting the sh_info field.
>>
..
>
> Any objections to set SHF_INFO_LINK for SHT_REL/SHT_RELA
> sections when setting the sh_info field?
>

It is a good pratice to set the SHF_INFO_LINK bit when the sh_info field
represents a section header index.  I checked in this patch.


-- 
H.J.
--
bfd/

    PR binutils/16317
    * elf.c (assign_section_numbers): Set the SHF_INFO_LINK bit for
    SHT_REL/SHT_RELA sections when setting the sh_info field.

binutils/testsuite/

    PR binutils/16317
    * binutils-all/readelf.s: Updated.
    * binutils-all/readelf.s-64: Likewise.

ld/testsuite/

    PR binutils/16317
    * ld-elf/linkinfo1.s: New file.
    * ld-elf/linkinfo1a.d: Likewise.
    * ld-elf/linkinfo1b.d: Likewise.

diff --git a/bfd/elf.c b/bfd/elf.c
index b589e60..59b1d4b 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3075,11 +3075,13 @@ assign_section_numbers (bfd *abfd, struct
bfd_link_info *link_info)
     {
       d->rel.hdr->sh_link = elf_onesymtab (abfd);
       d->rel.hdr->sh_info = d->this_idx;
+      d->rel.hdr->sh_flags |= SHF_INFO_LINK;
     }
       if (d->rela.idx != 0)
     {
       d->rela.hdr->sh_link = elf_onesymtab (abfd);
       d->rela.hdr->sh_info = d->this_idx;
+      d->rela.hdr->sh_flags |= SHF_INFO_LINK;
     }

       /* We need to set up sh_link for SHF_LINK_ORDER.  */
@@ -3166,7 +3168,10 @@ assign_section_numbers (bfd *abfd, struct
bfd_link_info *link_info)
         name += 5;
       s = bfd_get_section_by_name (abfd, name);
       if (s != NULL)
-        d->this_hdr.sh_info = elf_section_data (s)->this_idx;
+        {
+          d->this_hdr.sh_info = elf_section_data (s)->this_idx;
+          d->this_hdr.sh_flags |= SHF_INFO_LINK;
+        }
       break;

     case SHT_STRTAB:
diff --git a/binutils/testsuite/binutils-all/readelf.s
b/binutils/testsuite/binutils-all/readelf.s
index 22fb5d1..303e0c7 100644
--- a/binutils/testsuite/binutils-all/readelf.s
+++ b/binutils/testsuite/binutils-all/readelf.s
@@ -6,7 +6,7 @@ Section Headers:
 # On the normal MIPS systems, sections must be aligned to 16 byte
 # boundaries. On IA64, text sections are aligned to 16 byte boundaries.
  +\[ 1\] .text +PROGBITS +00000000 0000(34|40) 0000(08|10) 00 +AX +0 +0 +(.|..)
- +\[ 2\] .rel.+text +REL. +0+ 0+.* 0000.. 0. +. +1 +4
+ +\[ 2\] .rel.+text +REL. +0+ 0+.* 0000.. 0. +I +. +1 +4
 # MIPS targets put .rela.text here.
 #...
  +\[ .\] .data +PROGBITS +00000000 0000(3c|48|50) 0000(04|10) 00 +WA
+0 +0 +(.|..)
diff --git a/binutils/testsuite/binutils-all/readelf.s-64
b/binutils/testsuite/binutils-all/readelf.s-64
index ec31f3f..2e05d68 100644
--- a/binutils/testsuite/binutils-all/readelf.s-64
+++ b/binutils/testsuite/binutils-all/readelf.s-64
@@ -8,7 +8,7 @@ Section Headers:
  +\[ 1\] .text +PROGBITS +0000000000000000 +00000040
  +00000000000000.. +0000000000000000 +AX +0 +0 +.*
  +\[ 2\] .rel.+text +REL. +0+ +0+.*
- +000000000000001. +000000000000001. +. +1 +8
+ +000000000000001. +000000000000001. +I +. +1 +8
  +\[ 3\] .data +PROGBITS +0000000000000000 +000000(48|50)
  +000000000000000[48] +0000000000000000 +WA +0 +0 +.*
  +\[ 4\] .bss +NOBITS +0000000000000000 +000000(4c|50|54|58)
diff --git a/ld/testsuite/ld-elf/linkinfo1.s b/ld/testsuite/ld-elf/linkinfo1.s
new file mode 100644
index 0000000..dadda31
--- /dev/null
+++ b/ld/testsuite/ld-elf/linkinfo1.s
@@ -0,0 +1,2 @@
+    .text
+    call    foo@PLT
diff --git a/ld/testsuite/ld-elf/linkinfo1a.d b/ld/testsuite/ld-elf/linkinfo1a.d
new file mode 100644
index 0000000..8c6fb71
--- /dev/null
+++ b/ld/testsuite/ld-elf/linkinfo1a.d
@@ -0,0 +1,8 @@
+#source: linkinfo1.s
+#ld: -shared
+#readelf: -SW
+#target: x86_64-* i?86-*
+
+#...
+  \[[ 0-9]+\] \.rel[a]?\.plt[ \t]+REL[A]?[ \t][ \t0-9a-f]+AI[ \t0-9a-f]+
+#pass
diff --git a/ld/testsuite/ld-elf/linkinfo1b.d b/ld/testsuite/ld-elf/linkinfo1b.d
new file mode 100644
index 0000000..cc3aaed
--- /dev/null
+++ b/ld/testsuite/ld-elf/linkinfo1b.d
@@ -0,0 +1,9 @@
+#source: linkinfo1.s
+#ld: -shared
+#objcopy_linked_file: --strip-debug
+#readelf: -SW
+#target: x86_64-* i?86-*
+
+#...
+  \[[ 0-9]+\] \.rel[a]?\.plt[ \t]+REL[A]?[ \t][ \t0-9a-f]+AI[ \t0-9a-f]+
+#pass
-- 
1.8.3.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]