[llvm] f5b5398 - [JITLink][RISCV] Ignore R_RISCV_RELAX and check R_RISCV_ALIGN
Jonas Hahnfeld via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 6 09:09:40 PDT 2022
Author: Jonas Hahnfeld
Date: 2022-07-06T18:09:19+02:00
New Revision: f5b5398ebf7da1ab54f6793331bca8fbc3340f14
URL: https://github.com/llvm/llvm-project/commit/f5b5398ebf7da1ab54f6793331bca8fbc3340f14
DIFF: https://github.com/llvm/llvm-project/commit/f5b5398ebf7da1ab54f6793331bca8fbc3340f14.diff
LOG: [JITLink][RISCV] Ignore R_RISCV_RELAX and check R_RISCV_ALIGN
It is fine to not implement and ignore linker relaxation for now, but
we need to check the alignment. Luckily, an alignment of only 2 bytes
is the most common case when interpreting C++ code in clang-repl, and
already guaranteed by the length of compressed instructions.
Differential Revision: https://reviews.llvm.org/D129159
Added:
Modified:
llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
index 197ab71f52741..c7596efe2bb8c 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -494,6 +494,30 @@ class ELFLinkGraphBuilder_riscv : public ELFLinkGraphBuilder<ELFT> {
Block &BlockToFix) {
using Base = ELFLinkGraphBuilder<ELFT>;
+ uint32_t Type = Rel.getType(false);
+ // We do not implement linker relaxation, except what is required for
+ // alignment (see below).
+ if (Type == llvm::ELF::R_RISCV_RELAX)
+ return Error::success();
+
+ int64_t Addend = Rel.r_addend;
+ if (Type == llvm::ELF::R_RISCV_ALIGN) {
+ uint64_t Alignment = PowerOf2Ceil(Addend);
+ // FIXME: Implement support for ensuring alignment together with linker
+ // relaxation; 2 bytes are guaranteed by the length of compressed
+ // instructions, so this does not need any action from our side.
+ if (Alignment > 2)
+ return make_error<JITLinkError>(
+ formatv("Unsupported relocation R_RISCV_ALIGN with alignment {0} "
+ "larger than 2 (addend: {1})",
+ Alignment, Addend));
+ return Error::success();
+ }
+
+ Expected<riscv::EdgeKind_riscv> Kind = getRelocationKind(Type);
+ if (!Kind)
+ return Kind.takeError();
+
uint32_t SymbolIndex = Rel.getSymbol(false);
auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
if (!ObjSymbol)
@@ -508,12 +532,6 @@ class ELFLinkGraphBuilder_riscv : public ELFLinkGraphBuilder<ELFT> {
Base::GraphSymbols.size()),
inconvertibleErrorCode());
- uint32_t Type = Rel.getType(false);
- Expected<riscv::EdgeKind_riscv> Kind = getRelocationKind(Type);
- if (!Kind)
- return Kind.takeError();
-
- int64_t Addend = Rel.r_addend;
auto FixupAddress = orc::ExecutorAddr(FixupSect.sh_addr) + Rel.r_offset;
Edge::OffsetT Offset = FixupAddress - BlockToFix.getAddress();
Edge GE(*Kind, Offset, *GraphSymbol, Addend);
More information about the llvm-commits
mailing list