Skip to content

Commit be21bd9

Browse files
committed
Revert "[BOLT] Add --pad-funcs-before=func:n (#117924)"
14dcf82 introduced a subtle bug with the static `FunctionPadding` map. If either `opts::FunctionPadSpec` or `opts::FunctionPadBeforeSpec` are set, the map is going to be populated with the respective spec in the first invocation of `BinaryEmitter::emitFunction`. The subsequent invocations will pick up the padding from the map irrespective of whether `opts::FunctionPadSpec` or `opts::FunctionPadBeforeSpec` is passed as a parameter. This breaks an internal test, hence reverting the patch.
1 parent fbcf3cb commit be21bd9

File tree

3 files changed

+14
-80
lines changed

3 files changed

+14
-80
lines changed

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,13 @@ BreakFunctionNames("break-funcs",
4646
cl::Hidden,
4747
cl::cat(BoltCategory));
4848

49-
cl::list<std::string>
50-
FunctionPadSpec("pad-funcs", cl::CommaSeparated,
51-
cl::desc("list of functions to pad with amount of bytes"),
52-
cl::value_desc("func1:pad1,func2:pad2,func3:pad3,..."),
53-
cl::Hidden, cl::cat(BoltCategory));
54-
55-
cl::list<std::string> FunctionPadBeforeSpec(
56-
"pad-funcs-before", cl::CommaSeparated,
57-
cl::desc("list of functions to pad with amount of bytes"),
58-
cl::value_desc("func1:pad1,func2:pad2,func3:pad3,..."), cl::Hidden,
59-
cl::cat(BoltCategory));
49+
static cl::list<std::string>
50+
FunctionPadSpec("pad-funcs",
51+
cl::CommaSeparated,
52+
cl::desc("list of functions to pad with amount of bytes"),
53+
cl::value_desc("func1:pad1,func2:pad2,func3:pad3,..."),
54+
cl::Hidden,
55+
cl::cat(BoltCategory));
6056

6157
static cl::opt<bool> MarkFuncs(
6258
"mark-funcs",
@@ -74,12 +70,11 @@ X86AlignBranchBoundaryHotOnly("x86-align-branch-boundary-hot-only",
7470
cl::init(true),
7571
cl::cat(BoltOptCategory));
7672

77-
size_t padFunction(const cl::list<std::string> &Spec,
78-
const BinaryFunction &Function) {
73+
size_t padFunction(const BinaryFunction &Function) {
7974
static std::map<std::string, size_t> FunctionPadding;
8075

81-
if (FunctionPadding.empty() && !Spec.empty()) {
82-
for (const std::string &Spec : Spec) {
76+
if (FunctionPadding.empty() && !FunctionPadSpec.empty()) {
77+
for (std::string &Spec : FunctionPadSpec) {
8378
size_t N = Spec.find(':');
8479
if (N == std::string::npos)
8580
continue;
@@ -324,32 +319,6 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
324319
Streamer.emitCodeAlignment(Function.getAlign(), &*BC.STI);
325320
}
326321

327-
if (size_t Padding =
328-
opts::padFunction(opts::FunctionPadBeforeSpec, Function)) {
329-
// Handle padFuncsBefore after the above alignment logic but before
330-
// symbol addresses are decided.
331-
if (!BC.HasRelocations) {
332-
BC.errs() << "BOLT-ERROR: -pad-before-funcs is not supported in "
333-
<< "non-relocation mode\n";
334-
exit(1);
335-
}
336-
337-
// Preserve Function.getMinAlign().
338-
if (!isAligned(Function.getMinAlign(), Padding)) {
339-
BC.errs() << "BOLT-ERROR: user-requested " << Padding
340-
<< " padding bytes before function " << Function
341-
<< " is not a multiple of the minimum function alignment ("
342-
<< Function.getMinAlign().value() << ").\n";
343-
exit(1);
344-
}
345-
346-
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: padding before function " << Function
347-
<< " with " << Padding << " bytes\n");
348-
349-
// Since the padding is not executed, it can be null bytes.
350-
Streamer.emitFill(Padding, 0);
351-
}
352-
353322
MCContext &Context = Streamer.getContext();
354323
const MCAsmInfo *MAI = Context.getAsmInfo();
355324

@@ -404,7 +373,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
404373
emitFunctionBody(Function, FF, /*EmitCodeOnly=*/false);
405374

406375
// Emit padding if requested.
407-
if (size_t Padding = opts::padFunction(opts::FunctionPadSpec, Function)) {
376+
if (size_t Padding = opts::padFunction(Function)) {
408377
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: padding function " << Function << " with "
409378
<< Padding << " bytes\n");
410379
Streamer.emitFill(Padding, MAI->getTextAlignFillValue());

bolt/lib/Passes/ReorderFunctions.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ extern cl::OptionCategory BoltOptCategory;
2828
extern cl::opt<unsigned> Verbosity;
2929
extern cl::opt<uint32_t> RandomSeed;
3030

31-
extern size_t padFunction(const cl::list<std::string> &Spec,
32-
const bolt::BinaryFunction &Function);
33-
extern cl::list<std::string> FunctionPadSpec, FunctionPadBeforeSpec;
31+
extern size_t padFunction(const bolt::BinaryFunction &Function);
3432

3533
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
3634
cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions(
@@ -306,12 +304,8 @@ Error ReorderFunctions::runOnFunctions(BinaryContext &BC) {
306304
return false;
307305
if (B->isIgnored())
308306
return true;
309-
const size_t PadA =
310-
opts::padFunction(opts::FunctionPadSpec, *A) +
311-
opts::padFunction(opts::FunctionPadBeforeSpec, *A);
312-
const size_t PadB =
313-
opts::padFunction(opts::FunctionPadSpec, *B) +
314-
opts::padFunction(opts::FunctionPadBeforeSpec, *B);
307+
const size_t PadA = opts::padFunction(*A);
308+
const size_t PadB = opts::padFunction(*B);
315309
if (!PadA || !PadB) {
316310
if (PadA)
317311
return true;

bolt/test/AArch64/pad-before-funcs.s

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)