Skip to content

Commit 65847de

Browse files
committed
[JITLink][LoongArch] Ignore R_LARCH_RELAX and check R_LARCH_ALIGN
Linker relaxation is not implemented for jitlink now (maybe implement in the future). But if relaxation is enabled by clang, R_LARCH_RELAX and R_LARCH_ALIGN relocations will be emitted. So we just ignore linker relaxation and check the alignment now. If not, interpreting C++ code using clang-repl when relaxation is enabled will occur error: `JIT session error: Unsupported loongarch relocation:102: R_LARCH_ALIGN`. Similar to: f5b5398.
1 parent c660b28 commit 65847de

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@ class ELFLinkGraphBuilder_loongarch : public ELFLinkGraphBuilder<ELFT> {
9595
Block &BlockToFix) {
9696
using Base = ELFLinkGraphBuilder<ELFT>;
9797

98+
uint32_t Type = Rel.getType(false);
99+
// We do not implement linker relaxation for jitlink now, except what is
100+
// required for alignment (see below).
101+
if (Type == ELF::R_LARCH_RELAX)
102+
return Error::success();
103+
104+
int64_t Addend = Rel.r_addend;
105+
if (Type == ELF::R_LARCH_ALIGN) {
106+
uint64_t Alignment = PowerOf2Ceil(Addend);
107+
// FIXME: Implement support for ensuring alignment together with linker
108+
// relaxation. Addend is always 28 in the most common case when
109+
// interpreting C++ code in clang-repl.
110+
if (Alignment > 32)
111+
return make_error<JITLinkError>(
112+
formatv("Unsupported relocation R_LARCH_ALIGN with alignment {0} "
113+
"larger than 32 (addend: {1})",
114+
Alignment, Addend));
115+
return Error::success();
116+
}
117+
118+
Expected<loongarch::EdgeKind_loongarch> Kind = getRelocationKind(Type);
119+
if (!Kind)
120+
return Kind.takeError();
121+
98122
uint32_t SymbolIndex = Rel.getSymbol(false);
99123
auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
100124
if (!ObjSymbol)
@@ -109,12 +133,6 @@ class ELFLinkGraphBuilder_loongarch : public ELFLinkGraphBuilder<ELFT> {
109133
Base::GraphSymbols.size()),
110134
inconvertibleErrorCode());
111135

112-
uint32_t Type = Rel.getType(false);
113-
Expected<loongarch::EdgeKind_loongarch> Kind = getRelocationKind(Type);
114-
if (!Kind)
115-
return Kind.takeError();
116-
117-
int64_t Addend = Rel.r_addend;
118136
auto FixupAddress = orc::ExecutorAddr(FixupSect.sh_addr) + Rel.r_offset;
119137
Edge::OffsetT Offset = FixupAddress - BlockToFix.getAddress();
120138
Edge GE(*Kind, Offset, *GraphSymbol, Addend);

0 commit comments

Comments
 (0)