[llvm] [BOLT] Add --pad-funcs-before=func:n (PR #117924)
Peter Waller via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 5 06:12:13 PST 2024
================
@@ -319,6 +349,36 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
Streamer.emitCodeAlignment(Function.getAlign(), &*BC.STI);
}
+ if (size_t Padding = opts::padFunctionBefore(Function)) {
+ // Handle padFuncsBefore after the above alignment logic but before
+ // symbol addresses are decided; with the intent that the nops are
+ // not executed and the original alignment logic is preserved.
+ if (!BC.HasRelocations) {
+ errs() << "BOLT-ERROR: -pad-before-funcs is not supported in "
+ << "non-relocation mode\n";
+ exit(1);
+ }
+
+ // Preserve Function.getMinAlign().
+ if (!isAligned(Function.getMinAlign(), Padding)) {
+ errs() << "BOLT-ERROR: User-requested " << Padding
+ << " padding bytes before function " << Function
+ << " is not a multiple of the minimum function alignment ("
+ << Function.getMinAlign().value() << ").\n";
+ exit(1);
+ }
+
+ LLVM_DEBUG(dbgs() << "BOLT-DEBUG: padding function " << Function << " with "
+ << Padding << " bytes\n");
+
+ // Since the padding is not executed, it can be null bytes.
+ Streamer.emitFill(Padding, 0);
+
+ Function.setMaxSize(Function.getMaxSize() + Padding);
+ Function.setSize(Function.getSize() + Padding);
+ Function.setImageSize(Function.getImageSize() + Padding);
----------------
peterwaller-arm wrote:
Dropped. This is also residue from an earlier attempt at implementation.
https://github.com/llvm/llvm-project/pull/117924
More information about the llvm-commits
mailing list