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.
This commit is contained in:
Alan Modra
2021-03-01 08:22:49 +10:30
parent 7824c1d22f
commit 8ee10e8609
14 changed files with 95 additions and 4 deletions

View File

@@ -2070,8 +2070,6 @@ elf_shlib_list_options (FILE *file)
-z common Generate common symbols with STT_COMMON type\n"));
fprintf (file, _("\
-z nocommon Generate common symbols with STT_OBJECT type\n"));
fprintf (file, _("\
-z stack-size=SIZE Set size of stack segment\n"));
if (link_info.textrel_check == textrel_check_error)
fprintf (file, _("\
-z text Treat DT_TEXTREL in output as error (default)\n"));
@@ -2116,8 +2114,12 @@ elf_static_list_options (FILE *file)
fprintf (file, _("\
-z defs Report unresolved symbols in object files\n"));
fprintf (file, _("\
-z undefs Ignore unresolved symbols in object files\n"));
fprintf (file, _("\
-z muldefs Allow multiple definitions\n"));
fprintf (file, _("\
-z stack-size=SIZE Set size of stack segment\n"));
fprintf (file, _("\
-z execstack Mark executable as requiring executable stack\n"));
fprintf (file, _("\
-z noexecstack Mark executable as not requiring executable stack\n"));
@@ -2127,6 +2129,13 @@ elf_static_list_options (FILE *file)
-z nounique-symbol Keep duplicated local symbol names (default)\n"));
fprintf (file, _("\
-z globalaudit Mark executable requiring global auditing\n"));
fprintf (file, _("\
-z start-stop-gc Enable garbage collection on __start/__stop\n"));
fprintf (file, _("\
-z nostart-stop-gc Don't garbage collect __start/__stop (default)\n"));
fprintf (file, _("\
-z start-stop-visibility=V Set visibility of built-in __start/__stop symbols\n\
to DEFAULT, PROTECTED, HIDDEN or INTERNAL\n"));
}
static void