[llvm] 0ce24da - [Object] Support LoongArch in RelocationResolver
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 25 21:10:22 PDT 2022
Author: WANG Xuerui
Date: 2022-08-26T11:42:54+08:00
New Revision: 0ce24da0e13471f5ae19e590854696bb6a564e03
URL: https://github.com/llvm/llvm-project/commit/0ce24da0e13471f5ae19e590854696bb6a564e03
DIFF: https://github.com/llvm/llvm-project/commit/0ce24da0e13471f5ae19e590854696bb6a564e03.diff
LOG: [Object] Support LoongArch in RelocationResolver
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
Added:
Modified:
llvm/lib/Object/RelocationResolver.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Object/RelocationResolver.cpp b/llvm/lib/Object/RelocationResolver.cpp
index e14301663df3a..d1726053e7d57 100644
--- a/llvm/lib/Object/RelocationResolver.cpp
+++ b/llvm/lib/Object/RelocationResolver.cpp
@@ -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:
@@ -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};
@@ -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};
More information about the llvm-commits
mailing list