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; 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/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/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