[PATCH] D132089: [BOLT][NFC] Simplify handleRelocation
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 17 18:07:50 PDT 2022
Amir updated this revision to Diff 453495.
Amir added a comment.
Update
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132089/new/
https://reviews.llvm.org/D132089
Files:
bolt/lib/Rewrite/RewriteInstance.cpp
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -30,6 +30,7 @@
#include "bolt/Utils/CommandLineOpts.h"
#include "bolt/Utils/Utils.h"
#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
@@ -2424,8 +2425,8 @@
Address, /*CheckPastEnd*/ true, /*UseMaxSize*/ IsAArch64);
if (!IsSectionRelocation) {
- if (BinaryFunction *BF =
- BC->getBinaryFunctionContainingAddress(SymbolAddress)) {
+ BinaryFunction *BF = BC->getBinaryFunctionContainingAddress(SymbolAddress);
+ if (BF) {
if (BF != ReferencedBF) {
// It's possible we are referencing a function without referencing any
// code, e.g. when taking a bitmask action on a function address.
@@ -2452,20 +2453,16 @@
// if a non-pc-relative relocation in the code is pointing to (fptr - 1).
if (IsToCode && ContainingBF && !Relocation::isPCRelative(RType) &&
(!ReferencedBF || (ReferencedBF->getAddress() != Address))) {
- if (const BinaryFunction *RogueBF =
- BC->getBinaryFunctionAtAddress(Address + 1)) {
+ const BinaryFunction *RogueBF = BC->getBinaryFunctionAtAddress(Address + 1);
+ if (RogueBF) {
// Do an extra check that the function was referenced previously.
// It's a linear search, but it should rarely happen.
- bool Found = false;
- for (const auto &RelKV : ContainingBF->Relocations) {
- const Relocation &Rel = RelKV.second;
- if (Rel.Symbol == RogueBF->getSymbol() &&
- !Relocation::isPCRelative(Rel.Type)) {
- Found = true;
- break;
- }
- }
-
+ auto CheckReloc = [&](const Relocation &Rel) {
+ return Rel.Symbol == RogueBF->getSymbol() &&
+ !Relocation::isPCRelative(Rel.Type);
+ };
+ bool Found = llvm::any_of(
+ llvm::make_second_range(ContainingBF->Relocations), CheckReloc);
if (Found) {
errs() << "BOLT-WARNING: detected possible compiler de-virtualization "
"bug: -1 addend used with non-pc-relative relocation against "
@@ -2577,8 +2574,8 @@
if (SymbolFlags & SymbolRef::SF_Global) {
Name = SymbolName;
} else {
- if (StringRef(SymbolName)
- .startswith(BC->AsmInfo->getPrivateGlobalPrefix()))
+ StringRef PGPrefix(BC->AsmInfo->getPrivateGlobalPrefix());
+ if (StringRef(SymbolName).startswith(PGPrefix))
Name = NR.uniquify("PG" + SymbolName);
else
Name = NR.uniquify(SymbolName);
@@ -2601,9 +2598,9 @@
LLVM_DEBUG({
dbgs() << "BOLT-DEBUG: processing ending on data relocation "
<< NumDataRelocations << ": ";
+ printRelocationInfo(Rel, ReferencedSymbol->getName(), SymbolAddress,
+ Addend, ExtractedValue);
});
- printRelocationInfo(Rel, ReferencedSymbol->getName(), SymbolAddress,
- Addend, ExtractedValue);
}
return (!opts::MaxDataRelocations ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132089.453495.patch
Type: text/x-patch
Size: 3298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220818/efcb28b1/attachment.bin>
More information about the llvm-commits
mailing list