[PATCH] D153345: [BOLT] Don't register internal func relocs as external references
Job Noorman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 20 06:56:38 PDT 2023
jobnoorman created this revision.
jobnoorman added reviewers: rafauler, maksfb, yota9, Amir.
Herald added subscribers: asb, treapster, pmatos, ayermolo, luismarques, s.egerton, PkmX, simoncook, arichardson.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added subscribers: llvm-commits, wangpc.
Herald added a project: LLVM.
Currently, all relocations that point inside a function are registered
as external references. If these relocations cannot be resolved as jump
tables or computed gotos, the containing function gets marked as
not-simple and excluded from optimizations.
RISC-V uses relocations for branches and jumps (to support linker
relaxation) and as such, almost no functions get marked as simple. This
patch fixes this by only registering relocations that originate outside
of the referenced function as external references.
Note that this patch causes many functions in existing RISC-V test cases
to be considered "simple" and undergo transformations. This triggered
some missing MCPlusBuilder interfaces. Therefore, this patch by itself
breaks many tests. The missing interfaces are implemented by the parents
of this patch.
Depends on D153342 <https://reviews.llvm.org/D153342>, D153343 <https://reviews.llvm.org/D153343> and D153344 <https://reviews.llvm.org/D153344>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153345
Files:
bolt/lib/Rewrite/RewriteInstance.cpp
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -2792,7 +2792,13 @@
ReferencedSymbol =
ReferencedBF->getOrCreateLocalLabel(Address,
/*CreatePastEnd =*/true);
- ReferencedBF->registerReferencedOffset(RefFunctionOffset);
+
+ // If ContainingBF != nullptr, it equals ReferencedBF (see
+ // if-condition above) so we're handling a relocation from a function
+ // to itself. RISC-V uses such relocations for branches, for example.
+ // These should not be registered as externally references offsets.
+ if (!ContainingBF)
+ ReferencedBF->registerReferencedOffset(RefFunctionOffset);
}
if (opts::Verbosity > 1 &&
BinarySection(*BC, RelocatedSection).isWritable())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153345.532909.patch
Type: text/x-patch
Size: 980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230620/c16e2f86/attachment.bin>
More information about the llvm-commits
mailing list