Skip to content

Commit 51268a5

Browse files
authored
[BOLT] Enable --keep-nops option for Linux kernel by default (#86349)
Preserve nop instructions in the Linux kernel since they could be used for runtime patching.
1 parent 56197d7 commit 51268a5

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

Diff for: bolt/lib/Rewrite/BinaryPassManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static cl::opt<bool> JTFootprintReductionFlag(
7272
"instructions at jump sites"),
7373
cl::cat(BoltOptCategory));
7474

75-
static cl::opt<bool>
75+
cl::opt<bool>
7676
KeepNops("keep-nops",
7777
cl::desc("keep no-op instructions. By default they are removed."),
7878
cl::Hidden, cl::cat(BoltOptCategory));

Diff for: bolt/lib/Rewrite/RewriteInstance.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ extern cl::list<std::string> HotTextMoveSections;
8181
extern cl::opt<bool> Hugify;
8282
extern cl::opt<bool> Instrument;
8383
extern cl::opt<JumpTableSupportLevel> JumpTables;
84+
extern cl::opt<bool> KeepNops;
8485
extern cl::list<std::string> ReorderData;
8586
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
8687
extern cl::opt<bool> TimeBuild;
@@ -2031,6 +2032,9 @@ void RewriteInstance::adjustCommandLineOptions() {
20312032

20322033
if (opts::Lite)
20332034
BC->outs() << "BOLT-INFO: enabling lite mode\n";
2035+
2036+
if (BC->IsLinuxKernel && !opts::KeepNops.getNumOccurrences())
2037+
opts::KeepNops = true;
20342038
}
20352039

20362040
namespace {

Diff for: bolt/test/X86/linux-alt-instruction.s

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,30 @@
66
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
77
# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \
88
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie
9-
# RUN: llvm-bolt %t.exe --print-normalized --keep-nops -o %t.out \
10-
# RUN: --alt-inst-feature-size=2 | FileCheck %s
9+
# RUN: llvm-bolt %t.exe --print-normalized --alt-inst-feature-size=2 -o %t.out \
10+
# RUN: | FileCheck %s
1111

1212
## Older kernels used to have padlen field in alt_instr. Check compatibility.
1313

1414
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown --defsym PADLEN=1 \
1515
# RUN: %s -o %t.o
1616
# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \
1717
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie
18-
# RUN: llvm-bolt %t.exe --print-normalized --keep-nops --alt-inst-has-padlen \
19-
# RUN: -o %t.out | FileCheck %s
18+
# RUN: llvm-bolt %t.exe --print-normalized --alt-inst-has-padlen -o %t.out \
19+
# RUN: | FileCheck %s
2020

2121
## Check with a larger size of "feature" field in alt_instr.
2222

2323
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \
2424
# RUN: --defsym FEATURE_SIZE_4=1 %s -o %t.o
2525
# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \
2626
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie
27-
# RUN: llvm-bolt %t.exe --print-normalized --keep-nops \
28-
# RUN: --alt-inst-feature-size=4 -o %t.out | FileCheck %s
27+
# RUN: llvm-bolt %t.exe --print-normalized --alt-inst-feature-size=4 -o %t.out \
28+
# RUN: | FileCheck %s
2929

3030
## Check that out-of-bounds read is handled properly.
3131

32-
# RUN: not llvm-bolt %t.exe --print-normalized --keep-nops \
33-
# RUN: --alt-inst-feature-size=2 -o %t.out
32+
# RUN: not llvm-bolt %t.exe --print-normalized --alt-inst-feature-size=2 -o %t.out
3433

3534
# CHECK: BOLT-INFO: Linux kernel binary detected
3635
# CHECK: BOLT-INFO: parsed 2 alternative instruction entries

Diff for: bolt/test/X86/linux-orc.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
## Verify ORC bindings to instructions.
2828

2929
# RUN: llvm-bolt %t.exe --print-normalized --dump-orc --print-orc -o %t.out \
30-
# RUN: --bolt-info=0 |& FileCheck %s
30+
# RUN: --keep-nops=0 --bolt-info=0 |& FileCheck %s
3131

3232

3333
## Verify ORC bindings after rewrite.
@@ -37,7 +37,7 @@
3737

3838
## Verify ORC binding after rewrite when some of the functions are skipped.
3939

40-
# RUN: llvm-bolt %t.exe -o %t.out --skip-funcs=bar --bolt-info=0
40+
# RUN: llvm-bolt %t.exe -o %t.out --skip-funcs=bar --bolt-info=0 --keep-nops=0
4141
# RUN: llvm-bolt %t.out -o %t.out.1 --print-normalized --print-orc \
4242
# RUN: |& FileCheck %s
4343

Diff for: bolt/test/X86/linux-parainstructions.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## Verify paravirtual bindings to instructions.
1010

11-
# RUN: llvm-bolt %t.exe --print-normalized -o %t.out | FileCheck %s
11+
# RUN: llvm-bolt %t.exe --print-normalized -o %t.out --keep-nops=0 | FileCheck %s
1212

1313
# CHECK: BOLT-INFO: Linux kernel binary detected
1414
# CHECK: BOLT-INFO: parsed 2 paravirtual patch sites

0 commit comments

Comments
 (0)