From 5789f845fbf67d271e0f5ff154eb03319b551211 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 3 Mar 2021 12:14:55 +1030 Subject: --gc-sections with groups and start/stop syms The testcases added here show situations where synthesized start/stop symbols don't cause their associated input sections to be marked. Fixed with the elflink.c and ldlang.c changes. bfd/ PR 27500 * elflink.c (_bfd_elf_gc_mark_rsec): Do special start/stop processing not when start/stop symbol section is unmarked but on first time a start/stop symbol is processed. ld/ * ldlang.c (insert_undefined): Don't mark symbols here. (lang_mark_undefineds): Do so here instead, new function. (lang_process): Call lang_mark_undefineds. * testsuite/ld-gc/start3.d, * testsuite/ld-gc/start3.s: New test. * testsuite/ld-gc/start4.d, * testsuite/ld-gc/start4.s: New test. * testsuite/ld-gc/gc.exp: Run them. --- ld/ldlang.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'ld/ldlang.c') diff --git a/ld/ldlang.c b/ld/ldlang.c index a77e8fa..684e1d2 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -3986,8 +3986,6 @@ insert_undefined (const char *name) h->type = bfd_link_hash_undefined; h->u.undef.abfd = NULL; h->non_ir_ref_regular = TRUE; - if (is_elf_hash_table (link_info.hash)) - ((struct elf_link_hash_entry *) h)->mark = 1; bfd_link_add_undef (link_info.hash, h); } } @@ -4005,6 +4003,23 @@ lang_place_undefineds (void) insert_undefined (ptr->name); } +/* Mark -u symbols against garbage collection. */ + +static void +lang_mark_undefineds (void) +{ + ldlang_undef_chain_list_type *ptr; + + if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour) + for (ptr = ldlang_undef_chain_list_head; ptr != NULL; ptr = ptr->next) + { + struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) + bfd_link_hash_lookup (link_info.hash, ptr->name, FALSE, FALSE, TRUE); + if (h != NULL) + h->mark = 1; + } +} + /* Structure used to build the list of symbols that the user has required be defined. */ @@ -8116,6 +8131,8 @@ lang_process (void) /* Remove unreferenced sections if asked to. */ lang_gc_sections (); + lang_mark_undefineds (); + /* Check relocations. */ lang_check_relocs (); -- cgit v1.1