[llvm] Keep function which is directly called or has prologue (PR #88244)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 10 01:01:21 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff da5a86b53e7d6e7ff7407b16c2c869894493ee99 a846f4f3f4089c516a41db3b64d4cf750bd505ff -- bolt/include/bolt/Core/BinaryFunction.h bolt/include/bolt/Rewrite/RewriteInstance.h bolt/lib/Core/BinaryFunction.cpp bolt/lib/Rewrite/RewriteInstance.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index cd6ded17e4..bd1460580e 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -208,7 +208,7 @@ public:
/// Mark injected functions
bool IsInjected = false;
- bool IsDirectCalled =false;
+ bool IsDirectCalled = false;
using LSDATypeTableTy = SmallVector<uint64_t, 0>;
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 2f7e6a8d36..0e7a19da93 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1268,11 +1268,14 @@ Error BinaryFunction::disassemble() {
bool IsCall = MIB->isCall(Instruction);
const bool IsCondBranch = MIB->isConditionalBranch(Instruction);
MCSymbol *TargetSymbol = nullptr;
- if(IsCall) {
- if (BinaryFunction *TargetFunc = BC.getBinaryFunctionContainingAddress(TargetAddress)) {
+ if (IsCall) {
+ if (BinaryFunction *TargetFunc =
+ BC.getBinaryFunctionContainingAddress(TargetAddress)) {
// direct call here.
TargetFunc->IsDirectCalled = true;
- LLVM_DEBUG(dbgs() << "[Disasm] Find function which is directly called: 0x" << Twine::utohexstr(TargetFunc->getAddress()) << "\n");
+ LLVM_DEBUG(dbgs()
+ << "[Disasm] Find function which is directly called: 0x"
+ << Twine::utohexstr(TargetFunc->getAddress()) << "\n");
}
}
if (BC.MIB->isUnsupportedBranch(Instruction)) {
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index a0768ba870..7168804f8b 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -811,52 +811,65 @@ Error RewriteInstance::run() {
}
void RewriteInstance::keepDCPFunction() {
- BC->outs() << "keepDCPFunction!"<<"\n";
- for(auto &BFI : BC->getBinaryFunctions()) {
+ BC->outs() << "keepDCPFunction!" << "\n";
+ for (auto &BFI : BC->getBinaryFunctions()) {
BinaryFunction &BF = BFI.second;
- bool hasPrologue =false;
+ bool hasPrologue = false;
ErrorOr<ArrayRef<uint8_t>> ErrorOrFunctionData = BF.getData();
assert(ErrorOrFunctionData && "function data is not available");
ArrayRef<uint8_t> IData = *ErrorOrFunctionData;
- // BC->outs() << "Potential Function Entry Point: 0x" << Twine::utohexstr(IData[0]) << "\n";
- // Check for common function prologue patterns
- // push %rbp
- // mov %rsp %rbp
- if (BF.getSize()>=4 && (char)IData[0] == '\x55' && (char)IData[1] == '\x48' && (char)IData[2] == '\x89' && (char)IData[3] == '\xe5') {
- LLVM_DEBUG(dbgs() << "[keepDCPFunction] Find function with prologue in: 0x" << Twine::utohexstr(BF.getAddress()) << "\n");
- hasPrologue =true;
- } else if (BF.getSize()>=4 && (char)IData[0] == '\xf3' && (char)IData[1] == '\x0f' && (char)IData[2] == '\x1e' && (char)IData[3] == '\xfa') {
- LLVM_DEBUG(dbgs() << "[keepDCPFunction] Find function with prologue in: 0x" << Twine::utohexstr(BF.getAddress()) << "\n");
- hasPrologue= true;
+ // BC->outs() << "Potential Function Entry Point: 0x" <<
+ // Twine::utohexstr(IData[0]) << "\n"; Check for common function prologue
+ // patterns push %rbp mov %rsp %rbp
+ if (BF.getSize() >= 4 && (char)IData[0] == '\x55' &&
+ (char)IData[1] == '\x48' && (char)IData[2] == '\x89' &&
+ (char)IData[3] == '\xe5') {
+ LLVM_DEBUG(
+ dbgs() << "[keepDCPFunction] Find function with prologue in: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
+ hasPrologue = true;
+ } else if (BF.getSize() >= 4 && (char)IData[0] == '\xf3' &&
+ (char)IData[1] == '\x0f' && (char)IData[2] == '\x1e' &&
+ (char)IData[3] == '\xfa') {
+ LLVM_DEBUG(
+ dbgs() << "[keepDCPFunction] Find function with prologue in: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
+ hasPrologue = true;
} else {
hasPrologue = false;
}
- LLVM_DEBUG(
- if(BF.IsDirectCalled) dbgs() << "[keepDCPFunction] Find function which is directly called: 0x" << Twine::utohexstr(BF.getAddress()) << "\n"
- );
- if(!BF.IsDirectCalled && !hasPrologue )
+ LLVM_DEBUG(if (BF.IsDirectCalled) dbgs()
+ << "[keepDCPFunction] Find function which is directly called: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
+ if (!BF.IsDirectCalled && !hasPrologue)
BF.setIgnored();
}
}
void RewriteInstance::keepPrologueFunction() {
- BC->outs() << "keepPrologueFunction!"<<"\n";
- for(auto &BFI : BC->getBinaryFunctions()) {
+ BC->outs() << "keepPrologueFunction!" << "\n";
+ for (auto &BFI : BC->getBinaryFunctions()) {
BinaryFunction &BF = BFI.second;
ErrorOr<ArrayRef<uint8_t>> ErrorOrFunctionData = BF.getData();
assert(ErrorOrFunctionData && "function data is not available");
ArrayRef<uint8_t> IData = *ErrorOrFunctionData;
- // BC->outs() << "Potential Function Entry Point: 0x" << Twine::utohexstr(IData[0]) << "\n";
- // Check for common function prologue patterns
- // push %rbp
- // mov %rsp %rbp
- if (BF.getSize()>=4 && (char)IData[0] == '\x55' && (char)IData[1] == '\x48' && (char)IData[2] == '\x89' && (char)IData[3] == '\xe5') {
- LLVM_DEBUG(dbgs() << "[keepPrologueFunction] Find function with prologue in: 0x" << Twine::utohexstr(BF.getAddress()) << "\n");
- } else if (BF.getSize()>=4 && (char)IData[0] == '\xf3' && (char)IData[1] == '\x0f' && (char)IData[2] == '\x1e' && (char)IData[3] == '\xfa') {
- LLVM_DEBUG(dbgs() << "[keepPrologueFunction] Find function with prologue in: 0x" << Twine::utohexstr(BF.getAddress()) << "\n");
+ // BC->outs() << "Potential Function Entry Point: 0x" <<
+ // Twine::utohexstr(IData[0]) << "\n"; Check for common function prologue
+ // patterns push %rbp mov %rsp %rbp
+ if (BF.getSize() >= 4 && (char)IData[0] == '\x55' &&
+ (char)IData[1] == '\x48' && (char)IData[2] == '\x89' &&
+ (char)IData[3] == '\xe5') {
+ LLVM_DEBUG(
+ dbgs() << "[keepPrologueFunction] Find function with prologue in: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
+ } else if (BF.getSize() >= 4 && (char)IData[0] == '\xf3' &&
+ (char)IData[1] == '\x0f' && (char)IData[2] == '\x1e' &&
+ (char)IData[3] == '\xfa') {
+ LLVM_DEBUG(
+ dbgs() << "[keepPrologueFunction] Find function with prologue in: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
} else {
BF.setIgnored();
}
-
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/88244
More information about the llvm-commits
mailing list