diff options
author | Alan Modra <amodra@gmail.com> | 2016-10-11 18:13:04 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2016-10-11 18:13:04 +1030 |
commit | f02cb058822459ea29a9fdaa928c2623df435908 (patch) | |
tree | 1345ed2dd4496afc5d7a62981e881c0bda413908 /bfd | |
parent | 3b202c10808fa17200aaeb8eb9935d94e622e671 (diff) | |
download | gdb-f02cb058822459ea29a9fdaa928c2623df435908.zip gdb-f02cb058822459ea29a9fdaa928c2623df435908.tar.gz gdb-f02cb058822459ea29a9fdaa928c2623df435908.tar.bz2 |
Always descend into output section statements in lang_do_assignments
See https://sourceware.org/ml/binutils/2016-07/msg00091.html
This patch stop --gc-sections elf_gc_sweep_symbol localizing symbols
that ought to remain global.
The difficulty with always descending into output section statements
is that symbols defined by the script in such statements don't have
a bfd section when lang_do_assignments runs early in the link process.
There are two approaches to curing this problem. Either we can
create the bfd section early, or we can use a special section. This
patch takes the latter approach and uses bfd_und_section. (Creating
bfd sections early results in changed output section order, and thus
lots of testsuite failures. You can't create all output sections
early to ensure proper ordering as KEEP then stops empty sections
from being stripped.)
The wrinkle with this approach is that some code that runs at
gc-sections time needs to be made aware of the odd defined symbols
using bfd_und_section.
bfd/
* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Handle symbols
defined temporarily with bfd_und_section.
* elflink.c (_bfd_elf_gc_keep): Don't set SEC_KEEP for bfd_und_section.
* elfxx-mips.c (mips_elf_local_pic_function_p): Exclude defined
symbols with bfd_und_section.
ld/
* ldlang.c (lang_do_assignments_1): Descend into output section
statements that do not yet have bfd sections. Set symbol section
temporarily for symbols defined in such statements to the undefined
section. Don't error on data or reloc statements until final phase.
* ldexp.c (exp_fold_tree_1 <etree_assign>): Handle bfd_und_section
in expld.section.
* testsuite/ld-mmix/bpo-10.d: Adjust.
* testsuite/ld-mmix/bpo-11.d: Adjust.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 8 | ||||
-rw-r--r-- | bfd/elf64-x86-64.c | 5 | ||||
-rw-r--r-- | bfd/elflink.c | 3 | ||||
-rw-r--r-- | bfd/elfxx-mips.c | 1 |
4 files changed, 15 insertions, 2 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 7e9476b..c3e7a7c 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2016-10-11 Alan Modra <amodra@gmail.com> + + * elf64-x86-64.c (elf_x86_64_convert_load_reloc): Handle symbols + defined temporarily with bfd_und_section. + * elflink.c (_bfd_elf_gc_keep): Don't set SEC_KEEP for bfd_und_section. + * elfxx-mips.c (mips_elf_local_pic_function_p): Exclude defined + symbols with bfd_und_section. + 2016-10-07 Alan Modra <amodra@gmail.com> * targets.c (bfd_target <_bfd_merge_private_bfd_data>): Replace diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 2a372a6..79b8f1c 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -1877,7 +1877,10 @@ elf_x86_64_convert_load_reloc (bfd *abfd, asection *sec, bfd_elf_record_link_assignment. */ if (h->def_regular && (h->root.type == bfd_link_hash_new - || h->root.type == bfd_link_hash_undefined)) + || h->root.type == bfd_link_hash_undefined + || ((h->root.type == bfd_link_hash_defined + || h->root.type == bfd_link_hash_defweak) + && h->root.u.def.section == bfd_und_section_ptr))) { /* Skip since R_X86_64_32/R_X86_64_32S may overflow. */ if (require_reloc_pc32) diff --git a/bfd/elflink.c b/bfd/elflink.c index 1591682..2f40eb0 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -13037,7 +13037,8 @@ _bfd_elf_gc_keep (struct bfd_link_info *info) if (h != NULL && (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak) - && !bfd_is_abs_section (h->root.u.def.section)) + && !bfd_is_abs_section (h->root.u.def.section) + && !bfd_is_und_section (h->root.u.def.section)) h->root.u.def.section->flags |= SEC_KEEP; } } diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index d618e54..cc29c0e 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -1808,6 +1808,7 @@ mips_elf_local_pic_function_p (struct mips_elf_link_hash_entry *h) || h->root.root.type == bfd_link_hash_defweak) && h->root.def_regular && !bfd_is_abs_section (h->root.root.u.def.section) + && !bfd_is_und_section (h->root.root.u.def.section) && (!ELF_ST_IS_MIPS16 (h->root.other) || (h->fn_stub && h->need_fn_stub)) && (PIC_OBJECT_P (h->root.root.u.def.section->owner) |