Index: ELF/SymbolTable.h =================================================================== --- ELF/SymbolTable.h +++ ELF/SymbolTable.h @@ -55,7 +55,7 @@ DefinedRegular *addAbsolute(StringRef Name, uint8_t Visibility = llvm::ELF::STV_HIDDEN); SymbolBody *addSynthetic(StringRef Name, OutputSectionBase &Section, - uintX_t Value, uint8_t Visibility); + uintX_t Value); DefinedRegular *addIgnored(StringRef Name, uint8_t Visibility = llvm::ELF::STV_HIDDEN); Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -161,8 +161,8 @@ template SymbolBody *SymbolTable::addSynthetic(StringRef Name, OutputSectionBase &Sec, - uintX_t Val, uint8_t Visibility) { - auto *Sym = new (Alloc) DefinedSynthetic(Name, Val, Sec, Visibility); + uintX_t Val) { + auto *Sym = new (Alloc) DefinedSynthetic(Name, Val, Sec, STV_HIDDEN); resolve(Sym); return Sym; } Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -808,12 +808,12 @@ StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start"; if (Symtab.find(S)) ElfSym::RelaIpltStart = - Symtab.addSynthetic(S, *Out::RelaPlt, 0, STV_HIDDEN); + Symtab.addSynthetic(S, *Out::RelaPlt, 0); S = Config->Rela ? "__rela_iplt_end" : "__rel_iplt_end"; if (Symtab.find(S)) ElfSym::RelaIpltEnd = Symtab.addSynthetic( - S, *Out::RelaPlt, DefinedSynthetic::SectionEnd, STV_HIDDEN); + S, *Out::RelaPlt, DefinedSynthetic::SectionEnd); } template static bool includeInSymtab(const SymbolBody &B) { @@ -1061,7 +1061,7 @@ // 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::Dynamic, 0, STV_HIDDEN); + Symtab.addSynthetic("_DYNAMIC", *Out::Dynamic, 0); // Define __rel[a]_iplt_{start,end} symbols if needed. addRelIpltSymbols(); @@ -1211,9 +1211,8 @@ auto Define = [&](StringRef Start, StringRef End, OutputSectionBase *OS) { if (OS) { - Symtab.addSynthetic(Start, *OS, 0, STV_HIDDEN); - Symtab.addSynthetic(End, *OS, DefinedSynthetic::SectionEnd, - STV_HIDDEN); + Symtab.addSynthetic(Start, *OS, 0); + Symtab.addSynthetic(End, *OS, DefinedSynthetic::SectionEnd); } else { Symtab.addIgnored(Start); Symtab.addIgnored(End); @@ -1243,11 +1242,10 @@ StringRef Stop = Saver.save("__stop_" + S); if (SymbolBody *B = Symtab.find(Start)) if (B->isUndefined()) - Symtab.addSynthetic(Start, *Sec, 0, STV_DEFAULT); + Symtab.addSynthetic(Start, *Sec, 0); if (SymbolBody *B = Symtab.find(Stop)) if (B->isUndefined()) - Symtab.addSynthetic(Stop, *Sec, DefinedSynthetic::SectionEnd, - STV_DEFAULT); + Symtab.addSynthetic(Stop, *Sec, DefinedSynthetic::SectionEnd); } template static bool needsPtLoad(OutputSectionBase *Sec) { Index: test/ELF/startstop-shared.s =================================================================== --- test/ELF/startstop-shared.s +++ test/ELF/startstop-shared.s @@ -5,21 +5,21 @@ .quad __start_foo .section foo,"a" -// By default the symbol is visible and we need a dynamic reloc. -// CHECK: R_X86_64_64 __start_foo 0x0 +// By default the symbol is hidden. +// CHECK: R_X86_64_RELATIVE - 0x[[ADDR1:.*]] .hidden __start_bar .quad __start_bar .section bar,"a" -// Test that we are able to hide the symbol. -// CHECK: R_X86_64_RELATIVE - 0x[[ADDR:.*]] +// References do not affect the visibility. +// CHECK: R_X86_64_RELATIVE - 0x[[ADDR2:.*]] // CHECK: Name: __start_bar -// CHECK-NEXT: Value: 0x[[ADDR]] +// CHECK-NEXT: Value: 0x[[ADDR2]] // CHECK-NEXT: Size: // CHECK-NEXT: Binding: Local // CHECK: Name: __start_foo -// CHECK-NEXT: Value: +// CHECK-NEXT: Value: 0x[[ADDR1]] // CHECK-NEXT: Size: -// CHECK-NEXT: Binding: Global +// CHECK-NEXT: Binding: Local