Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -559,14 +559,6 @@ return Symtab::X->addSynthetic(Name, Sec, Val, StOther); } -template -static void addSynthetic(StringRef Name, OutputSectionBase *Sec, - typename ELFT::uint Val) { - SymbolBody *S = Symtab::X->find(Name); - if (!S || S->isUndefined() || S->isShared()) - Symtab::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 // executable. The runtime needs these symbols in order to resolve @@ -953,13 +945,9 @@ template void Writer::addStartEndSymbols() { auto Define = [&](StringRef Start, StringRef End, OutputSectionBase *OS) { - if (OS) { - addSynthetic(Start, OS, 0); - addSynthetic(End, OS, DefinedSynthetic::SectionEnd); - } else { - addOptionalSynthetic(Start, (OutputSectionBase *)nullptr, 0); - addOptionalSynthetic(End, (OutputSectionBase *)nullptr, 0); - } + // These symbols resolve to the image base if the section does not exist. + addOptionalSynthetic(Start, OS, 0); + addOptionalSynthetic(End, OS, OS ? DefinedSynthetic::SectionEnd : 0); }; Define("__preinit_array_start", "__preinit_array_end", Index: lld/trunk/test/ELF/gc-sections.s =================================================================== --- lld/trunk/test/ELF/gc-sections.s +++ lld/trunk/test/ELF/gc-sections.s @@ -21,8 +21,6 @@ # NOGC: Name: c # NOGC: Name: x # NOGC: Name: y -# NOGC: Name: __preinit_array_start -# NOGC: Name: __preinit_array_end # NOGC: Name: d # GC1: Name: .eh_frame @@ -38,8 +36,6 @@ # GC1: Name: c # GC1-NOT: Name: x # GC1-NOT: Name: y -# GC1: Name: __preinit_array_start -# GC1: Name: __preinit_array_end # GC1-NOT: Name: d # GC2: Name: .eh_frame @@ -55,8 +51,6 @@ # GC2: Name: c # GC2-NOT: Name: x # GC2-NOT: Name: y -# GC2: Name: __preinit_array_start -# GC2: Name: __preinit_array_end # GC2: Name: d .globl _start, d