Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions bolt/lib/Rewrite/LinuxKernelRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,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"),
Expand Down Expand Up @@ -237,6 +232,9 @@ class LinuxKernelRewriter final : public MetadataRewriter {
/// Static key entries that need nop conversion.
DenseSet<uint32_t> NopIDs;

/// Use long jumps/nops for Linux kernel static keys.
bool LongJumpLabels{false};

/// Section containing static call table.
ErrorOr<BinarySection &> StaticCallSection = std::errc::bad_address;
uint64_t StaticCallTableAddress = 0;
Expand Down Expand Up @@ -351,6 +349,8 @@ class LinuxKernelRewriter final : public MetadataRewriter {
if (Error E = detectLinuxKernelVersion())
return E;

LongJumpLabels = LinuxKernelVersion < LKVersion(5, 14, 0);

processLKSections();

if (Error E = processSMPLocks())
Expand Down Expand Up @@ -1799,13 +1799,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());
Expand All @@ -1832,7 +1832,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);
}

Expand Down Expand Up @@ -1879,7 +1879,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.
Expand Down
Loading