diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h --- a/bolt/include/bolt/Core/MCPlusBuilder.h +++ b/bolt/include/bolt/Core/MCPlusBuilder.h @@ -639,9 +639,12 @@ return false; } - /// If non-zero, this is used to fill the executable space with instructions - /// that will trap. Defaults to 0. - virtual unsigned getTrapFillValue() const { return 0; } + /// Used to fill the executable space with instructions + /// that will trap. + virtual StringRef getTrapFillValue() const { + llvm_unreachable("not implemented"); + return StringRef(); + } /// Interface and basic functionality of a MCInstMatcher. The idea is to make /// it easy to match one or more MCInsts against a tree-like pattern and diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp --- a/bolt/lib/Core/BinaryEmitter.cpp +++ b/bolt/lib/Core/BinaryEmitter.cpp @@ -380,7 +380,7 @@ } if (opts::MarkFuncs) - Streamer.emitIntValue(BC.MIB->getTrapFillValue(), 1); + Streamer.emitBytes(BC.MIB->getTrapFillValue()); // Emit CFI end if (Function.hasCFI()) @@ -424,7 +424,7 @@ // case, the call site entries in that LSDA have 0 as offset to the landing // pad, which the runtime interprets as "no handler". To prevent this, // insert some padding. - Streamer.emitIntValue(BC.MIB->getTrapFillValue(), 1); + Streamer.emitBytes(BC.MIB->getTrapFillValue()); } // Track the first emitted instruction with debug info. diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -5286,8 +5286,10 @@ if (!BF.getFileOffset() || !BF.isEmitted()) continue; OS.seek(BF.getFileOffset()); - for (unsigned I = 0; I < BF.getMaxSize(); ++I) - OS.write((unsigned char)BC->MIB->getTrapFillValue()); + StringRef TrapInstr = BC->MIB->getTrapFillValue(); + unsigned NInstr = BF.getMaxSize() / TrapInstr.size(); + for (unsigned I = 0; I < NInstr; ++I) + OS.write(TrapInstr.data(), TrapInstr.size()); } OS.seek(SavedPos); } diff --git a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp --- a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp +++ b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp @@ -1134,6 +1134,10 @@ } } + StringRef getTrapFillValue() const override { + return StringRef("\0\0\0\0", 4); + } + bool createReturn(MCInst &Inst) const override { Inst.setOpcode(AArch64::RET); Inst.clear(); diff --git a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp --- a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp +++ b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp @@ -171,6 +171,10 @@ return true; } + StringRef getTrapFillValue() const override { + return StringRef("\0\0\0\0", 4); + } + bool analyzeBranch(InstructionIterator Begin, InstructionIterator End, const MCSymbol *&TBB, const MCSymbol *&FBB, MCInst *&CondBranch, diff --git a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp --- a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp +++ b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp @@ -397,7 +397,7 @@ } } - unsigned getTrapFillValue() const override { return 0xCC; } + StringRef getTrapFillValue() const override { return StringRef("\314", 1); } struct IndJmpMatcherFrag1 : MCInstMatcher { std::unique_ptr Base;