[llvm] [BOLT][Linux] Remove long-jump-labels option (PR #120929)

via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 22 18:44:17 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Franklin (FLZ101)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) bolt/lib/Rewrite/LinuxKernelRewriter.cpp (+7-9) 


``````````diff
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.

``````````

</details>


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


More information about the llvm-commits mailing list