diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -1102,10 +1102,16 @@ if (config->entry && !isa(config->entry)) prepareBranchTarget(config->entry); scanRelocations(); + + // Do not proceed if there was an undefined symbol. + if (errorCount()) + return; + if (in.stubHelper->isNeeded()) in.stubHelper->setup(); scanSymbols(); createOutputSections(); + // After this point, we create no new segments; HOWEVER, we might // yet create branch-range extension thunks for architectures whose // hardware call instructions have limited range, e.g., ARM(64). diff --git a/lld/test/MachO/invalid/arm64-thunk-undefined.s b/lld/test/MachO/invalid/arm64-thunk-undefined.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/invalid/arm64-thunk-undefined.s @@ -0,0 +1,24 @@ +# REQUIRES: aarch64 + +# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.o +## This shouldn't assert. +# RUN: not %lld -arch arm64 -lSystem -o %t/thunk %t.o 2>&1 | FileCheck %s + +# CHECK: error: undefined symbol: _g + +.subsections_via_symbols + +.p2align 2 + +.globl _main, _g + +.globl _main +_main: + bl _g + ret + +_filler1: +.space 0x4000000 + +_filler2: +.space 0x4000000