Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -546,15 +546,15 @@ } template -static Symbol *addOptionalSynthetic(StringRef Name, - OutputSectionBase *Sec, - typename ELFT::uint Val) { +static Symbol * +addOptionalSynthetic(StringRef Name, OutputSectionBase *Sec, + typename ELFT::uint Val, uint8_t StOther = STV_HIDDEN) { SymbolBody *S = Symtab::X->find(Name); if (!S) return nullptr; if (!S->isUndefined() && !S->isShared()) return S->symbol(); - return Symtab::X->addSynthetic(Name, Sec, Val, STV_HIDDEN); + return Symtab::X->addSynthetic(Name, Sec, Val, StOther); } template @@ -974,15 +974,9 @@ if (!isValidCIdentifier(S)) return; StringSaver Saver(Alloc); - StringRef Start = Saver.save("__start_" + S); - StringRef Stop = Saver.save("__stop_" + S); - if (SymbolBody *B = Symtab::X->find(Start)) - if (B->isUndefined()) - Symtab::X->addSynthetic(Start, Sec, 0, B->getVisibility()); - if (SymbolBody *B = Symtab::X->find(Stop)) - if (B->isUndefined()) - Symtab::X->addSynthetic( - Stop, Sec, DefinedSynthetic::SectionEnd, B->getVisibility()); + addOptionalSynthetic(Saver.save("__start_" + S), Sec, 0, STV_DEFAULT); + addOptionalSynthetic(Saver.save("__stop_" + S), Sec, + DefinedSynthetic::SectionEnd, STV_DEFAULT); } template Index: lld/trunk/test/ELF/Inputs/startstop-shared2.s =================================================================== --- lld/trunk/test/ELF/Inputs/startstop-shared2.s +++ lld/trunk/test/ELF/Inputs/startstop-shared2.s @@ -0,0 +1,2 @@ +.globl __start_foo +__start_foo: Index: lld/trunk/test/ELF/startstop-shared2.s =================================================================== --- lld/trunk/test/ELF/startstop-shared2.s +++ lld/trunk/test/ELF/startstop-shared2.s @@ -0,0 +1,14 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/startstop-shared2.s -o %t.o +// RUN: ld.lld -o %t.so %t.o -shared +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o +// RUN: ld.lld -o %t %t2.o %t.so +// RUN: llvm-objdump -s -h %t | FileCheck %s + +// CHECK: foo 00000000 0000000000011008 + +// CHECK: Contents of section .text: +// CHECK-NEXT: 11000 08100100 00000000 + +.quad __start_foo +.section foo,"ax"