Skip to content

Commit 2a184fa

Browse files
committed
[BOLT][NFC] Don't remove nops in non-simple functions
Follow the logic of https://reviews.llvm.org/D143887 patch (fixed later by llvm#71377) we don't want to remove nops in non-simple function just in case there is undetected jump table to minimize chances to break offsets in it.
1 parent 72b73e2 commit 2a184fa

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "bolt/Core/ParallelUtilities.h"
1616
#include "bolt/Passes/ReorderAlgorithm.h"
1717
#include "bolt/Passes/ReorderFunctions.h"
18+
#include "bolt/Utils/CommandLineOpts.h"
1819
#include "llvm/Support/CommandLine.h"
1920
#include <atomic>
2021
#include <mutex>
@@ -1923,7 +1924,7 @@ Error RemoveNops::runOnFunctions(BinaryContext &BC) {
19231924
};
19241925

19251926
ParallelUtilities::PredicateTy SkipFunc = [&](const BinaryFunction &BF) {
1926-
return BF.shouldPreserveNops();
1927+
return BF.shouldPreserveNops() || (!opts::StrictMode && !BF.isSimple());
19271928
};
19281929

19291930
ParallelUtilities::runOnEachFunction(

bolt/test/RISCV/reloc-label-diff.s

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang %cflags -o %t %s
2-
// RUN: llvm-bolt -o %t.bolt %t
2+
// RUN: llvm-bolt --strict -o %t.bolt %t
33
// RUN: llvm-readelf -x .data %t.bolt | FileCheck %s
44

55
.text
@@ -9,15 +9,16 @@
99
_start:
1010
// Force BOLT into relocation mode
1111
.reloc 0, R_RISCV_NONE
12-
// BOLT removes this nop so the label difference is initially 8 but should be
13-
// 4 after BOLT processes it.
12+
// BOLT removes this nop so the label difference is initially 12 but should be
13+
// 8 after BOLT processes it.
1414
nop
1515
beq x0, x0, _test_end
16+
addi x1, x1, 1
1617
_test_end:
1718
ret
1819
.size _start, .-_start
1920

2021
.data
2122
// CHECK: Hex dump of section '.data':
22-
// CHECK: 0x{{.*}} 04000000
23+
// CHECK: 0x{{.*}} 08000000
2324
.word _test_end - _start

0 commit comments

Comments
 (0)