Skip to content

[BOLT][Linux] Fix static keys test case #119771

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
Dec 16, 2024
Merged

Conversation

maksfb
Copy link
Contributor

@maksfb maksfb commented Dec 12, 2024

The key address in the static keys jump table was incorrectly encoded as an absolute value instead of PC-relative causing incorrect interpretation of the "likely" property of the key.

The key address in the static keys jump table was incorrectly encoded as
an absolute value instead of PC-relative causing incorrect
interpretation of the "likely" property of the key.
@llvmbot
Copy link
Member

llvmbot commented Dec 12, 2024

@llvm/pr-subscribers-bolt

Author: Maksim Panchenko (maksfb)

Changes

The key address in the static keys jump table was incorrectly encoded as an absolute value instead of PC-relative causing incorrect interpretation of the "likely" property of the key.


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

1 Files Affected:

  • (modified) bolt/test/X86/linux-static-keys.s (+15-9)
diff --git a/bolt/test/X86/linux-static-keys.s b/bolt/test/X86/linux-static-keys.s
index 0bd17a375d8824..d34dd640ef8790 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
+  jmp .L0
 
 ## Check that a branch profile associated with a NOP is handled properly when
 ## dynamic branch is created.
@@ -67,18 +67,24 @@ foo:
   .type __start___jump_table, %object
 __start___jump_table:
 
-  .long .L0 - . # Jump address
-  .long L1 - . # Target address
-  .quad 1       # Key address
+  .long .L0 - .                   # Jump address
+  .long L1 - .                    # Target address
+  .quad fake_static_key + 1 - .   # Key address; LSB = 1 : likely
 
-  .long L1 - . # Jump address
-  .long L2 - . # Target address
-  .quad 0       # Key address
+  .long L1 - .                    # Jump address
+  .long L2 - .                    # Target address
+  .quad fake_static_key -.        # Key address; LSB = 0 : unlikely
 
   .globl __stop___jump_table
   .type __stop___jump_table, %object
 __stop___jump_table:
 
+## Staic keys (we just use the label ignoring the format of the keys).
+  .data
+  .align 8
+fake_static_key:
+  .quad 0
+
 ## Fake Linux Kernel sections.
   .section __ksymtab,"a",@progbits
   .section __ksymtab_gpl,"a",@progbits

@maksfb maksfb merged commit f86f457 into llvm:main Dec 16, 2024
9 checks passed
@maksfb maksfb deleted the gh-fix-linux-sk-test 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