diff options
author | Alan Modra <amodra@gmail.com> | 2021-03-03 12:14:55 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-03-03 17:46:36 +1030 |
commit | 5789f845fbf67d271e0f5ff154eb03319b551211 (patch) | |
tree | d1cf1f67c603d4d4eb3ef237d7054fb351eeedbe | |
parent | 270f32fc50b465e84c214a17d4ad3aebc3161bae (diff) | |
download | fsf-binutils-gdb-5789f845fbf67d271e0f5ff154eb03319b551211.zip fsf-binutils-gdb-5789f845fbf67d271e0f5ff154eb03319b551211.tar.gz fsf-binutils-gdb-5789f845fbf67d271e0f5ff154eb03319b551211.tar.bz2 |
--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.
-rw-r--r-- | bfd/ChangeLog | 7 | ||||
-rw-r--r-- | bfd/elflink.c | 8 | ||||
-rw-r--r-- | ld/ChangeLog | 12 | ||||
-rw-r--r-- | ld/ldlang.c | 21 | ||||
-rw-r--r-- | ld/testsuite/ld-gc/gc.exp | 2 | ||||
-rw-r--r-- | ld/testsuite/ld-gc/start3.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-gc/start3.s | 29 | ||||
-rw-r--r-- | ld/testsuite/ld-gc/start4.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-gc/start4.s | 19 |
9 files changed, 112 insertions, 4 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 0e518ce..5e2571b 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,12 @@ 2021-03-03 Alan Modra <amodra@gmail.com> + 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. + +2021-03-03 Alan Modra <amodra@gmail.com> + * reloc.c: Include x86_64.h rather than internal.h. 2021-03-02 Nick Clifton <nickc@redhat.com> diff --git a/bfd/elflink.c b/bfd/elflink.c index 74b54c2..e1278a5 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -13422,6 +13422,8 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_info *info, asection *sec, if (r_symndx >= cookie->locsymcount || ELF_ST_BIND (cookie->locsyms[r_symndx].st_info) != STB_LOCAL) { + bfd_boolean was_marked; + h = cookie->sym_hashes[r_symndx - cookie->extsymoff]; if (h == NULL) { @@ -13432,6 +13434,8 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_info *info, asection *sec, while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; + + was_marked = h->mark; h->mark = 1; /* Keep all aliases of the symbol too. If an object symbol needs to be copied into .dynbss then all of its aliases @@ -13444,7 +13448,7 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_info *info, asection *sec, hw->mark = 1; } - if (h->start_stop && !h->root.ldscript_def) + if (!was_marked && h->start_stop && !h->root.ldscript_def) { if (info->start_stop_gc) return NULL; @@ -13455,7 +13459,7 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_info *info, asection *sec, else if (start_stop != NULL) { asection *s = h->u2.start_stop_section; - *start_stop = !s->gc_mark; + *start_stop = TRUE; return s; } } diff --git a/ld/ChangeLog b/ld/ChangeLog index bf1d226..0f1da7f 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,5 +1,17 @@ 2021-03-03 Alan Modra <amodra@gmail.com> + PR 27500 + * 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. + +2021-03-03 Alan Modra <amodra@gmail.com> + * testsuite/ld-gc/gc.exp: Define UNDERSCORE in ASFLAGS. Move tests with ELF section directives to is_elf_format block. * testsuite/ld-gc/abi-note.d: Run on more targets. 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 (); diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp index ba528d0..cd5c6f7 100644 --- a/ld/testsuite/ld-gc/gc.exp +++ b/ld/testsuite/ld-gc/gc.exp @@ -101,6 +101,8 @@ if { [is_elf_format] } then { run_dump_test "stop" run_dump_test "start" run_dump_test "start2" + run_dump_test "start3" + run_dump_test "start4" } if { [is_elf_format] && [check_shared_lib_support] } then { diff --git a/ld/testsuite/ld-gc/start3.d b/ld/testsuite/ld-gc/start3.d new file mode 100644 index 0000000..a57dab1 --- /dev/null +++ b/ld/testsuite/ld-gc/start3.d @@ -0,0 +1,9 @@ +#name: --gc-sections with groups and start/stop syms +#ld: --gc-sections -e _start +#nm: -n +#notarget: [is_generic] +#xfail: bfin-*-*linux* frv-*-*linux* lm32-*-*linux* + +#... +[0-9a-f]+ T +bar +#... diff --git a/ld/testsuite/ld-gc/start3.s b/ld/testsuite/ld-gc/start3.s new file mode 100644 index 0000000..0e720ba --- /dev/null +++ b/ld/testsuite/ld-gc/start3.s @@ -0,0 +1,29 @@ + .text + .global _start +_start: + .dc.a foo + .ifdef UNDERSCORE + .dc.a ___start_xx, ___stop_xx + .else + .dc.a __start_xx, __stop_xx + .endif + + .section .text,"axG",%progbits,foo_group + .global foo +foo: + .dc.a 0 + + .section xx,"aG",%progbits,foo_group + .global foo_xx +foo_xx: + .dc.a 1 + + .section .text,"axG",%progbits,bar_group + .global bar +bar: + .dc.a 2 + + .section xx,"aG",%progbits,bar_group + .global bar_xx +bar_xx: + .dc.a 3 diff --git a/ld/testsuite/ld-gc/start4.d b/ld/testsuite/ld-gc/start4.d new file mode 100644 index 0000000..ae77aa9 --- /dev/null +++ b/ld/testsuite/ld-gc/start4.d @@ -0,0 +1,9 @@ +#name: --gc-sections with other syms and start/stop syms +#ld: --gc-sections -e _start +#nm: -n +#target: [supports_gnu_unique] +#xfail: bfin-*-*linux* frv-*-*linux* lm32-*-*linux* + +#... +[0-9a-f]+ R +bar_xx +#... diff --git a/ld/testsuite/ld-gc/start4.s b/ld/testsuite/ld-gc/start4.s new file mode 100644 index 0000000..1aa9445 --- /dev/null +++ b/ld/testsuite/ld-gc/start4.s @@ -0,0 +1,19 @@ + .text + .global _start +_start: + .dc.a foo_xx + .ifdef UNDERSCORE + .dc.a ___start_xx, ___stop_xx + .else + .dc.a __start_xx, __stop_xx + .endif + + .section xx,"a",%progbits,unique,0 + .global foo_xx +foo_xx: + .dc.a 1 + + .section xx,"a",%progbits,unique,1 + .global bar_xx +bar_xx: + .dc.a 3 |