Skip to content

[JITLink][LoongArch] Ignore R_LARCH_RELAX and check R_LARCH_ALIGN #121097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ class ELFLinkGraphBuilder_loongarch : public ELFLinkGraphBuilder<ELFT> {
Block &BlockToFix) {
using Base = ELFLinkGraphBuilder<ELFT>;

uint32_t Type = Rel.getType(false);
// We do not implement linker relaxation for jitlink now, except what is
// required for alignment (see below).
if (Type == ELF::R_LARCH_RELAX)
return Error::success();

int64_t Addend = Rel.r_addend;
if (Type == ELF::R_LARCH_ALIGN) {
uint64_t Alignment = PowerOf2Ceil(Addend);
// FIXME: Implement support for ensuring alignment together with linker
// relaxation. Addend is always 28 in the most common case when
// interpreting C++ code in clang-repl.
if (Alignment > 32)
return make_error<JITLinkError>(
formatv("Unsupported relocation R_LARCH_ALIGN with alignment {0} "
"larger than 32 (addend: {1})",
Alignment, Addend));
return Error::success();
}

Expected<loongarch::EdgeKind_loongarch> Kind = getRelocationKind(Type);
if (!Kind)
return Kind.takeError();

uint32_t SymbolIndex = Rel.getSymbol(false);
auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
if (!ObjSymbol)
Expand All @@ -109,12 +133,6 @@ class ELFLinkGraphBuilder_loongarch : public ELFLinkGraphBuilder<ELFT> {
Base::GraphSymbols.size()),
inconvertibleErrorCode());

uint32_t Type = Rel.getType(false);
Expected<loongarch::EdgeKind_loongarch> 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);
Expand Down
Loading