Skip to content

Commit a89b838

Browse files
committed
[BOLT] Fix Linux kernel static keys handling
Fix the following issues: * `Cursor.tell() + (int32_t)DE.getU32(Cursor)` is undefined * In `bolt/test/X86/linux-static-keys.s` __start___jump_table is unaligned: ``` ffffffff800001fd g O .rodata 0000000000000000 __start___jump_table ``` This makes the test case undeterministic.
1 parent 342c8db commit a89b838

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

bolt/lib/Rewrite/LinuxKernelRewriter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,12 +1660,13 @@ Error LinuxKernelRewriter::readStaticKeysJumpTable() {
16601660
DataExtractor::Cursor Cursor(StaticKeysJumpTableAddress - SectionAddress);
16611661
uint32_t EntryID = 0;
16621662
while (Cursor && Cursor.tell() < Stop->getAddress() - SectionAddress) {
1663+
uint64_t _;
16631664
const uint64_t JumpAddress =
1664-
SectionAddress + Cursor.tell() + (int32_t)DE.getU32(Cursor);
1665+
(_ = SectionAddress + Cursor.tell(), _ + (int32_t)DE.getU32(Cursor));
16651666
const uint64_t TargetAddress =
1666-
SectionAddress + Cursor.tell() + (int32_t)DE.getU32(Cursor);
1667+
(_ = SectionAddress + Cursor.tell(), _ + (int32_t)DE.getU32(Cursor));
16671668
const uint64_t KeyAddress =
1668-
SectionAddress + Cursor.tell() + (int64_t)DE.getU64(Cursor);
1669+
(_ = SectionAddress + Cursor.tell(), _ + (int64_t)DE.getU64(Cursor));
16691670

16701671
// Consume the status of the cursor.
16711672
if (!Cursor)

bolt/test/X86/linux-static-keys.s

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ _start:
3535
.L0:
3636
jmp L1
3737
# CHECK: jit
38-
# CHECK-SAME: # ID: 1 {{.*}} # Likely: 0 # InitValue: 1
38+
# CHECK-SAME: # ID: 1 {{.*}} # Likely: 1 # InitValue: 0
3939
nop
4040
L1:
4141
.nops 5
4242
jmp .L0
4343
# CHECK: jit
44-
# CHECK-SAME: # ID: 2 {{.*}} # Likely: 1 # InitValue: 1
44+
# CHECK-SAME: # ID: 2 {{.*}} # Likely: 0 # InitValue: 0
4545

4646
## Check that a branch profile associated with a NOP is handled properly when
4747
## dynamic branch is created.
@@ -65,6 +65,7 @@ foo:
6565
.rodata
6666
.globl __start___jump_table
6767
.type __start___jump_table, %object
68+
.align 8
6869
__start___jump_table:
6970

7071
.long .L0 - . # Jump address

0 commit comments

Comments
 (0)