Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -115,6 +115,7 @@ bool ZNow; bool ZOrigin; bool ZRelro; + bool ForcedEntry = false; UnresolvedPolicy UnresolvedSymbols; BuildIdKind BuildId = BuildIdKind::None; ELFKind EKind = ELFNoneKind; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -551,8 +551,10 @@ // Add entry symbol. Note that AMDGPU binaries have no entry points. if (Config->Entry.empty() && !Config->Shared && !Config->Relocatable && - Config->EMachine != EM_AMDGPU) + Config->EMachine != EM_AMDGPU) { Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start"; + Config->ForcedEntry = true; + } // Default output filename is "a.out" by the Unix tradition. if (Config->OutputFile.empty()) Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -740,8 +740,11 @@ // We only report undefined symbols in regular objects. This means that we // will accept an undefined reference in bitcode if it can be optimized out. - if (S->IsUsedInRegularObj && Body->isUndefined() && !S->isWeak()) + if (S->IsUsedInRegularObj && Body->isUndefined() && !S->isWeak()) { + if (S == Config->EntrySym && Config->ForcedEntry) + continue; reportUndefined(Body); + } if (!includeInSymtab(*Body)) continue; Index: test/ELF/entry.s =================================================================== --- test/ELF/entry.s +++ test/ELF/entry.s @@ -1,5 +1,6 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 -# RUN: not ld.lld %t1 -o %t2 +# RUN: ld.lld %t1 -o %t2 +# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=NOENTRY %s # RUN: ld.lld %t1 -o %t2 -e entry # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=SYM %s # RUN: ld.lld %t1 -shared -o %t2 -e entry @@ -11,6 +12,7 @@ # RUN: ld.lld %t1 -o %t2 -e 0777 # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=OCT %s +# NOENTRY: Entry: 0x0 # SYM: Entry: 0x11000 # DSO: Entry: 0x1000 # DEC: Entry: 0x1000 Index: test/ELF/reproduce-windows.s =================================================================== --- test/ELF/reproduce-windows.s +++ test/ELF/reproduce-windows.s @@ -5,7 +5,7 @@ # RUN: mkdir -p %t.dir/build # RUN: llvm-mc %s -o %t.dir/build/foo.o -filetype=obj -triple=x86_64-pc-linux # RUN: cd %t.dir -# RUN: not ld.lld build/foo.o --reproduce repro +# RUN: ld.lld build/foo.o --reproduce repro # RUN: cpio -t < repro.cpio | FileCheck %s # CHECK: repro/response.txt Index: test/ELF/undef-start.s =================================================================== --- test/ELF/undef-start.s +++ test/ELF/undef-start.s @@ -1,4 +1,3 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s -# CHECK: undefined symbol: _start +# RUN: ld.lld %t -o %t2 2>&1 # REQUIRES: x86