diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp index dd0d041692484..c35775464751b 100644 --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -1336,8 +1336,17 @@ void BinaryContext::processInterproceduralReferences() { << Function.getPrintName() << " and " << TargetFunction->getPrintName() << '\n'; } - if (uint64_t Offset = Address - TargetFunction->getAddress()) - TargetFunction->addEntryPointAtOffset(Offset); + if (uint64_t Offset = Address - TargetFunction->getAddress()) { + if (!TargetFunction->isInConstantIsland(Address)) { + TargetFunction->addEntryPointAtOffset(Offset); + } else { + TargetFunction->setIgnored(); + this->outs() << "BOLT-WARNING: Ignoring entry point at address 0x" + << Twine::utohexstr(Address) + << " in constant island of function " << *TargetFunction + << '\n'; + } + } continue; } diff --git a/bolt/test/AArch64/constant-island-entry.s b/bolt/test/AArch64/constant-island-entry.s new file mode 100644 index 0000000000000..6567114eb980a --- /dev/null +++ b/bolt/test/AArch64/constant-island-entry.s @@ -0,0 +1,27 @@ +// This test checks that we ignore functions which add an entry point that +// is in a constant island. + +# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o +# RUN: %clang %cflags %t.o -pie -Wl,-q -o %t.exe +# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s + +# CHECK: BOLT-WARNING: Ignoring entry point at address 0x{{[0-9a-f]+}} in constant island of function func + +.globl func +.type func, %function +func: + b .Lafter_constant + +.type constant_island, %object +constant_island: + .xword 0xabcdef + +.Lafter_constant: + ret + .size func, .-func + +.globl caller +.type caller, %function +caller: + bl constant_island + ret