Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -1021,8 +1021,9 @@ // If an entry symbol is in a static archive, pull out that file now // to complete the symbol table. After this, no new names except a // few linker-synthesized ones will be added to the symbol table. - if (Symtab->find(Config->Entry)) - Symtab->addUndefined(Config->Entry); + if (SymbolBody *B = Symtab->find(Config->Entry)) + if (!B->isUndefined() || !B->symbol()->isWeak()) + Symtab->addUndefined(Config->Entry); // Return if there were name resolution errors. if (ErrorCount) Index: test/ELF/weak-entry.s =================================================================== --- /dev/null +++ test/ELF/weak-entry.s @@ -0,0 +1,13 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +# RUN: ld.lld %t -o %tout +# RUN: llvm-nm %tout | FileCheck %s + +# CHECK: w _start +# CHECK-NEXT: T foo + +.global foo +.weak _start +.text +foo: + .dc.a _start