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

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 27 16:22:47 PDT 2021


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a subscriber: kristof.beyls.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
thakis requested review of this revision.

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


https://reviews.llvm.org/D108853

Files:
  lld/MachO/ConcatOutputSection.cpp
  lld/test/MachO/arm64-thunks.s


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108853.369213.patch
Type: text/x-patch
Size: 2363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210827/ca1b06d7/attachment.bin>


More information about the llvm-commits mailing list