Index: lld/MachO/ConcatOutputSection.cpp =================================================================== --- lld/MachO/ConcatOutputSection.cpp +++ lld/MachO/ConcatOutputSection.cpp @@ -109,7 +109,7 @@ // thus, we place thunks at monotonically increasing addresses. Once a thunk // is placed, it and all previous input-section addresses are final. // -// * MergedInputSection::finalize() and MergedInputSection::writeTo() merge +// * ConcatInputSection::finalize() and ConcatInputSection::writeTo() merge // the inputs and thunks vectors (both ordered by ascending address), which // is simple and cheap. @@ -295,6 +295,12 @@ thunkInfo.isec = make(isec->getSegName(), isec->getName()); thunkInfo.isec->parent = this; + + // This code runs after dead code removal. Need to set the `live` bit + // on the thunk isec so that asserts that check that only live sections + // get written are happy. + thunkInfo.isec->live = true; + StringRef thunkName = saver.save(funcSym->getName() + ".thunk." + std::to_string(thunkInfo.sequence++)); r.referent = thunkInfo.sym = symtab->addDefined( Index: lld/test/MachO/arm64-thunks.s =================================================================== --- lld/test/MachO/arm64-thunks.s +++ lld/test/MachO/arm64-thunks.s @@ -2,15 +2,17 @@ ## Check for the following: ## (1) address match between thunk definitions and call destinations -## (2) address match between thunk page+offset computations and function definitions +## (2) address match between thunk page+offset computations and function +## definitions ## (3) a second thunk is created when the first one goes out of range -## (4) early calls to a dylib stub use a thunk, and later calls the stub directly +## (4) early calls to a dylib stub use a thunk, and later calls the stub +## directly ## Notes: ## 0x4000000 = 64 Mi = half the magnitude of the forward-branch range # RUN: rm -rf %t; mkdir %t # RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t/input.o -# RUN: %lld -arch arm64 -lSystem -o %t/thunk %t/input.o +# RUN: %lld -arch arm64 -dead_strip -lSystem -o %t/thunk %t/input.o # RUN: llvm-objdump -d --no-show-raw-insn %t/thunk | FileCheck %s # CHECK: Disassembly of section __TEXT,__text: