diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 3e1f723671b0..9f13ca667502 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -667,16 +667,15 @@ template void LinkerDriver::link(opt::InputArgList &Args) { // Note that AMDGPU binaries have no entries. if (!Config->Entry.empty()) { // It is either "-e " or "-e ". - if (Config->Entry.getAsInteger(0, Config->EntryAddr)) - Config->EntrySym = Symtab.addUndefined(Config->Entry); + Config->Entry.getAsInteger(0, Config->EntryAddr); } else if (!Config->Shared && !Config->Relocatable && Config->EMachine != EM_AMDGPU) { // -e was not specified. Use the default start symbol name // if it is resolvable. Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start"; - if (Symtab.find(Config->Entry)) - Config->EntrySym = Symtab.addUndefined(Config->Entry); } + if (Symtab.find(Config->Entry)) + Config->EntrySym = Symtab.addUndefined(Config->Entry); if (HasError) return; // There were duplicate symbols or incompatible files diff --git a/lld/test/ELF/linkerscript/linkerscript.s b/lld/test/ELF/linkerscript/linkerscript.s index 29e5428e734c..c103739c7458 100644 --- a/lld/test/ELF/linkerscript/linkerscript.s +++ b/lld/test/ELF/linkerscript/linkerscript.s @@ -60,11 +60,10 @@ # RUN: ld.lld -o %t2 %t.script %t # RUN: llvm-readobj %t2 > /dev/null +# The entry symbol should not cause an undefined error. # RUN: echo "ENTRY(_wrong_label)" > %t.script -# RUN: not ld.lld -o %t2 %t.script %t > %t.log 2>&1 -# RUN: FileCheck -check-prefix=ERR-ENTRY %s < %t.log - -# ERR-ENTRY: undefined symbol: _wrong_label +# RUN: ld.lld -o %t2 %t.script %t +# RUN: ld.lld --entry=abc -o %t2 %t # -e has precedence over linker script's ENTRY. # RUN: echo "ENTRY(_label)" > %t.script