[lld/mac] Don't assert on -dead_strip + arm64 range extension thunks

The assert is harmless and thinks worked fine in builds with asserts enabled,
but it's still nice to fix the assert.

Differential Revision: https://reviews.llvm.org/D108853
This commit is contained in:
Nico Weber
2021-08-27 19:20:29 -04:00
parent a4a5c00b53
commit 28be02f334
2 changed files with 12 additions and 4 deletions

View File

@@ -109,7 +109,7 @@ void ConcatOutputSection::addInput(ConcatInputSection *input) {
// 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 @@ void ConcatOutputSection::finalize() {
thunkInfo.isec =
make<ConcatInputSection>(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(

View File

@@ -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: