Skip to content

Commit 178ca01

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 e534178 commit 178ca01

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
@@ -99,6 +99,30 @@ class ELFLinkGraphBuilder_loongarch : public ELFLinkGraphBuilder<ELFT> {
9999
Block &BlockToFix) {
100100
using Base = ELFLinkGraphBuilder<ELFT>;
101101

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

116-
uint32_t Type = Rel.getType(false);
117-
Expected<loongarch::EdgeKind_loongarch> Kind = getRelocationKind(Type);
118-
if (!Kind)
119-
return Kind.takeError();
120-
121-
int64_t Addend = Rel.r_addend;
122140
auto FixupAddress = orc::ExecutorAddr(FixupSect.sh_addr) + Rel.r_offset;
123141
Edge::OffsetT Offset = FixupAddress - BlockToFix.getAddress();
124142
Edge GE(*Kind, Offset, *GraphSymbol, Addend);

0 commit comments

Comments
 (0)