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. --- ld/ChangeLog | 13 +++++++++++++ ld/NEWS | 3 +++ ld/emultempl/elf.em | 4 ++++ ld/ld.texi | 17 +++++++++++++++++ ld/ldmain.c | 1 + ld/lexsup.c | 13 +++++++++++-- ld/testsuite/ld-gc/gc.exp | 1 + ld/testsuite/ld-gc/start2.d | 10 ++++++++++ ld/testsuite/ld-gc/start2.s | 7 +++++++ 9 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-gc/start2.d create mode 100644 ld/testsuite/ld-gc/start2.s (limited to 'ld') diff --git a/ld/ChangeLog b/ld/ChangeLog index 2347f9a..d72d69a 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,4 +1,17 @@ 2021-03-01 Alan Modra + Fangrui Song + + * 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. + +2021-03-01 Alan Modra * ldlang.c (undef_start_stop): For ELF make undefined start/stop symbols undefweak if that was how they were referenced. Undo diff --git a/ld/NEWS b/ld/NEWS index 4bb4ba3..d1aa3b0 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -5,6 +5,9 @@ * Add -z report-relative-reloc to x86 ELF linker to report dynamic relative relocations. +* Add -z start-stop-gc to disable special treatment of __start_*/__stop_* + references when --gc-sections. + Changes in 2.36: * Add libdep plugin, for linking dependencies of static libraries that diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em index 5e59f38..cea89e5 100644 --- a/ld/emultempl/elf.em +++ b/ld/emultempl/elf.em @@ -760,6 +760,10 @@ fragment <