Skip to content

[BOLT] Improve constant island disassembly #127971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2025
Merged

Conversation

maksfb
Copy link
Contributor

@maksfb maksfb commented Feb 20, 2025

  • Add label that identifies constant island.
  • Support cases where the island is located after the function.

* Add label that identifies constant island.
* Support cases where the island is located after the function.
@llvmbot
Copy link
Member

llvmbot commented Feb 20, 2025

@llvm/pr-subscribers-bolt

Author: Maksim Panchenko (maksfb)

Changes
  • Add label that identifies constant island.
  • Support cases where the island is located after the function.

Full diff: https://github.com/llvm/llvm-project/pull/127971.diff

2 Files Affected:

  • (modified) bolt/lib/Core/BinaryFunction.cpp (+6-1)
  • (modified) bolt/test/AArch64/data-in-code.s (+8-2)
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index bc45caf3ec8b7..1e427b2df11cf 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -498,6 +498,11 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
     if (!IslandOffset)
       return;
 
+    // Print label if it exists at this offset.
+    if (const BinaryData *BD =
+            BC.getBinaryDataAtAddress(getAddress() + *IslandOffset))
+      OS << BD->getName() << ":\n";
+
     const size_t IslandSize = getSizeOfDataInCodeAt(*IslandOffset);
     BC.printData(OS, BC.extractData(getAddress() + *IslandOffset, IslandSize),
                  *IslandOffset);
@@ -1066,7 +1071,7 @@ size_t BinaryFunction::getSizeOfDataInCodeAt(uint64_t Offset) const {
   auto Iter = Islands->CodeOffsets.upper_bound(Offset);
   if (Iter != Islands->CodeOffsets.end())
     return *Iter - Offset;
-  return getSize() - Offset;
+  return getMaxSize() - Offset;
 }
 
 std::optional<uint64_t>
diff --git a/bolt/test/AArch64/data-in-code.s b/bolt/test/AArch64/data-in-code.s
index 8d3179a0c3350..1df5d4568542f 100644
--- a/bolt/test/AArch64/data-in-code.s
+++ b/bolt/test/AArch64/data-in-code.s
@@ -7,7 +7,8 @@
 ## Check disassembly of BOLT input.
 # RUN: llvm-objdump %t.exe -d | FileCheck %s
 
-# RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm | FileCheck %s
+# RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm \
+# RUN:   | FileCheck %s --check-prefixes CHECK,CHECK-BOLT-ONLY
 
 .text
 .balign 4
@@ -16,16 +17,21 @@
 .type _start, %function
 _start:
   mov x0, #0x0
+  ldr x1, .L1
   .word 0x4f82e010
   ret
+.size _start, .-_start
+.L1:
   .byte 0x0, 0xff, 0x42
 # CHECK-LABEL: _start
 # CHECK:        mov x0, #0x0
+# CHECK-NEXT:   ldr x1
+# CHECK-BOLT-ONLY-SAME: ISLANDat[[ADDR:]]
 # CHECK-NEXT:   .word 0x4f82e010
 # CHECK-NEXT:   ret
+# CHECK-BOLT-ONLY-NEXT: ISLANDat[[ADDR]]
 # CHECK-NEXT:   .short 0xff00
 # CHECK-NEXT:   .byte 0x42
-.size _start, .-_start
 
 ## Force relocation mode.
   .reloc 0, R_AARCH64_NONE

Copy link
Member

@dcci dcci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maksfb maksfb merged commit 0ba391a into llvm:main Feb 20, 2025
9 checks passed
@maksfb maksfb deleted the gh-fix-island branch March 6, 2025 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants