[llvm] [BOLT] Fix Linux kernel static keys handling (PR #119557)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 11 05:48:10 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Franklin (FLZ101)

<details>
<summary>Changes</summary>

Fix the following issues:

* `Cursor.tell() + (int32_t)DE.getU32(Cursor)` is undefined

* `bolt/test/X86/linux-static-keys.s` generates a binary whose .rodata is unaligned:

  ```
  3 .rodata       00000020  ffffffff800001fd  ffffffff800001fd  000001fd  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  ```

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


2 Files Affected:

- (modified) bolt/lib/Rewrite/LinuxKernelRewriter.cpp (+4-3) 
- (modified) bolt/test/X86/linux-static-keys.s (+3-2) 


``````````diff
diff --git a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
index 03b414b71caca7..7409c33ec84e18 100644
--- a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
+++ b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
@@ -1660,12 +1660,13 @@ Error LinuxKernelRewriter::readStaticKeysJumpTable() {
   DataExtractor::Cursor Cursor(StaticKeysJumpTableAddress - SectionAddress);
   uint32_t EntryID = 0;
   while (Cursor && Cursor.tell() < Stop->getAddress() - SectionAddress) {
+    uint64_t _;
     const uint64_t JumpAddress =
-        SectionAddress + Cursor.tell() + (int32_t)DE.getU32(Cursor);
+        (_ = SectionAddress + Cursor.tell(), _ + (int32_t)DE.getU32(Cursor));
     const uint64_t TargetAddress =
-        SectionAddress + Cursor.tell() + (int32_t)DE.getU32(Cursor);
+        (_ = SectionAddress + Cursor.tell(), _ + (int32_t)DE.getU32(Cursor));
     const uint64_t KeyAddress =
-        SectionAddress + Cursor.tell() + (int64_t)DE.getU64(Cursor);
+        (_ = SectionAddress + Cursor.tell(), _ + (int64_t)DE.getU64(Cursor));
 
     // Consume the status of the cursor.
     if (!Cursor)
diff --git a/bolt/test/X86/linux-static-keys.s b/bolt/test/X86/linux-static-keys.s
index 0bd17a375d8824..465e865458d902 100644
--- a/bolt/test/X86/linux-static-keys.s
+++ b/bolt/test/X86/linux-static-keys.s
@@ -35,13 +35,13 @@ _start:
 .L0:
   jmp L1
 # CHECK:      jit
-# CHECK-SAME: # ID: 1 {{.*}} # Likely: 0 # InitValue: 1
+# CHECK-SAME: # ID: 1 {{.*}} # Likely: 1 # InitValue: 0
   nop
 L1:
   .nops 5
   jmp .L0
 # CHECK:      jit
-# CHECK-SAME: # ID: 2 {{.*}} # Likely: 1 # InitValue: 1
+# CHECK-SAME: # ID: 2 {{.*}} # Likely: 0 # InitValue: 0
 
 ## Check that a branch profile associated with a NOP is handled properly when
 ## dynamic branch is created.
@@ -65,6 +65,7 @@ foo:
   .rodata
   .globl __start___jump_table
   .type __start___jump_table, %object
+  .align 8
 __start___jump_table:
 
   .long .L0 - . # Jump address

``````````

</details>


https://github.com/llvm/llvm-project/pull/119557


More information about the llvm-commits mailing list