aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog13
-rw-r--r--ld/NEWS3
-rw-r--r--ld/emultempl/elf.em4
-rw-r--r--ld/ld.texi17
-rw-r--r--ld/ldmain.c1
-rw-r--r--ld/lexsup.c13
-rw-r--r--ld/testsuite/ld-gc/gc.exp1
-rw-r--r--ld/testsuite/ld-gc/start2.d10
-rw-r--r--ld/testsuite/ld-gc/start2.s7
9 files changed, 67 insertions, 2 deletions
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 <amodra@gmail.com>
+ Fangrui Song <maskray@google.com>
+
+ * 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 <amodra@gmail.com>
* 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 <<EOF
{
link_info.flags_1 |= DF_1_GLOBAUDIT;
}
+ else if (CONST_STRNEQ (optarg, "start-stop-gc"))
+ link_info.start_stop_gc = TRUE;
+ else if (CONST_STRNEQ (optarg, "nostart-stop-gc"))
+ link_info.start_stop_gc = FALSE;
else if (CONST_STRNEQ (optarg, "start-stop-visibility="))
{
if (strcmp (optarg, "start-stop-visibility=default") == 0)
diff --git a/ld/ld.texi b/ld/ld.texi
index 9643818..6d016ec 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1453,6 +1453,23 @@ Specify a stack size for an ELF @code{PT_GNU_STACK} segment.
Specifying zero will override any default non-zero sized
@code{PT_GNU_STACK} segment creation.
+@item start-stop-gc
+@itemx nostart-stop-gc
+@cindex start-stop-gc
+When @samp{--gc-sections} is in effect, a reference from a retained
+section to @code{__start_SECNAME} or @code{__stop_SECNAME} causes all
+input sections named @code{SECNAME} to also be retained, if
+@code{SECNAME} is representable as a C identifier and either
+@code{__start_SECNAME} or @code{__stop_SECNAME} is synthesized by the
+linker. @samp{-z start-stop-gc} disables this effect, allowing
+sections to be garbage collected as if the special synthesized symbols
+were not defined. @samp{-z start-stop-gc} has no effect on a
+definition of @code{__start_SECNAME} or @code{__stop_SECNAME} in an
+object file or linker script. Such a definition will prevent the
+linker providing a synthesized @code{__start_SECNAME} or
+@code{__stop_SECNAME} respectively, and therefore the special
+treatment by garbage collection for those references.
+
@item start-stop-visibility=@var{value}
@cindex visibility
@cindex ELF symbol visibility
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 5c88ee7..7a3c02a 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -357,6 +357,7 @@ main (int argc, char **argv)
#ifdef DEFAULT_NEW_DTAGS
link_info.new_dtags = DEFAULT_NEW_DTAGS;
#endif
+ link_info.start_stop_gc = FALSE;
link_info.start_stop_visibility = STV_PROTECTED;
ldfile_add_arch ("");
diff --git a/ld/lexsup.c b/ld/lexsup.c
index f005a58..36492ab 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -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
diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp
index b3245bb..ad3bc2e 100644
--- a/ld/testsuite/ld-gc/gc.exp
+++ b/ld/testsuite/ld-gc/gc.exp
@@ -89,6 +89,7 @@ test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func"
run_dump_test "noent"
run_dump_test "abi-note"
run_dump_test "start"
+run_dump_test "start2"
run_dump_test "stop"
run_dump_test "pr19167"
if { [is_elf_format] } then {
diff --git a/ld/testsuite/ld-gc/start2.d b/ld/testsuite/ld-gc/start2.d
new file mode 100644
index 0000000..480dc74
--- /dev/null
+++ b/ld/testsuite/ld-gc/start2.d
@@ -0,0 +1,10 @@
+#name: --gc-sections with -z start-stop-gc
+#ld: --gc-sections -e _start -z start-stop-gc
+#nm: -n
+#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
+#xfail: bfin-*-*linux* frv-*-*
+
+#failif
+#...
+[0-9a-f]+ D +__start__foo
+#...
diff --git a/ld/testsuite/ld-gc/start2.s b/ld/testsuite/ld-gc/start2.s
new file mode 100644
index 0000000..b0084a1
--- /dev/null
+++ b/ld/testsuite/ld-gc/start2.s
@@ -0,0 +1,7 @@
+.globl _start
+_start:
+ .weak __start__foo
+ .dc.a __start__foo
+ .section _foo,"aw",%progbits
+foo:
+ .long 1