From aed64b35fbdb4d924b081158fd31015bb5d366c2 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 13 Apr 2012 23:20:00 +0000 Subject: [PATCH] Set reloc_count to 0 for reloc sections bfd/ 2012-04-13 Alan Modra PR ld/13947 * elflink.c (bfd_elf_final_link): Set reloc_count to 0 for reloc sections. ld/testsuite/ 2012-04-13 H.J. Lu PR ld/13947 * ld-x86-64/x86-64.exp: Run pr13947. * ld-x86-64/pr13947.d: New file. * ld-x86-64/pr13947.s: Likewise. --- bfd/ChangeLog | 6 ++++++ bfd/elflink.c | 8 +++++++- ld/testsuite/ChangeLog | 7 +++++++ ld/testsuite/ld-x86-64/pr13947.d | 7 +++++++ ld/testsuite/ld-x86-64/pr13947.s | 5 +++++ ld/testsuite/ld-x86-64/x86-64.exp | 1 + 6 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-x86-64/pr13947.d create mode 100644 ld/testsuite/ld-x86-64/pr13947.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 6eea52d56c5..ab5fd6fb6bc 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2012-04-13 Alan Modra + + PR ld/13947 + * elflink.c (bfd_elf_final_link): Set reloc_count to 0 for + reloc sections. + 2012-04-12 David S. Miller * reloc.c (BFD_RELOC_SPARC_H34, BFD_RELOC_SPARC_SIZE32, diff --git a/bfd/elflink.c b/bfd/elflink.c index 0ed52081999..aa02e2597bd 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -10396,7 +10396,13 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) if (sec->flags & SEC_MERGE) merged = TRUE; - if (info->relocatable || info->emitrelocations) + if (esdo->this_hdr.sh_type == SHT_REL + || esdo->this_hdr.sh_type == SHT_RELA) + /* Some backends use reloc_count in relocation sections + to count particular types of relocs. Of course, + reloc sections themselves can't have relocations. */ + reloc_count = 0; + else if (info->relocatable || info->emitrelocations) reloc_count = sec->reloc_count; else if (bed->elf_backend_count_relocs) reloc_count = (*bed->elf_backend_count_relocs) (info, sec); diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 4064c84231b..669014d0d22 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2012-04-13 H.J. Lu + + PR ld/13947 + * ld-x86-64/x86-64.exp: Run pr13947. + * ld-x86-64/pr13947.d: New file. + * ld-x86-64/pr13947.s: Likewise. + 2012-04-13 Roland McGrath * ld-arm/arm-elf.exp (armelftests_common): Move cases using diff --git a/ld/testsuite/ld-x86-64/pr13947.d b/ld/testsuite/ld-x86-64/pr13947.d new file mode 100644 index 00000000000..c8af34d8e78 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13947.d @@ -0,0 +1,7 @@ +#ld: -shared --emit-relocs +#readelf: -S --wide + +#failif +#... + +\[ [0-9]\] .rela.rela.plt +RELA +[0-9a-f]+ +[0-9a-f]+ 0+ +.* +#... diff --git a/ld/testsuite/ld-x86-64/pr13947.s b/ld/testsuite/ld-x86-64/pr13947.s new file mode 100644 index 00000000000..71928cbe130 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13947.s @@ -0,0 +1,5 @@ + .text + .globl foo + .type foo, @function +foo: + call bar@PLT diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 963e8e7bd32..27174d50946 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -205,6 +205,7 @@ run_dump_test "nogot2" run_dump_test "discarded1" run_dump_test "pr12718" run_dump_test "pr12921" +run_dump_test "pr13947" if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} { return -- 2.30.2