Skip to content

Commit

Permalink
[Object] Support LoongArch in RelocationResolver
Browse files Browse the repository at this point in the history
Similar to the RISCV logic added in D62062.

With this patch applied, llvm-dwarfdump works on existing LoongArch
object files, but generation of debuginfo on LoongArch is still pending
on proper support for relocations, so no test cases this time. They will
come later.

Differential Revision: https://reviews.llvm.org/D132019
  • Loading branch information
xen0n authored and SixWeining committed Aug 26, 2022
1 parent 784f21e commit 0ce24da
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions llvm/lib/Object/RelocationResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,58 @@ static uint64_t resolveCSKY(uint64_t Type, uint64_t Offset, uint64_t S,
}
}

static bool supportsLoongArch(uint64_t Type) {
switch (Type) {
case ELF::R_LARCH_NONE:
case ELF::R_LARCH_32:
case ELF::R_LARCH_32_PCREL:
case ELF::R_LARCH_64:
case ELF::R_LARCH_ADD8:
case ELF::R_LARCH_SUB8:
case ELF::R_LARCH_ADD16:
case ELF::R_LARCH_SUB16:
case ELF::R_LARCH_ADD32:
case ELF::R_LARCH_SUB32:
case ELF::R_LARCH_ADD64:
case ELF::R_LARCH_SUB64:
return true;
default:
return false;
}
}

static uint64_t resolveLoongArch(uint64_t Type, uint64_t Offset, uint64_t S,
uint64_t LocData, int64_t Addend) {
switch (Type) {
case ELF::R_LARCH_NONE:
return LocData;
case ELF::R_LARCH_32:
return (S + Addend) & 0xFFFFFFFF;
case ELF::R_LARCH_32_PCREL:
return (S + Addend - Offset) & 0xFFFFFFFF;
case ELF::R_LARCH_64:
return S + Addend;
case ELF::R_LARCH_ADD8:
return (LocData + (S + Addend)) & 0xFF;
case ELF::R_LARCH_SUB8:
return (LocData - (S + Addend)) & 0xFF;
case ELF::R_LARCH_ADD16:
return (LocData + (S + Addend)) & 0xFFFF;
case ELF::R_LARCH_SUB16:
return (LocData - (S + Addend)) & 0xFFFF;
case ELF::R_LARCH_ADD32:
return (LocData + (S + Addend)) & 0xFFFFFFFF;
case ELF::R_LARCH_SUB32:
return (LocData - (S + Addend)) & 0xFFFFFFFF;
case ELF::R_LARCH_ADD64:
return (LocData + (S + Addend));
case ELF::R_LARCH_SUB64:
return (LocData - (S + Addend));
default:
llvm_unreachable("Invalid relocation type");
}
}

static bool supportsCOFFX86(uint64_t Type) {
switch (Type) {
case COFF::IMAGE_REL_I386_SECREL:
Expand Down Expand Up @@ -711,6 +763,8 @@ getRelocationResolver(const ObjectFile &Obj) {
case Triple::bpfel:
case Triple::bpfeb:
return {supportsBPF, resolveBPF};
case Triple::loongarch64:
return {supportsLoongArch, resolveLoongArch};
case Triple::mips64el:
case Triple::mips64:
return {supportsMips64, resolveMips64};
Expand Down Expand Up @@ -747,6 +801,8 @@ getRelocationResolver(const ObjectFile &Obj) {
return {supportsAVR, resolveAVR};
case Triple::lanai:
return {supportsLanai, resolveLanai};
case Triple::loongarch32:
return {supportsLoongArch, resolveLoongArch};
case Triple::mipsel:
case Triple::mips:
return {supportsMips32, resolveMips32};
Expand Down

0 comments on commit 0ce24da

Please sign in to comment.