From 730035f7afaff40fa613348abd5a087319f1cb45 Mon Sep 17 00:00:00 2001 From: Dave Korn Date: Sat, 7 May 2011 14:29:10 +0000 Subject: [PATCH] bfd/ChangeLog: PR ld/12365 * cofflink.c (bfd_coff_link_input_bfd): Check for and warn about references to symbols defined in discarded sections. ld/ChangeLog: PR ld/12365 * scripttempl/pe.sc (__rt_psrelocs_start): New symbol definition. (__rt_psrelocs_end): Likewise. (__rt_psrelocs_size): Likewise difference between the above. (__RUNTIME_PSEUDO_RELOC_LIST_END__): Move outside .rdata section immediately after end of pseudo-reloc data. (___RUNTIME_PSEUDO_RELOC_LIST_END___): Likewise. (__RUNTIME_PSEUDO_RELOC_LIST__): Move outside .rdata section and calculate backward from list end. (___RUNTIME_PSEUDO_RELOC_LIST___): Likewise. * scripttempl/pep.sc: Likewise. ld/testsuite/ChangeLog: PR ld/12365 * ld-plugin/plugin-7.d: Allow underscore in error message. * ld-plugin/plugin-8.d: Likewise. --- bfd/ChangeLog | 6 ++++++ bfd/cofflink.c | 29 +++++++++++++++++++++++++++++ ld/ChangeLog | 14 ++++++++++++++ ld/scripttempl/pe.sc | 11 +++++++---- ld/scripttempl/pep.sc | 11 +++++++---- ld/testsuite/ChangeLog | 6 ++++++ ld/testsuite/ld-plugin/plugin-7.d | 2 +- ld/testsuite/ld-plugin/plugin-8.d | 2 +- 8 files changed, 71 insertions(+), 10 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 10255dab6cd..b8c2cf4b0d7 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2011-05-07 Dave Korn + + PR ld/12365 + * cofflink.c (bfd_coff_link_input_bfd): Check for and warn about + references to symbols defined in discarded sections. + 2011-05-07 Dave Korn PR ld/12365 diff --git a/bfd/cofflink.c b/bfd/cofflink.c index 33de7fe3cc8..fdfab1de48f 100644 --- a/bfd/cofflink.c +++ b/bfd/cofflink.c @@ -2365,6 +2365,35 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info *finfo, bfd *input_bfd) if (internal_relocs == NULL) return FALSE; + /* Run through the relocs looking for relocs against symbols + coming from discarded sections and complain about them. */ + irel = internal_relocs; + for (; irel < &internal_relocs[o->reloc_count]; irel++) + { + struct coff_link_hash_entry *h; + asection *ps = NULL; + long symndx = irel->r_symndx; + if (symndx < 0) + continue; + h = obj_coff_sym_hashes (input_bfd)[symndx]; + if (h == NULL) + continue; + while (h->root.type == bfd_link_hash_indirect + || h->root.type == bfd_link_hash_warning) + h = (struct coff_link_hash_entry *) h->root.u.i.link; + if (h->root.type == bfd_link_hash_defined + || h->root.type == bfd_link_hash_defweak) + ps = h->root.u.def.section; + if (ps == NULL) + continue; + /* Complain if definition comes from an excluded section. */ + if (ps->flags & SEC_EXCLUDE) + (*finfo->info->callbacks->einfo) + (_("%X`%s' referenced in section `%A' of %B: " + "defined in discarded section `%A' of %B\n"), + h->root.root.string, o, input_bfd, ps, ps->owner); + } + /* Call processor specific code to relocate the section contents. */ if (! bfd_coff_relocate_section (output_bfd, finfo->info, diff --git a/ld/ChangeLog b/ld/ChangeLog index 7368c5ca9e9..b2fe365b83c 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,17 @@ +2011-05-07 Dave Korn + + PR ld/12365 + * scripttempl/pe.sc (__rt_psrelocs_start): New symbol definition. + (__rt_psrelocs_end): Likewise. + (__rt_psrelocs_size): Likewise difference between the above. + (__RUNTIME_PSEUDO_RELOC_LIST_END__): Move outside .rdata section + immediately after end of pseudo-reloc data. + (___RUNTIME_PSEUDO_RELOC_LIST_END___): Likewise. + (__RUNTIME_PSEUDO_RELOC_LIST__): Move outside .rdata section and + calculate backward from list end. + (___RUNTIME_PSEUDO_RELOC_LIST___): Likewise. + * scripttempl/pep.sc: Likewise. + 2011-05-06 Tristan Gingold * scripttempl/alphavms.sc (CODE): Add *$CODE*. diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc index a82d08c7b59..126c1d4b199 100644 --- a/ld/scripttempl/pe.sc +++ b/ld/scripttempl/pe.sc @@ -106,12 +106,15 @@ SECTIONS .rdata ${RELOCATING+BLOCK(__section_alignment__)} : { ${R_RDATA} - ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = .;} - ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = .;} + ${RELOCATING+__rt_psrelocs_start = .;} *(.rdata_runtime_pseudo_reloc) - ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;} - ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;} + ${RELOCATING+__rt_psrelocs_end = .;} } + ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;} + ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;} + ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;} + ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;} + ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;} .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} : { diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc index b8315c53f9a..a3e0cf37530 100644 --- a/ld/scripttempl/pep.sc +++ b/ld/scripttempl/pep.sc @@ -107,12 +107,15 @@ SECTIONS .rdata ${RELOCATING+BLOCK(__section_alignment__)} : { ${R_RDATA} - ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = .;} - ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = .;} + ${RELOCATING+__rt_psrelocs_start = .;} *(.rdata_runtime_pseudo_reloc) - ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;} - ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;} + ${RELOCATING+__rt_psrelocs_end = .;} } + ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;} + ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;} + ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;} + ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;} + ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;} .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} : { diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index c312749986e..02581cccb6a 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-05-07 Dave Korn + + PR ld/12365 + * ld-plugin/plugin-7.d: Allow underscore in error message. + * ld-plugin/plugin-8.d: Likewise. + 2011-05-07 H.J. Lu PR ld/12730 diff --git a/ld/testsuite/ld-plugin/plugin-7.d b/ld/testsuite/ld-plugin/plugin-7.d index 04f41392ca6..4d0b9d7d91f 100644 --- a/ld/testsuite/ld-plugin/plugin-7.d +++ b/ld/testsuite/ld-plugin/plugin-7.d @@ -26,6 +26,6 @@ hook called: claim_file tmpdir/func.o \[@0/.* CLAIMED hook called: claim_file tmpdir/text.o \[@0/.* not claimed #... hook called: all symbols read. -`func' referenced in section `\.text.*' of tmpdir/main.o: defined in discarded section .* +`_?func' referenced in section `\.text.*' of tmpdir/main.o: defined in discarded section .* hook called: cleanup. #... diff --git a/ld/testsuite/ld-plugin/plugin-8.d b/ld/testsuite/ld-plugin/plugin-8.d index 003537c94f4..a589f01efc6 100644 --- a/ld/testsuite/ld-plugin/plugin-8.d +++ b/ld/testsuite/ld-plugin/plugin-8.d @@ -30,6 +30,6 @@ hook called: claim_file tmpdir/text.o \[@0/.* not claimed hook called: all symbols read. Sym: '_?func' Resolution: LDPR_PREVAILING_DEF Sym: '_?func2' Resolution: LDPR_PREVAILING_DEF_IRONLY -`func' referenced in section `\.text.*' of tmpdir/main.o: defined in discarded section .* +`_?func' referenced in section `\.text.*' of tmpdir/main.o: defined in discarded section .* hook called: cleanup. #... -- 2.30.2