From 3fe0d0275ac706c48129f40d022f94191297ccc9 Mon Sep 17 00:00:00 2001 From: Ash Dobrescu Date: Tue, 14 Oct 2025 15:23:02 +0000 Subject: [PATCH 1/6] [BOLT] Check entry point address is not in constant island --- bolt/lib/Core/BinaryContext.cpp | 13 +++++++-- bolt/test/AArch64/constant-island-entry.s | 35 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 bolt/test/AArch64/constant-island-entry.s 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..bd0906d87f15f --- /dev/null +++ b/bolt/test/AArch64/constant-island-entry.s @@ -0,0 +1,35 @@ +// This test checks that we ignore functions which add an entry point that +// is in a costant island. + +# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-linux-gnu %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: + ret + nop + 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 + +.globl main +.type main, %function +main: + bl caller + ret From c447ccebec7477723d5bfe363f9a5d763e0a60a0 Mon Sep 17 00:00:00 2001 From: Asher Dobrescu Date: Tue, 14 Oct 2025 17:07:51 +0100 Subject: [PATCH 2/6] Update constant-island-entry.s --- bolt/test/AArch64/constant-island-entry.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bolt/test/AArch64/constant-island-entry.s b/bolt/test/AArch64/constant-island-entry.s index bd0906d87f15f..5b7b906dbf4ea 100644 --- a/bolt/test/AArch64/constant-island-entry.s +++ b/bolt/test/AArch64/constant-island-entry.s @@ -1,7 +1,7 @@ // This test checks that we ignore functions which add an entry point that // is in a costant island. -# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-linux-gnu %s -o %t.o +# 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 From e15e490d2d64d3724ab73e2db35558b220bf8ab7 Mon Sep 17 00:00:00 2001 From: Asher Dobrescu Date: Wed, 15 Oct 2025 11:19:17 +0100 Subject: [PATCH 3/6] Update comment in constant-island-entry.s --- bolt/test/AArch64/constant-island-entry.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bolt/test/AArch64/constant-island-entry.s b/bolt/test/AArch64/constant-island-entry.s index 5b7b906dbf4ea..bccfb82385119 100644 --- a/bolt/test/AArch64/constant-island-entry.s +++ b/bolt/test/AArch64/constant-island-entry.s @@ -1,5 +1,5 @@ // This test checks that we ignore functions which add an entry point that -// is in a costant island. +// 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 From d2506f796e04080fc24db8485504b3166b9c4197 Mon Sep 17 00:00:00 2001 From: Ash Dobrescu Date: Thu, 16 Oct 2025 13:36:19 +0000 Subject: [PATCH 4/6] Remove main block from test --- bolt/test/AArch64/constant-island-entry.s | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bolt/test/AArch64/constant-island-entry.s b/bolt/test/AArch64/constant-island-entry.s index bccfb82385119..d0eaad62d652e 100644 --- a/bolt/test/AArch64/constant-island-entry.s +++ b/bolt/test/AArch64/constant-island-entry.s @@ -27,9 +27,3 @@ constant_island: caller: bl constant_island ret - -.globl main -.type main, %function -main: - bl caller - ret From 8c24e71051f55cde802255a564586187e0ea16fc Mon Sep 17 00:00:00 2001 From: Asher Dobrescu Date: Thu, 16 Oct 2025 14:40:09 +0100 Subject: [PATCH 5/6] Remove ret from constant-island-entry.s --- bolt/test/AArch64/constant-island-entry.s | 1 - 1 file changed, 1 deletion(-) diff --git a/bolt/test/AArch64/constant-island-entry.s b/bolt/test/AArch64/constant-island-entry.s index d0eaad62d652e..483c8824e1b68 100644 --- a/bolt/test/AArch64/constant-island-entry.s +++ b/bolt/test/AArch64/constant-island-entry.s @@ -10,7 +10,6 @@ .globl func .type func, %function func: - ret nop b .Lafter_constant From dcb23f8ea6c9fad35c025bd58e2db5bdfe80f254 Mon Sep 17 00:00:00 2001 From: Asher Dobrescu Date: Thu, 16 Oct 2025 14:41:27 +0100 Subject: [PATCH 6/6] Update constant-island-entry.s --- bolt/test/AArch64/constant-island-entry.s | 1 - 1 file changed, 1 deletion(-) diff --git a/bolt/test/AArch64/constant-island-entry.s b/bolt/test/AArch64/constant-island-entry.s index 483c8824e1b68..6567114eb980a 100644 --- a/bolt/test/AArch64/constant-island-entry.s +++ b/bolt/test/AArch64/constant-island-entry.s @@ -10,7 +10,6 @@ .globl func .type func, %function func: - nop b .Lafter_constant .type constant_island, %object