summaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog8
-rw-r--r--ld/NEWS3
-rw-r--r--ld/emultempl/elf.em15
-rw-r--r--ld/ld.texi13
-rw-r--r--ld/ldmain.c2
5 files changed, 41 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 2a6f1b5489d..fc6a43b4b44 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,11 @@
+2020-06-12 Roland McGrath <mcgrathr@google.com>
+
+ * NEWS: Mention -z start-stop-visibility=... option for ELF.
+ * ld.texi (Options): Document -z start-stop-visibility=... option.
+ * ldmain.c (main): Initialize link_info.start_stop_visibility.
+ * emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
+ Parse -z start-stop-visibility=... option.
+
2020-06-11 Alan Modra <amodra@gmail.com>
* testsuite/ld-plugin/lto.exp (lto_link_tests): Move lto-6,
diff --git a/ld/NEWS b/ld/NEWS
index 485e1cf5b9a..6955937429b 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -25,6 +25,9 @@
searched relative to the directory of the linker script before other search
paths.
+* Add ELF linker command-line option `-z start-stop-visibility=...' to control
+ the visibility of synthetic `__start_SECNAME` and `__stop_SECNAME` symbols.
+
Changes in 2.34:
* The ld check for "PHDR segment not covered by LOAD segment" is more
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index c4979eb9538..c577e8b2e61 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -749,6 +749,21 @@ fragment <<EOF
{
link_info.flags_1 |= DF_1_GLOBAUDIT;
}
+ else if (CONST_STRNEQ (optarg, "start-stop-visibility="))
+ {
+ if (strcmp (optarg, "start-stop-visibility=default") == 0)
+ link_info.start_stop_visibility = STV_DEFAULT;
+ else if (strcmp (optarg, "start-stop-visibility=internal") == 0)
+ link_info.start_stop_visibility = STV_INTERNAL;
+ else if (strcmp (optarg, "start-stop-visibility=hidden") == 0)
+ link_info.start_stop_visibility = STV_HIDDEN;
+ else if (strcmp (optarg, "start-stop-visibility=protected") == 0)
+ link_info.start_stop_visibility = STV_PROTECTED;
+ else
+ einfo (_("%F%P: invalid visibility in \`-z %s'; "
+ "must be default, internal, hidden, or protected"),
+ optarg);
+ }
EOF
if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
diff --git a/ld/ld.texi b/ld/ld.texi
index bf474d4c62b..b89c1a57c0b 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1373,6 +1373,19 @@ 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-visibility=@var{value}
+@cindex visibility
+@cindex ELF symbol visibility
+Specify the ELF symbol visibility for synthesized
+@code{__start_SECNAME} and @code{__stop_SECNAME} symbols (@pxref{Input
+Section Example}). @var{value} must be exactly @samp{default},
+@samp{internal}, @samp{hidden}, or @samp{protected}. If no @samp{-z
+start-stop-visibility} option is given, @samp{protected} is used for
+compatibility with historical practice. However, it's highly
+recommended to use @samp{-z start-stop-visibility=hidden} in new
+programs and shared libraries so that these symbols are not exported
+between shared objects, which is not usually what's intended.
+
@item text
@itemx notext
@itemx textoff
diff --git a/ld/ldmain.c b/ld/ldmain.c
index e2c559ea3e0..b0ce69f1186 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -27,6 +27,7 @@
#include "bfdlink.h"
#include "ctf-api.h"
#include "filenames.h"
+#include "elf/common.h"
#include "ld.h"
#include "ldmain.h"
@@ -307,6 +308,7 @@ main (int argc, char **argv)
#ifdef DEFAULT_NEW_DTAGS
link_info.new_dtags = DEFAULT_NEW_DTAGS;
#endif
+ link_info.start_stop_visibility = STV_PROTECTED;
ldfile_add_arch ("");
emulation = get_emulation (argc, argv);