[PATCH] D55682: [ELF] Support defining __start/__stop symbols as hidden
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 13 15:40:24 PST 2018
phosek created this revision.
phosek added a reviewer: ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
We cannot define these symbols as hidden by default because some
users apparently rely on using dlsym to look them up, see
https://sourceware.org/bugzilla/show_bug.cgi?id=21964
However, it's still useful to define them as hidden in many contexts.
To do so, this change introduces the -z hidden-start-stop-symbols
option that provides that ability.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D55682
Files:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Writer.cpp
lld/test/ELF/startstop-hidden.s
Index: lld/test/ELF/startstop-hidden.s
===================================================================
--- /dev/null
+++ lld/test/ELF/startstop-hidden.s
@@ -0,0 +1,26 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: ld.lld -z hidden-start-stop-symbols %t.o -o %t
+// RUN: llvm-readobj -symbols %t | FileCheck %s
+
+// CHECK: Symbol {
+// CHECK: Name: __start_bar
+// CHECK: STV_HIDDEN
+// CHECK: Section: bar
+// CHECK: }
+// CHECK: Symbol {
+// CHECK: Name: __start_foo
+// CHECK: STV_HIDDEN
+// CHECK: Section: foo
+// CHECK: }
+
+.quad __start_foo
+.section foo,"ax"
+
+.quad __start_bar
+.section bar,"ax"
+
+.global _start
+.text
+_start:
+ nop
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -1846,8 +1846,9 @@
StringRef S = Sec->Name;
if (!isValidCIdentifier(S))
return;
- addOptionalRegular(Saver.save("__start_" + S), Sec, 0, STV_PROTECTED);
- addOptionalRegular(Saver.save("__stop_" + S), Sec, -1, STV_PROTECTED);
+ uint8_t B = Config->ZHiddenStartStopSymbols ? STV_HIDDEN : STV_PROTECTED;
+ addOptionalRegular(Saver.save("__start_" + S), Sec, 0, B);
+ addOptionalRegular(Saver.save("__stop_" + S), Sec, -1, B);
}
static bool needsPtLoad(OutputSection *Sec) {
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -355,6 +355,7 @@
S == "nokeep-text-section-prefix" || S == "norelro" || S == "notext" ||
S == "now" || S == "origin" || S == "relro" || S == "retpolineplt" ||
S == "rodynamic" || S == "text" || S == "wxneeded" ||
+ S == "hidden-start-stop-symbols" ||
S.startswith("max-page-size=") || S.startswith("stack-size=");
}
@@ -872,6 +873,7 @@
Config->ZExecstack = getZFlag(Args, "execstack", "noexecstack", false);
Config->ZGlobal = hasZOption(Args, "global");
Config->ZHazardplt = hasZOption(Args, "hazardplt");
+ Config->ZHiddenStartStopSymbols = hasZOption(Args, "hidden-start-stop-symbols");
Config->ZInitfirst = hasZOption(Args, "initfirst");
Config->ZInterpose = hasZOption(Args, "interpose");
Config->ZKeepTextSectionPrefix = getZFlag(
Index: lld/ELF/Config.h
===================================================================
--- lld/ELF/Config.h
+++ lld/ELF/Config.h
@@ -186,6 +186,7 @@
bool ZExecstack;
bool ZGlobal;
bool ZHazardplt;
+ bool ZHiddenStartStopSymbols;
bool ZInitfirst;
bool ZInterpose;
bool ZKeepTextSectionPrefix;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55682.178153.patch
Type: text/x-patch
Size: 2618 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181213/3738881f/attachment.bin>
More information about the llvm-commits
mailing list