From 8ee10e86093150c70360d9e26b29e6d9b6398f33 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 1 Mar 2021 08:22:49 +1030 Subject: PR27451, -z start_stop_gc When --gc-sections is in effect, a reference from a retained section to __start_SECNAME or __stop_SECNAME causes all input sections named SECNAME to also be retained, if SECNAME is representable as a C identifier and either __start_SECNAME or __stop_SECNAME is synthesized by the linker. Add an option to disable that feature, effectively ignoring any relocation that references a synthesized linker defined __start_ or __stop_ symbol. PR 27451 include/ * bfdlink.h (struct bfd_link_info): Add start_stop_gc. bfd/ * elflink.c (_bfd_elf_gc_mark_rsec): Ignore synthesized linker defined start/stop symbols when start_stop_gc. (bfd_elf_gc_mark_dynamic_ref_symbol): Likewise. (bfd_elf_define_start_stop): Don't modify ldscript_def syms. * linker.c (bfd_generic_define_start_stop): Likewise. ld/ * emultempl/elf.em: Handle -z start-stop-gc and -z nostart-stop-gc. * lexsup.c (elf_static_list_options): Display help for them. Move help for -z stack-size to here from elf_shlib_list_options. Add help for -z start-stop-visibility and -z undefs. * ld.texi: Document -z start-stop-gc and -z nostart-stop-gc. * NEWS: Mention -z start-stop-gc. * testsuite/ld-gc/start2.s, * testsuite/ld-gc/start2.d: New test. * testsuite/ld-gc/gc.exp: Run it. --- bfd/ChangeLog | 9 +++++++++ bfd/elflink.c | 11 +++++++++-- bfd/linker.c | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 2fef817..818f580 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2021-03-01 Alan Modra + Fangrui Song + + * elflink.c (_bfd_elf_gc_mark_rsec): Ignore synthesized linker + defined start/stop symbols when start_stop_gc. + (bfd_elf_gc_mark_dynamic_ref_symbol): Likewise. + (bfd_elf_define_start_stop): Don't modify ldscript_def syms. + * linker.c (bfd_generic_define_start_stop): Likewise. + 2021-02-25 Alan Modra PR 27441 diff --git a/bfd/elflink.c b/bfd/elflink.c index 7b74f26..74b54c2 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -13444,12 +13444,15 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_info *info, asection *sec, hw->mark = 1; } - if (start_stop != NULL) + if (h->start_stop && !h->root.ldscript_def) { + if (info->start_stop_gc) + return NULL; + /* To work around a glibc bug, mark XXX input sections when there is a reference to __start_XXX or __stop_XXX symbols. */ - if (h->start_stop) + else if (start_stop != NULL) { asection *s = h->u2.start_stop_section; *start_stop = !s->gc_mark; @@ -13912,6 +13915,9 @@ bfd_elf_gc_mark_dynamic_ref_symbol (struct elf_link_hash_entry *h, void *inf) if ((h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak) + && (!h->start_stop + || h->root.ldscript_def + || !info->start_stop_gc) && ((h->ref_dynamic && !h->forced_local) || ((h->def_regular || ELF_COMMON_DEF_P (h)) && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL @@ -14984,6 +14990,7 @@ bfd_elf_define_start_stop (struct bfd_link_info *info, FALSE, FALSE, TRUE); /* NB: Common symbols will be turned into definition later. */ if (h != NULL + && !h->root.ldscript_def && (h->root.type == bfd_link_hash_undefined || h->root.type == bfd_link_hash_undefweak || ((h->ref_regular || h->def_dynamic) diff --git a/bfd/linker.c b/bfd/linker.c index 1fb5787..7e0415c 100644 --- a/bfd/linker.c +++ b/bfd/linker.c @@ -3188,6 +3188,7 @@ bfd_generic_define_start_stop (struct bfd_link_info *info, h = bfd_link_hash_lookup (info->hash, symbol, FALSE, FALSE, TRUE); if (h != NULL + && !h->ldscript_def && (h->type == bfd_link_hash_undefined || h->type == bfd_link_hash_undefweak)) { -- cgit v1.1