[PATCH] D127111: [BOLT][AArch64] Handle data at the beginning of a function when disassembling and building CFG.

Denis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 6 07:50:43 PDT 2022


treapster updated this revision to Diff 434475.
treapster added a comment.

Seems like clang used on buildkite doesn't mark .space directive as data, changed test to use repeated .byte instead


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127111/new/

https://reviews.llvm.org/D127111

Files:
  bolt/include/bolt/Core/BinaryFunction.h
  bolt/lib/Core/BinaryFunction.cpp
  bolt/lib/Core/Exceptions.cpp
  bolt/test/AArch64/data-at-0-offset.c


Index: bolt/test/AArch64/data-at-0-offset.c
===================================================================
--- /dev/null
+++ bolt/test/AArch64/data-at-0-offset.c
@@ -0,0 +1,17 @@
+// RUN: %clang -O2 -fPIE -Wl,-q -Wl,-pie  %s -o %t.exe
+// RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
+// CHECK-NOT: BOLT-WARNING
+
+void extra_space() {
+  asm volatile(".rept 256\n"
+               "    .byte 0xff\n"
+               ".endr\n");
+  return;
+}
+
+int main(int argc, char **argv) {
+  void (*fn)(void);
+  fn = extra_space + 256;
+  fn();
+  return 0;
+}
Index: bolt/lib/Core/Exceptions.cpp
===================================================================
--- bolt/lib/Core/Exceptions.cpp
+++ bolt/lib/Core/Exceptions.cpp
@@ -493,7 +493,7 @@
   Optional<uint64_t> LSDA = CurFDE.getLSDAAddress();
   Function.setLSDAAddress(LSDA ? *LSDA : 0);
 
-  uint64_t Offset = 0;
+  uint64_t Offset = Function.getFirstInstructionOffset();
   uint64_t CodeAlignment = CurFDE.getLinkedCIE()->getCodeAlignmentFactor();
   uint64_t DataAlignment = CurFDE.getLinkedCIE()->getDataAlignmentFactor();
   if (CurFDE.getLinkedCIE()->getPersonalityAddress()) {
Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -1383,6 +1383,9 @@
   // Reset symbolizer for the disassembler.
   BC.SymbolicDisAsm->setSymbolizer(nullptr);
 
+  if (uint64_t Offset = getFirstInstructionOffset())
+    Labels[Offset] = BC.Ctx->createNamedTempSymbol();
+
   clearList(Relocations);
 
   if (!IsSimple) {
@@ -1895,7 +1898,7 @@
     return false;
 
   assert(BasicBlocks.empty() && "basic block list should be empty");
-  assert((Labels.find(0) != Labels.end()) &&
+  assert((Labels.find(getFirstInstructionOffset()) != Labels.end()) &&
          "first instruction should always have a label");
 
   // Create basic blocks in the original layout order:
@@ -1999,9 +2002,9 @@
         updateOffset(LastInstrOffset);
       }
     }
-    if (Offset == 0) {
-      // Add associated CFI pseudos in the first offset (0)
-      addCFIPlaceholders(0, InsertBB);
+    if (Offset == getFirstInstructionOffset()) {
+      // Add associated CFI pseudos in the first offset
+      addCFIPlaceholders(Offset, InsertBB);
     }
 
     const bool IsBlockEnd = MIB->isTerminator(Instr);
Index: bolt/include/bolt/Core/BinaryFunction.h
===================================================================
--- bolt/include/bolt/Core/BinaryFunction.h
+++ bolt/include/bolt/Core/BinaryFunction.h
@@ -968,6 +968,15 @@
     return const_cast<BinaryFunction *>(this)->getInstructionAtOffset(Offset);
   }
 
+  /// Return offset for the first instruction. If there is data at the
+  /// beginning of a function then offset of the first instruction could
+  /// be different from 0
+  uint64_t getFirstInstructionOffset() const {
+    if (Instructions.empty())
+      return 0;
+    return Instructions.begin()->first;
+  }
+
   /// Return jump table that covers a given \p Address in memory.
   JumpTable *getJumpTableContainingAddress(uint64_t Address) {
     auto JTI = JumpTables.upper_bound(Address);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127111.434475.patch
Type: text/x-patch
Size: 3184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220606/2a445ec0/attachment.bin>


More information about the llvm-commits mailing list