From fc89b1c2d80f8aeed1236d4f80ca8047ff75f37e Mon Sep 17 00:00:00 2001 From: YongKang Zhu Date: Mon, 2 Feb 2026 16:05:40 -0800 Subject: [PATCH] [BOLT] Get symbol for const island referenced across func by relocation (#178988) When handling relocation in one function referencing code or data defined in another function, we should check if relocation target is constant island or not, and get the referenced symbol accordingly for both cases. --- bolt/lib/Rewrite/RewriteInstance.cpp | 7 ++++--- bolt/test/AArch64/constant-island-reference.s | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 bolt/test/AArch64/constant-island-reference.s diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index 3953653caf5c..b475c6e13790 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -3136,10 +3136,11 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection, ReferencedSymbol = nullptr; ExtractedValue = Address; } else if (RefFunctionOffset) { - if (ContainingBF && ContainingBF != ReferencedBF && - !ReferencedBF->isInConstantIsland(Address)) { + if (ContainingBF && ContainingBF != ReferencedBF) { ReferencedSymbol = - ReferencedBF->addEntryPointAtOffset(RefFunctionOffset); + ReferencedBF->isInConstantIsland(Address) + ? ReferencedBF->getOrCreateIslandAccess(Address) + : ReferencedBF->addEntryPointAtOffset(RefFunctionOffset); } else { ReferencedSymbol = ReferencedBF->getOrCreateLocalLabel(Address); diff --git a/bolt/test/AArch64/constant-island-reference.s b/bolt/test/AArch64/constant-island-reference.s new file mode 100644 index 000000000000..7148bbb29612 --- /dev/null +++ b/bolt/test/AArch64/constant-island-reference.s @@ -0,0 +1,20 @@ +// Test BOLT won't ignore function having reference to constant island +// that is defined in another function. + +// RUN: %clang %cxxflags -fuse-ld=lld %s -o %t.so -Wl,-q -no-pie +// RUN: llvm-bolt %t.so -o %t.bolt.so --strict + + .text + .type foo,@function +foo: + adrp x9, :got:_global_func_ptr + ldr x9, [x9, #:got_lo12:_global_func_ptr] + blr x9 + .size foo, .-foo + + .type bar,@function +bar: + nop +_global_func_ptr: + .quad 0 + .size bar, .-bar