Set SHF_INFO_LINK bit for SHT_REL/SHT_RELA sections
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 19 Dec 2013 19:34:47 +0000 (11:34 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 19 Dec 2013 19:34:47 +0000 (11:34 -0800)
It is a good pratice to set the SHF_INFO_LINK bit when the sh_info field
represents a section header index.

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.

bfd/ChangeLog
bfd/elf.c
binutils/testsuite/ChangeLog
binutils/testsuite/binutils-all/readelf.s
binutils/testsuite/binutils-all/readelf.s-64
ld/testsuite/ChangeLog
ld/testsuite/ld-elf/linkinfo1.s [new file with mode: 0644]
ld/testsuite/ld-elf/linkinfo1a.d [new file with mode: 0644]
ld/testsuite/ld-elf/linkinfo1b.d [new file with mode: 0644]

index 95355fc..70c7e72 100644 (file)
@@ -1,3 +1,9 @@
+2013-12-19  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.
+
 2013-12-19  Pierre Muller  <muller@sourceware.org>
 
        * peXXigen.c (rsrc_cmp): Fix unused variable warning.
index b589e60..59b1d4b 100644 (file)
--- 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:
index 1023526..a1e6724 100644 (file)
@@ -1,3 +1,9 @@
+2013-12-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/16317
+       * binutils-all/readelf.s: Updated.
+       * binutils-all/readelf.s-64: Likewise.
+
 2013-12-13  Kuan-Lin Chen  <kuanlinchentw@gmail.com>
            Wei-Cheng Wang  <cole945@gmail.com>
 
index 22fb5d1..303e0c7 100644 (file)
@@ -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 +(.|..)
index ec31f3f..2e05d68 100644 (file)
@@ -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)
index f7e6e58..519c2cd 100644 (file)
@@ -1,3 +1,10 @@
+2013-12-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/16317
+       * ld-elf/linkinfo1.s: New file.
+       * ld-elf/linkinfo1a.d: Likewise.
+       * ld-elf/linkinfo1b.d: Likewise.
+
 2013-12-18  Vidya Praveen  <vidyapraveen@arm.com>
 
        * lib/ld-lib.exp (check_lto_available): Support cflags, ldflags and
diff --git a/ld/testsuite/ld-elf/linkinfo1.s b/ld/testsuite/ld-elf/linkinfo1.s
new file mode 100644 (file)
index 0000000..dadda31
--- /dev/null
@@ -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 (file)
index 0000000..8c6fb71
--- /dev/null
@@ -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 (file)
index 0000000..cc3aaed
--- /dev/null
@@ -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