From 9ef5d938819dff73d7640a2654b07df64670d7f9 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 19 Dec 2013 11:34:47 -0800 Subject: [PATCH] Set SHF_INFO_LINK bit for SHT_REL/SHT_RELA sections 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 | 6 ++++++ bfd/elf.c | 7 ++++++- binutils/testsuite/ChangeLog | 6 ++++++ binutils/testsuite/binutils-all/readelf.s | 2 +- binutils/testsuite/binutils-all/readelf.s-64 | 2 +- ld/testsuite/ChangeLog | 7 +++++++ ld/testsuite/ld-elf/linkinfo1.s | 2 ++ ld/testsuite/ld-elf/linkinfo1a.d | 8 ++++++++ ld/testsuite/ld-elf/linkinfo1b.d | 9 +++++++++ 9 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 ld/testsuite/ld-elf/linkinfo1.s create mode 100644 ld/testsuite/ld-elf/linkinfo1a.d create mode 100644 ld/testsuite/ld-elf/linkinfo1b.d diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 95355fcba61..70c7e72ff32 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2013-12-19 H.J. Lu + + 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 * peXXigen.c (rsrc_cmp): Fix unused variable warning. diff --git a/bfd/elf.c b/bfd/elf.c index b589e60777f..59b1d4b4748 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/ChangeLog b/binutils/testsuite/ChangeLog index 1023526042d..a1e67246d2c 100644 --- a/binutils/testsuite/ChangeLog +++ b/binutils/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2013-12-19 H.J. Lu + + PR binutils/16317 + * binutils-all/readelf.s: Updated. + * binutils-all/readelf.s-64: Likewise. + 2013-12-13 Kuan-Lin Chen Wei-Cheng Wang diff --git a/binutils/testsuite/binutils-all/readelf.s b/binutils/testsuite/binutils-all/readelf.s index 22fb5d1e14a..303e0c77ba1 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 ec31f3f2654..2e05d681c40 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/ChangeLog b/ld/testsuite/ChangeLog index f7e6e582962..519c2cd94cd 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2013-12-19 H.J. Lu + + PR binutils/16317 + * ld-elf/linkinfo1.s: New file. + * ld-elf/linkinfo1a.d: Likewise. + * ld-elf/linkinfo1b.d: Likewise. + 2013-12-18 Vidya Praveen * 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 index 00000000000..dadda31ca39 --- /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 00000000000..8c6fb71cc7f --- /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 00000000000..cc3aaed135c --- /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 -- 2.30.2