From 97d343d40012b1030f1fd219f91efcab180fb3ef Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 26 Apr 2017 15:34:00 -0700 Subject: [PATCH] x86: Add DT_PLTRELSZ/DT_PLTREL/DT_JMPREL for PLT relocation x86, PLT relocation may contain R_386_TLS_DESC or R_X86_64_TLSDESC even though there is no real PLT. We need to add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL if there is a .rel.plt/.rela.plt section. bfd/ * elf32-i386.c (elf_i386_size_dynamic_sections): Alwasys add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rel.plt section. * elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Alwasys add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rela.plt section. ld/ * testsuite/ld-i386/tlsdesc2.d: New test. * testsuite/ld-x86-64/tlsdesc2.d: Likewise. --- bfd/ChangeLog | 7 +++++++ bfd/elf32-i386.c | 14 +++++++------- bfd/elf64-x86-64.c | 22 +++++++++++----------- ld/ChangeLog | 5 +++++ ld/testsuite/ld-i386/i386.exp | 1 + ld/testsuite/ld-i386/tlsdesc2.d | 10 ++++++++++ ld/testsuite/ld-x86-64/tlsdesc2.d | 10 ++++++++++ ld/testsuite/ld-x86-64/x86-64.exp | 1 + 8 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 ld/testsuite/ld-i386/tlsdesc2.d create mode 100644 ld/testsuite/ld-x86-64/tlsdesc2.d diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 26b3572c5b1..32342300757 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2017-04-26 H.J. Lu + + * elf32-i386.c (elf_i386_size_dynamic_sections): Alwasys add + DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rel.plt section. + * elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Alwasys + add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rela.plt section. + 2017-04-26 Nick Clifton PR binutils/21434 diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 9a568ce522b..78c5d5b9ddb 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -3577,14 +3577,14 @@ elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) relocation. */ if (!add_dynamic_entry (DT_PLTGOT, 0)) return FALSE; + } - if (htab->elf.srelplt->size != 0) - { - if (!add_dynamic_entry (DT_PLTRELSZ, 0) - || !add_dynamic_entry (DT_PLTREL, DT_REL) - || !add_dynamic_entry (DT_JMPREL, 0)) - return FALSE; - } + if (htab->elf.srelplt->size != 0) + { + if (!add_dynamic_entry (DT_PLTRELSZ, 0) + || !add_dynamic_entry (DT_PLTREL, DT_REL) + || !add_dynamic_entry (DT_JMPREL, 0)) + return FALSE; } if (relocs) diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 965ceb2f334..0e0a020393f 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -4052,21 +4052,21 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd, relocation. */ if (!add_dynamic_entry (DT_PLTGOT, 0)) return FALSE; + } - if (htab->elf.srelplt->size != 0) - { - if (!add_dynamic_entry (DT_PLTRELSZ, 0) - || !add_dynamic_entry (DT_PLTREL, DT_RELA) - || !add_dynamic_entry (DT_JMPREL, 0)) - return FALSE; - } - - if (htab->tlsdesc_plt - && (!add_dynamic_entry (DT_TLSDESC_PLT, 0) - || !add_dynamic_entry (DT_TLSDESC_GOT, 0))) + if (htab->elf.srelplt->size != 0) + { + if (!add_dynamic_entry (DT_PLTRELSZ, 0) + || !add_dynamic_entry (DT_PLTREL, DT_RELA) + || !add_dynamic_entry (DT_JMPREL, 0)) return FALSE; } + if (htab->tlsdesc_plt + && (!add_dynamic_entry (DT_TLSDESC_PLT, 0) + || !add_dynamic_entry (DT_TLSDESC_GOT, 0))) + return FALSE; + if (relocs) { if (!add_dynamic_entry (DT_RELA, 0) diff --git a/ld/ChangeLog b/ld/ChangeLog index 93165f2cbdc..c93d903ef48 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2017-04-26 H.J. Lu + + * testsuite/ld-i386/tlsdesc2.d: New test. + * testsuite/ld-x86-64/tlsdesc2.d: Likewise. + 2017-04-26 Maciej W. Rozycki PR ld/21334 diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 844b36f5071..a709bcffab7 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -437,6 +437,7 @@ run_dump_test "pr18801" run_dump_test "pr18815" run_dump_test "pr19939a" run_dump_test "pr19939b" +run_dump_test "tlsdesc2" proc undefined_weak {cflags ldflags} { set testname "Undefined weak symbol" diff --git a/ld/testsuite/ld-i386/tlsdesc2.d b/ld/testsuite/ld-i386/tlsdesc2.d new file mode 100644 index 00000000000..b8569e893b8 --- /dev/null +++ b/ld/testsuite/ld-i386/tlsdesc2.d @@ -0,0 +1,10 @@ +#source: tlsdesc.s +#as: --32 +#ld: -melf_i386 -shared -z now +#readelf: -d --wide + +#... +.*\(PLTRELSZ\).* +.*\(PLTREL\).* +.*\(JMPREL\).* +#pass diff --git a/ld/testsuite/ld-x86-64/tlsdesc2.d b/ld/testsuite/ld-x86-64/tlsdesc2.d new file mode 100644 index 00000000000..86797579bac --- /dev/null +++ b/ld/testsuite/ld-x86-64/tlsdesc2.d @@ -0,0 +1,10 @@ +#source: tlsdesc.s +#as: --64 +#ld: -melf_x86_64 -shared -z now +#readelf: -d --wide + +#... +.*\(PLTRELSZ\).* +.*\(PLTREL\).* +.*\(JMPREL\).* +#pass diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index a9394c3a564..7127eca02b0 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -530,6 +530,7 @@ run_dump_test "pr20253-4e" run_dump_test "pr20253-4f" run_dump_test "pr20253-5a" run_dump_test "pr20253-5b" +run_dump_test "tlsdesc2" proc undefined_weak {cflags ldflags} { set testname "Undefined weak symbol" -- 2.30.2