forked from OSchip/llvm-project
ELF: Use hidden visibility for all DefinedSynthetic symbols.
This simplifies the code by allowing us to remove the visibility argument to functions that create synthetic symbols. The only functional change is that the visibility of the MIPS "_gp" symbol is now hidden. Because this symbol is defined in every executable or DSO, it would be difficult to observe a visibility change here. Differential Revision: http://reviews.llvm.org/D19033 llvm-svn: 266208
This commit is contained in:
parent
9b46861eae
commit
f6e9b4ec24
|
@ -161,8 +161,8 @@ DefinedRegular<ELFT> *SymbolTable<ELFT>::addAbsolute(StringRef Name,
|
|||
template <class ELFT>
|
||||
SymbolBody *SymbolTable<ELFT>::addSynthetic(StringRef Name,
|
||||
OutputSectionBase<ELFT> &Sec,
|
||||
uintX_t Val, uint8_t Visibility) {
|
||||
auto *Sym = new (Alloc) DefinedSynthetic<ELFT>(Name, Val, Sec, Visibility);
|
||||
uintX_t Val) {
|
||||
auto *Sym = new (Alloc) DefinedSynthetic<ELFT>(Name, Val, Sec);
|
||||
resolve(Sym);
|
||||
return Sym;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
DefinedRegular<ELFT> *addAbsolute(StringRef Name,
|
||||
uint8_t Visibility = llvm::ELF::STV_HIDDEN);
|
||||
SymbolBody *addSynthetic(StringRef Name, OutputSectionBase<ELFT> &Section,
|
||||
uintX_t Value, uint8_t Visibility);
|
||||
uintX_t Value);
|
||||
DefinedRegular<ELFT> *addIgnored(StringRef Name,
|
||||
uint8_t Visibility = llvm::ELF::STV_HIDDEN);
|
||||
|
||||
|
|
|
@ -296,9 +296,8 @@ UndefinedElf<ELFT>::UndefinedElf(const Elf_Sym &Sym)
|
|||
|
||||
template <typename ELFT>
|
||||
DefinedSynthetic<ELFT>::DefinedSynthetic(StringRef N, uintX_t Value,
|
||||
OutputSectionBase<ELFT> &Section,
|
||||
uint8_t StOther)
|
||||
: Defined(SymbolBody::DefinedSyntheticKind, N, STB_GLOBAL, StOther,
|
||||
OutputSectionBase<ELFT> &Section)
|
||||
: Defined(SymbolBody::DefinedSyntheticKind, N, STB_GLOBAL, STV_HIDDEN,
|
||||
0 /* Type */),
|
||||
Value(Value), Section(Section) {}
|
||||
|
||||
|
|
|
@ -269,8 +269,8 @@ InputSectionBase<ELFT> *DefinedRegular<ELFT>::NullInputSection;
|
|||
template <class ELFT> class DefinedSynthetic : public Defined {
|
||||
public:
|
||||
typedef typename ELFT::uint uintX_t;
|
||||
DefinedSynthetic(StringRef N, uintX_t Value, OutputSectionBase<ELFT> &Section,
|
||||
uint8_t StOther);
|
||||
DefinedSynthetic(StringRef N, uintX_t Value,
|
||||
OutputSectionBase<ELFT> &Section);
|
||||
|
||||
static bool classof(const SymbolBody *S) {
|
||||
return S->kind() == SymbolBody::DefinedSyntheticKind;
|
||||
|
|
|
@ -932,11 +932,10 @@ bool Writer<ELFT>::isDiscarded(InputSectionBase<ELFT> *S) const {
|
|||
template <class ELFT>
|
||||
static SymbolBody *
|
||||
addOptionalSynthetic(SymbolTable<ELFT> &Table, StringRef Name,
|
||||
OutputSectionBase<ELFT> &Sec, typename ELFT::uint Val,
|
||||
uint8_t Visibility) {
|
||||
OutputSectionBase<ELFT> &Sec, typename ELFT::uint Val) {
|
||||
if (!Table.find(Name))
|
||||
return nullptr;
|
||||
return Table.addSynthetic(Name, Sec, Val, Visibility);
|
||||
return Table.addSynthetic(Name, Sec, Val);
|
||||
}
|
||||
|
||||
// The beginning and the ending of .rel[a].plt section are marked
|
||||
|
@ -951,12 +950,11 @@ void Writer<ELFT>::addRelIpltSymbols() {
|
|||
return;
|
||||
StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start";
|
||||
ElfSym<ELFT>::RelaIpltStart =
|
||||
addOptionalSynthetic(Symtab, S, *Out<ELFT>::RelaPlt, 0, STV_HIDDEN);
|
||||
addOptionalSynthetic(Symtab, S, *Out<ELFT>::RelaPlt, 0);
|
||||
|
||||
S = Config->Rela ? "__rela_iplt_end" : "__rel_iplt_end";
|
||||
ElfSym<ELFT>::RelaIpltEnd =
|
||||
addOptionalSynthetic(Symtab, S, *Out<ELFT>::RelaPlt,
|
||||
DefinedSynthetic<ELFT>::SectionEnd, STV_HIDDEN);
|
||||
ElfSym<ELFT>::RelaIpltEnd = addOptionalSynthetic(
|
||||
Symtab, S, *Out<ELFT>::RelaPlt, DefinedSynthetic<ELFT>::SectionEnd);
|
||||
}
|
||||
|
||||
template <class ELFT> static bool includeInSymtab(const SymbolBody &B) {
|
||||
|
@ -1076,18 +1074,18 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
|
|||
// See "Global Data Symbols" in Chapter 6 in the following document:
|
||||
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
|
||||
ElfSym<ELFT>::MipsGp =
|
||||
Symtab.addSynthetic("_gp", *Out<ELFT>::Got, MipsGPOffset, STV_DEFAULT);
|
||||
Symtab.addSynthetic("_gp", *Out<ELFT>::Got, MipsGPOffset);
|
||||
|
||||
// On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
|
||||
// start of function and 'gp' pointer into GOT.
|
||||
ElfSym<ELFT>::MipsGpDisp = addOptionalSynthetic(
|
||||
Symtab, "_gp_disp", *Out<ELFT>::Got, MipsGPOffset, STV_HIDDEN);
|
||||
ElfSym<ELFT>::MipsGpDisp =
|
||||
addOptionalSynthetic(Symtab, "_gp_disp", *Out<ELFT>::Got, MipsGPOffset);
|
||||
// The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
|
||||
// pointer. This symbol is used in the code generated by .cpload pseudo-op
|
||||
// in case of using -mno-shared option.
|
||||
// https://sourceware.org/ml/binutils/2004-12/msg00094.html
|
||||
ElfSym<ELFT>::MipsLocalGp = addOptionalSynthetic(
|
||||
Symtab, "__gnu_local_gp", *Out<ELFT>::Got, MipsGPOffset, STV_HIDDEN);
|
||||
Symtab, "__gnu_local_gp", *Out<ELFT>::Got, MipsGPOffset);
|
||||
}
|
||||
|
||||
// In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol
|
||||
|
@ -1213,7 +1211,7 @@ template <class ELFT> void Writer<ELFT>::createSections() {
|
|||
// Even the author of gold doesn't remember why gold behaves that way.
|
||||
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
|
||||
if (isOutputDynamic())
|
||||
Symtab.addSynthetic("_DYNAMIC", *Out<ELFT>::Dynamic, 0, STV_HIDDEN);
|
||||
Symtab.addSynthetic("_DYNAMIC", *Out<ELFT>::Dynamic, 0);
|
||||
|
||||
// Define __rel[a]_iplt_{start,end} symbols if needed.
|
||||
addRelIpltSymbols();
|
||||
|
@ -1363,9 +1361,8 @@ template <class ELFT> void Writer<ELFT>::addStartEndSymbols() {
|
|||
auto Define = [&](StringRef Start, StringRef End,
|
||||
OutputSectionBase<ELFT> *OS) {
|
||||
if (OS) {
|
||||
Symtab.addSynthetic(Start, *OS, 0, STV_HIDDEN);
|
||||
Symtab.addSynthetic(End, *OS, DefinedSynthetic<ELFT>::SectionEnd,
|
||||
STV_HIDDEN);
|
||||
Symtab.addSynthetic(Start, *OS, 0);
|
||||
Symtab.addSynthetic(End, *OS, DefinedSynthetic<ELFT>::SectionEnd);
|
||||
} else {
|
||||
Symtab.addIgnored(Start);
|
||||
Symtab.addIgnored(End);
|
||||
|
@ -1395,11 +1392,10 @@ void Writer<ELFT>::addStartStopSymbols(OutputSectionBase<ELFT> *Sec) {
|
|||
StringRef Stop = Saver.save("__stop_" + S);
|
||||
if (SymbolBody *B = Symtab.find(Start))
|
||||
if (B->isUndefined())
|
||||
Symtab.addSynthetic(Start, *Sec, 0, STV_HIDDEN);
|
||||
Symtab.addSynthetic(Start, *Sec, 0);
|
||||
if (SymbolBody *B = Symtab.find(Stop))
|
||||
if (B->isUndefined())
|
||||
Symtab.addSynthetic(Stop, *Sec, DefinedSynthetic<ELFT>::SectionEnd,
|
||||
STV_HIDDEN);
|
||||
Symtab.addSynthetic(Stop, *Sec, DefinedSynthetic<ELFT>::SectionEnd);
|
||||
}
|
||||
|
||||
template <class ELFT> static bool needsPtLoad(OutputSectionBase<ELFT> *Sec) {
|
||||
|
|
|
@ -204,6 +204,17 @@ __start:
|
|||
# CHECK-NEXT: Section: Undefined (0x0)
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: Symbol {
|
||||
# CHECK-NEXT: Name: _gp
|
||||
# CHECK-NEXT: Value: 0x37FF0
|
||||
# CHECK-NEXT: Size: 0
|
||||
# CHECK-NEXT: Binding: Local
|
||||
# CHECK-NEXT: Type: None (0x0)
|
||||
# CHECK-NEXT: Other [ (0x2)
|
||||
# CHECK-NEXT: STV_HIDDEN (0x2)
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK-NEXT: Section: .got
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: Symbol {
|
||||
# CHECK-NEXT: Name: __start
|
||||
# CHECK-NEXT: Value: 0x20000
|
||||
# CHECK-NEXT: Size: 0
|
||||
|
@ -212,15 +223,6 @@ __start:
|
|||
# CHECK-NEXT: Other: 0
|
||||
# CHECK-NEXT: Section: .text
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: Symbol {
|
||||
# CHECK-NEXT: Name: _gp
|
||||
# CHECK-NEXT: Value: 0x37FF0
|
||||
# CHECK-NEXT: Size: 0
|
||||
# CHECK-NEXT: Binding: Global
|
||||
# CHECK-NEXT: Type: None (0x0)
|
||||
# CHECK-NEXT: Other: 0
|
||||
# CHECK-NEXT: Section: .got
|
||||
# CHECK-NEXT: }
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK-NEXT: ProgramHeaders [
|
||||
# CHECK-NEXT: ProgramHeader {
|
||||
|
|
|
@ -47,8 +47,8 @@
|
|||
# EXE-DAG: 0x70000005 MIPS_FLAGS NOTPOT
|
||||
# EXE-DAG: 0x70000006 MIPS_BASE_ADDRESS
|
||||
# EXE-DAG: 0x7000000A MIPS_LOCAL_GOTNO 2
|
||||
# EXE-DAG: 0x70000011 MIPS_SYMTABNO 3
|
||||
# EXE-DAG: 0x70000013 MIPS_GOTSYM 0x3
|
||||
# EXE-DAG: 0x70000011 MIPS_SYMTABNO 2
|
||||
# EXE-DAG: 0x70000013 MIPS_GOTSYM 0x2
|
||||
# EXE-DAG: 0x70000016 MIPS_RLD_MAP [[RLDMAPADDR]]
|
||||
# EXE: ]
|
||||
|
||||
|
@ -73,7 +73,6 @@
|
|||
# DSO: Name: @
|
||||
# DSO: Name: __start@
|
||||
# DSO: Name: _foo@
|
||||
# DSO: Name: _gp@
|
||||
# DSO: ]
|
||||
# DSO: DynamicSection [
|
||||
# DSO-NEXT: Tag Type Name/Value
|
||||
|
@ -82,8 +81,8 @@
|
|||
# DSO-DAG: 0x70000005 MIPS_FLAGS NOTPOT
|
||||
# DSO-DAG: 0x70000006 MIPS_BASE_ADDRESS 0x0
|
||||
# DSO-DAG: 0x7000000A MIPS_LOCAL_GOTNO 2
|
||||
# DSO-DAG: 0x70000011 MIPS_SYMTABNO 4
|
||||
# DSO-DAG: 0x70000013 MIPS_GOTSYM 0x4
|
||||
# DSO-DAG: 0x70000011 MIPS_SYMTABNO 3
|
||||
# DSO-DAG: 0x70000013 MIPS_GOTSYM 0x3
|
||||
# DSO: ]
|
||||
|
||||
.text
|
||||
|
|
|
@ -47,9 +47,9 @@ v1:
|
|||
# EXE_SYM: Sections:
|
||||
# EXE_SYM: .got 0000000c 0000000000030000 DATA
|
||||
# EXE_SYM: SYMBOL TABLE:
|
||||
# EXE_SYM: 00040000 g .data 00000004 v1
|
||||
# EXE_SYM: 00037ff0 .got 00000000 _gp
|
||||
# EXE_SYM: 00037ff0 .got 00000000 .hidden _gp
|
||||
# ^-- .got + GP offset (0x7ff0)
|
||||
# EXE_SYM: 00040000 g .data 00000004 v1
|
||||
|
||||
|
||||
# EXE_GOT_BE: Contents of section .got:
|
||||
|
@ -71,9 +71,9 @@ v1:
|
|||
# DSO_SYM: Sections:
|
||||
# DSO_SYM: .got 0000000c 0000000000020000 DATA
|
||||
# DSO_SYM: SYMBOL TABLE:
|
||||
# DSO_SYM: 00030000 g .data 00000004 v1
|
||||
# DSO_SYM: 00027ff0 .got 00000000 _gp
|
||||
# DSO_SYM: 00027ff0 .got 00000000 .hidden _gp
|
||||
# ^-- .got + GP offset (0x7ff0)
|
||||
# DSO_SYM: 00030000 g .data 00000004 v1
|
||||
|
||||
# DSO_GOT_BE: Contents of section .got:
|
||||
# DSO_GOT_BE: 20000 00000000 80000000 00030000
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
# DIS-NEXT: 10000: 3c 08 00 01 lui $8, 1
|
||||
# DIS-NEXT: 10004: 21 08 7f f0 addi $8, $8, 32752
|
||||
# ^-- 0x37ff0 & 0xffff
|
||||
# DIS: 00027ff0 .got 00000000 _gp
|
||||
# DIS: 00027ff0 .got 00000000 .hidden _gp
|
||||
|
||||
# REL: Relocations [
|
||||
# REL-NEXT: ]
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# CHECK-NEXT: 20000: 3c 08 00 03 lui $8, 3
|
||||
# CHECK-NEXT: 20004: 21 08 7f f0 addi $8, $8, 32752
|
||||
|
||||
# CHECK: 00037ff0 .got 00000000 _gp
|
||||
# CHECK: 00037ff0 .got 00000000 .hidden _gp
|
||||
|
||||
.text
|
||||
.globl __start
|
||||
|
|
|
@ -28,4 +28,4 @@
|
|||
# CHECK: SYMBOL TABLE:
|
||||
# CHECK: 00010000 .text 00000000 foo
|
||||
# CHECK: 00010010 .text 00000000 bar
|
||||
# CHECK: 00027ff0 .got 00000000 _gp
|
||||
# CHECK: 00027ff0 .got 00000000 .hidden _gp
|
||||
|
|
|
@ -28,4 +28,4 @@ v1:
|
|||
# CHECK: SYMBOL TABLE:
|
||||
# CHECK: 00010008 .text 00000000 bar
|
||||
# CHECK: 00010004 .text 00000000 foo
|
||||
# CHECK: 00027ff0 .got 00000000 _gp
|
||||
# CHECK: 00027ff0 .got 00000000 .hidden _gp
|
||||
|
|
|
@ -25,9 +25,9 @@ __start:
|
|||
# ^-- %lo(0x37ff0-0x20004+4)
|
||||
|
||||
# EXE: SYMBOL TABLE:
|
||||
# EXE: 00037ff0 .got 00000000 .hidden _gp
|
||||
# EXE: 00020000 .text 00000000 __start
|
||||
# EXE: 00020010 .text 00000000 _foo
|
||||
# EXE: 00037ff0 .got 00000000 _gp
|
||||
|
||||
# SO: Disassembly of section .text:
|
||||
# SO-NEXT: __start:
|
||||
|
@ -37,6 +37,6 @@ __start:
|
|||
# ^-- %lo(0x27ff0-0x10004+4)
|
||||
|
||||
# SO: SYMBOL TABLE:
|
||||
# SO: 00027ff0 .got 00000000 .hidden _gp
|
||||
# SO: 00010000 .text 00000000 __start
|
||||
# SO: 00010010 .text 00000000 _foo
|
||||
# SO: 00027ff0 .got 00000000 _gp
|
||||
|
|
Loading…
Reference in New Issue