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.
Reviewed By: rafauler
Differential Revision: https://reviews.llvm.org/D153345
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())