[lld] r279262 - [ELF] - Give automatically generated __start_* and __stop_* symbols default visibility.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 08:36:32 PDT 2016
Author: grimar
Date: Fri Aug 19 10:36:32 2016
New Revision: 279262
URL: http://llvm.org/viewvc/llvm-project?rev=279262&view=rev
Log:
[ELF] - Give automatically generated __start_* and __stop_* symbols default visibility.
This patch is opposite to D19024, which made this symbols to be hidden by default.
Unfortunately FreeBSD loader wants to see
start_set_modmetadata_set/stop_set_modmetadata_set in the dynamic symbol table.
They were not placed there because had hidden visibility.
Patch makes them to have default visibility again.
Differential revision: https://reviews.llvm.org/D23552
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/startstop-shared.s
lld/trunk/test/ELF/startstop.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=279262&r1=279261&r2=279262&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Aug 19 10:36:32 2016
@@ -51,8 +51,8 @@ static void addRegular(SymbolAssignment
}
template <class ELFT> static void addSynthetic(SymbolAssignment *Cmd) {
- Symbol *Sym = Symtab<ELFT>::X->addSynthetic(Cmd->Name, nullptr, 0);
- Sym->Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
+ Symbol *Sym = Symtab<ELFT>::X->addSynthetic(
+ Cmd->Name, nullptr, 0, Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT);
Cmd->Sym = Sym->body();
}
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=279262&r1=279261&r2=279262&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Fri Aug 19 10:36:32 2016
@@ -418,12 +418,12 @@ Symbol *SymbolTable<ELFT>::addRegular(St
template <typename ELFT>
Symbol *SymbolTable<ELFT>::addSynthetic(StringRef N,
OutputSectionBase<ELFT> *Section,
- uintX_t Value) {
+ uintX_t Value, uint8_t StOther) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) =
- insert(N, STT_NOTYPE, STV_HIDDEN, /*CanOmitFromDynSym*/ false,
- /*IsUsedInRegularObj*/ true, nullptr);
+ std::tie(S, WasInserted) = insert(N, STT_NOTYPE, /*Visibility*/ StOther & 0x3,
+ /*CanOmitFromDynSym*/ false,
+ /*IsUsedInRegularObj*/ true, nullptr);
int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, STB_GLOBAL);
if (Cmp > 0)
replaceBody<DefinedSynthetic<ELFT>>(S, N, Value, Section);
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=279262&r1=279261&r2=279262&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Fri Aug 19 10:36:32 2016
@@ -65,7 +65,7 @@ public:
InputSectionBase<ELFT> *Section);
Symbol *addRegular(StringRef Name, uint8_t Binding, uint8_t StOther);
Symbol *addSynthetic(StringRef N, OutputSectionBase<ELFT> *Section,
- uintX_t Value);
+ uintX_t Value, uint8_t StOther);
void addShared(SharedFile<ELFT> *F, StringRef Name, const Elf_Sym &Sym,
const typename ELFT::Verdef *Verdef);
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=279262&r1=279261&r2=279262&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Aug 19 10:36:32 2016
@@ -519,7 +519,7 @@ static Symbol *addOptionalSynthetic(Stri
return nullptr;
if (!S->isUndefined() && !S->isShared())
return S->symbol();
- return Symtab<ELFT>::X->addSynthetic(Name, Sec, Val);
+ return Symtab<ELFT>::X->addSynthetic(Name, Sec, Val, STV_HIDDEN);
}
template <class ELFT>
@@ -527,7 +527,7 @@ static void addSynthetic(StringRef Name,
typename ELFT::uint Val) {
SymbolBody *S = Symtab<ELFT>::X->find(Name);
if (!S || S->isUndefined() || S->isShared())
- Symtab<ELFT>::X->addSynthetic(Name, Sec, Val);
+ Symtab<ELFT>::X->addSynthetic(Name, Sec, Val, STV_HIDDEN);
}
// The beginning and the ending of .rel[a].plt section are marked
// with __rel[a]_iplt_{start,end} symbols if it is a statically linked
@@ -554,7 +554,8 @@ template <class ELFT> void Writer<ELFT>:
// so that it points to an absolute address which is relative to GOT.
// See "Global Data Symbols" in Chapter 6 in the following document:
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
- Symtab<ELFT>::X->addSynthetic("_gp", Out<ELFT>::Got, MipsGPOffset);
+ Symtab<ELFT>::X->addSynthetic("_gp", Out<ELFT>::Got, MipsGPOffset,
+ STV_HIDDEN);
// On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
// start of function and 'gp' pointer into GOT.
@@ -701,7 +702,8 @@ template <class ELFT> void Writer<ELFT>:
// Even the author of gold doesn't remember why gold behaves that way.
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
if (Out<ELFT>::DynSymTab)
- Symtab<ELFT>::X->addSynthetic("_DYNAMIC", Out<ELFT>::Dynamic, 0);
+ Symtab<ELFT>::X->addSynthetic("_DYNAMIC", Out<ELFT>::Dynamic, 0,
+ STV_HIDDEN);
// Define __rel[a]_iplt_{start,end} symbols if needed.
addRelIpltSymbols();
@@ -893,11 +895,11 @@ void Writer<ELFT>::addStartStopSymbols(O
StringRef Stop = Saver.save("__stop_" + S);
if (SymbolBody *B = Symtab<ELFT>::X->find(Start))
if (B->isUndefined())
- Symtab<ELFT>::X->addSynthetic(Start, Sec, 0);
+ Symtab<ELFT>::X->addSynthetic(Start, Sec, 0, B->getVisibility());
if (SymbolBody *B = Symtab<ELFT>::X->find(Stop))
if (B->isUndefined())
- Symtab<ELFT>::X->addSynthetic(Stop, Sec,
- DefinedSynthetic<ELFT>::SectionEnd);
+ Symtab<ELFT>::X->addSynthetic(
+ Stop, Sec, DefinedSynthetic<ELFT>::SectionEnd, B->getVisibility());
}
template <class ELFT>
Modified: lld/trunk/test/ELF/startstop-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/startstop-shared.s?rev=279262&r1=279261&r2=279262&view=diff
==============================================================================
--- lld/trunk/test/ELF/startstop-shared.s (original)
+++ lld/trunk/test/ELF/startstop-shared.s Fri Aug 19 10:36:32 2016
@@ -6,21 +6,23 @@
.data
.quad __start_foo
.section foo,"aw"
-// By default the symbol is hidden.
-// CHECK: R_X86_64_RELATIVE - 0x[[ADDR1:.*]]
.hidden __start_bar
.quad __start_bar
.section bar,"a"
-// References do not affect the visibility.
-// CHECK: R_X86_64_RELATIVE - 0x[[ADDR2:.*]]
+
+// Test that we are able to hide the symbol.
+// CHECK: R_X86_64_RELATIVE - 0x[[ADDR:.*]]
+
+// By default the symbol is visible and we need a dynamic reloc.
+// CHECK: R_X86_64_64 __start_foo 0x0
// CHECK: Name: __start_bar
-// CHECK-NEXT: Value: 0x[[ADDR2]]
+// CHECK-NEXT: Value: 0x[[ADDR]]
// CHECK-NEXT: Size:
// CHECK-NEXT: Binding: Local
// CHECK: Name: __start_foo
-// CHECK-NEXT: Value: 0x[[ADDR1]]
+// CHECK-NEXT: Value:
// CHECK-NEXT: Size:
-// CHECK-NEXT: Binding: Local
+// CHECK-NEXT: Binding: Global
Modified: lld/trunk/test/ELF/startstop.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/startstop.s?rev=279262&r1=279261&r2=279262&view=diff
==============================================================================
--- lld/trunk/test/ELF/startstop.s (original)
+++ lld/trunk/test/ELF/startstop.s Fri Aug 19 10:36:32 2016
@@ -22,30 +22,46 @@
// SYMBOL: Relocations [
// SYMBOL-NEXT: Section ({{.*}}) .rela.dyn {
-// SYMBOL-NEXT: 0x3000 R_X86_64_RELATIVE - 0x3020
-// SYMBOL-NEXT: 0x3008 R_X86_64_RELATIVE - 0x3021
-// SYMBOL-NEXT: 0x3010 R_X86_64_RELATIVE - 0x3010
-// SYMBOL-NEXT: 0x3018 R_X86_64_RELATIVE - 0x3011
+// SYMBOL-NEXT: 0x3010 R_X86_64_64 __stop_zed1 0x0
+// SYMBOL-NEXT: 0x3018 R_X86_64_64 __stop_zed1 0x1
+// SYMBOL-NEXT: 0x3000 R_X86_64_64 __stop_zed2 0x0
+// SYMBOL-NEXT: 0x3008 R_X86_64_64 __stop_zed2 0x1
// SYMBOL-NEXT: }
// SYMBOL-NEXT: ]
// SYMBOL: Symbol {
// SYMBOL: Name: __start_bar
// SYMBOL: Value: 0x1012
+// SYMBOL: STV_HIDDEN
// SYMBOL: Section: bar
// SYMBOL: }
// SYMBOL-NOT: Section: __stop_bar
// SYMBOL: Symbol {
// SYMBOL: Name: __start_foo
// SYMBOL: Value: 0x100F
+// SYMBOL: STV_HIDDEN
// SYMBOL: Section: foo
// SYMBOL: }
// SYMBOL: Symbol {
// SYMBOL: Name: __stop_foo
// SYMBOL: Value: 0x1012
+// STMBOL: STV_HIDDEN
// SYMBOL: Section: foo
// SYMBOL: }
+// SYMBOL: Symbol {
+// SYMBOL: Name: __stop_zed1
+// SYMBOL: Value: 0x3010
+// STMBOL: Other: 0
+// SYMBOL: Section: zed1
+// SYMBOL: }
+// SYMBOL: Symbol {
+// SYMBOL: Name: __stop_zed2
+// SYMBOL: Value: 0x3020
+// STMBOL: Other: 0
+// SYMBOL: Section: zed2
+// SYMBOL: }
+
.hidden __start_foo
.hidden __stop_foo
.hidden __start_bar
More information about the llvm-commits
mailing list