[lld] Fix lld crash wrt generated thunks growing away from the patched code (PR #170495)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 3 08:56:22 PST 2025


================
@@ -1981,11 +1981,12 @@ void ThunkCreator::createInitialThunkSections(
 
 ThunkSection *ThunkCreator::addThunkSection(OutputSection *os,
                                             InputSectionDescription *isd,
-                                            uint64_t off) {
+                                            uint64_t off,
+                                            bool isPrefix) {
   auto *ts = make<ThunkSection>(ctx, os, off);
   ts->partition = os->partition;
   if ((ctx.arg.fixCortexA53Errata843419 || ctx.arg.fixCortexA8) &&
-      !isd->sections.empty()) {
+      !isd->sections.empty() && !isPrefix) {
     // The errata fixes are sensitive to addresses modulo 4 KiB. When we add
     // thunks we disturb the base addresses of sections placed after the thunks
     // this makes patches we have generated redundant, and may cause us to
----------------
smithp35 wrote:

Can we update this comment to explain what isPrefix is used for? Possibly at the end of the block:

> isPrefix is a ThunkSection explicitly inserted before its target section. We suppress the rounding up of the size of these ThunkSections as unlike normal ThunkSections, they are small in size, but when BTI is enabled very frequent. This can bloat code-size and push the errata patches out of branch range.

https://github.com/llvm/llvm-project/pull/170495


More information about the llvm-commits mailing list