Skip to content

[BOLT][Linux] Remove long-jump-labels option #120929

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

Closed
wants to merge 1 commit into from

Conversation

FLZ101
Copy link
Contributor

@FLZ101 FLZ101 commented Dec 23, 2024

It is not easy for users to figure out long-jump-labels is required for Linux kernel < 5.14. Remove this user-unfriendly option and use LinuxKernelVersion instead.

References:

@llvmbot
Copy link
Member

llvmbot commented Dec 23, 2024

@llvm/pr-subscribers-bolt

Author: Franklin (FLZ101)

Changes

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

1 Files Affected:

  • (modified) bolt/lib/Rewrite/LinuxKernelRewriter.cpp (+7-9)
diff --git a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
index 03b414b71caca7..4443bc478cd44a 100644
--- a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
+++ b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
@@ -77,11 +77,6 @@ static cl::opt<bool>
                    cl::desc("dump Linux kernel static keys jump table"),
                    cl::init(false), cl::Hidden, cl::cat(BoltCategory));
 
-static cl::opt<bool> LongJumpLabels(
-    "long-jump-labels",
-    cl::desc("always use long jumps/nops for Linux kernel static keys"),
-    cl::init(false), cl::Hidden, cl::cat(BoltCategory));
-
 static cl::opt<bool>
     PrintORC("print-orc",
              cl::desc("print ORC unwind information for instructions"),
@@ -285,11 +280,14 @@ class LinuxKernelRewriter final : public MetadataRewriter {
   Error rewriteStaticKeysJumpTable();
   Error updateStaticKeysJumpTablePostEmit();
 
+  bool LongJumpLabels{false};
 public:
   LinuxKernelRewriter(BinaryContext &BC)
       : MetadataRewriter("linux-kernel-rewriter", BC) {}
 
   Error preCFGInitializer() override {
+    LongJumpLabels = LinuxKernelVersion <= LKVersion(5, 13, 19);
+
     processLKSections();
 
     if (Error E = processSMPLocks())
@@ -1735,13 +1733,13 @@ Error LinuxKernelRewriter::readStaticKeysJumpTable() {
     // the code, it will be converted to a different instruction in
     // rewriteStaticKeysJumpTable().
     //
-    // NB: for older kernels, under LongJumpLabels option, we create long
+    // NB: for older kernels (for which LongJumpLabels is true), we create long
     //     conditional branch to guarantee that code size estimation takes
     //     into account the extra bytes needed for long branch that will be used
     //     by the kernel patching code. Newer kernels can work with both short
     //     and long branches. The code for long conditional branch is larger
     //     than unconditional one, so we are pessimistic in our estimations.
-    if (opts::LongJumpLabels)
+    if (LongJumpLabels)
       BC.MIB->createLongCondBranch(StaticKeyBranch, Target, 0, BC.Ctx.get());
     else
       BC.MIB->createCondBranch(StaticKeyBranch, Target, 0, BC.Ctx.get());
@@ -1768,7 +1766,7 @@ Error LinuxKernelRewriter::readStaticKeysJumpTable() {
     if (!BC.MIB->getOffset(*Inst))
       BC.MIB->setOffset(*Inst, JumpAddress - BF->getAddress());
 
-    if (opts::LongJumpLabels)
+    if (LongJumpLabels)
       BC.MIB->setSize(*Inst, 5);
   }
 
@@ -1815,7 +1813,7 @@ Error LinuxKernelRewriter::rewriteStaticKeysJumpTable() {
         MCInst NewInst;
         // Replace the instruction with unconditional jump even if it needs to
         // be nop in the binary.
-        if (opts::LongJumpLabels) {
+        if (LongJumpLabels) {
           BC.MIB->createLongUncondBranch(NewInst, Target, BC.Ctx.get());
         } else {
           // Newer kernels can handle short and long jumps for static keys.

Copy link

github-actions bot commented Dec 23, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@FLZ101 FLZ101 closed this Dec 27, 2024
@FLZ101 FLZ101 force-pushed the fix-bolt-long-jump-labels branch from b39801f to 9d3f9f4 Compare December 27, 2024 02:20
It is not easy for users to figure out that long-jump-labels
is required for Linux kernel < 5.14. Remove this user-unfriendly
option and use LinuxKernelVersion instead.

References:

* https://elixir.bootlin.com/linux/v5.13.19/source/arch/x86/include/asm/jump_label.h
* https://elixir.bootlin.com/linux/v5.14-rc1/source/arch/x86/include/asm/jump_label.h
@FLZ101 FLZ101 reopened this Dec 27, 2024
@FLZ101 FLZ101 marked this pull request as ready for review December 27, 2024 02:32
@FLZ101 FLZ101 closed this Feb 26, 2025
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.

2 participants