Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -43,7 +43,7 @@ private: void copyLocalSymbols(); void addReservedSymbols(); - void createSections(); + bool createSections(); void addPredefinedSections(); template @@ -156,7 +156,8 @@ if (!Config->DiscardAll) copyLocalSymbols(); addReservedSymbols(); - createSections(); + if (!createSections()) + return; assignAddresses(); fixAbsoluteSymbols(); openFile(Config->OutputFile); @@ -382,7 +383,7 @@ if (Config->NoInhibitExec) warning(Msg); else - fatal(Msg); + error(Msg); } template @@ -796,7 +797,7 @@ } // Create output section objects and add them to OutputSections. -template void Writer::createSections() { +template bool Writer::createSections() { // Add .interp first because some loaders want to see that section // on the first page of the executable file when loaded into memory. if (needsInterpSection()) @@ -887,6 +888,11 @@ if (isOutputDynamic() && includeInDynamicSymtab(*Body)) Out::DynSymTab->addSymbol(Body); } + + // Do not proceed if there was an undefined symbol. + if (HasError) + return false; + addCommonSymbols(CommonSymbols); addCopyRelSymbols(CopyRelSymbols); @@ -915,6 +921,7 @@ for (OutputSectionBase *Sec : OutputSections) if (Sec != Out::DynStrTab) Sec->finalize(); + return true; } // This function add Out::* sections to OutputSections. Index: test/ELF/undef.s =================================================================== --- test/ELF/undef.s +++ test/ELF/undef.s @@ -1,8 +1,10 @@ # 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: bar in {{.*}} # CHECK: undefined symbol: foo in {{.*}} # REQUIRES: x86 - .globl _start; + .globl _start _start: call foo + call bar