[llvm] [RelocationResolver][Xtensa] Implement R_XTENSA_32 (PR #96311)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 21 07:24:06 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
Author: YAMAMOTO Takashi (yamt)
<details>
<summary>Changes</summary>
This makes llvm-dwarfdump work on Xtensa ELF objects.
Reference: https://github.com/jcmvbkbc/xtensa-abi/blob/master/relocations
---
Full diff: https://github.com/llvm/llvm-project/pull/96311.diff
1 Files Affected:
- (modified) llvm/lib/Object/RelocationResolver.cpp (+27-2)
``````````diff
diff --git a/llvm/lib/Object/RelocationResolver.cpp b/llvm/lib/Object/RelocationResolver.cpp
index 564d9da78e97d..b404a79966b9d 100644
--- a/llvm/lib/Object/RelocationResolver.cpp
+++ b/llvm/lib/Object/RelocationResolver.cpp
@@ -310,6 +310,28 @@ static uint64_t resolveX86(uint64_t Type, uint64_t Offset, uint64_t S,
}
}
+static bool supportsXtensa(uint64_t Type) {
+ switch (Type) {
+ case ELF::R_XTENSA_NONE:
+ case ELF::R_XTENSA_32:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static uint64_t resolveXtensa(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t Addend) {
+ switch (Type) {
+ case ELF::R_XTENSA_NONE:
+ return LocData;
+ case ELF::R_XTENSA_32:
+ return (S + Addend + LocData) & 0xFFFFFFFF;
+ default:
+ llvm_unreachable("Invalid relocation type");
+ }
+}
+
static bool supportsPPC32(uint64_t Type) {
switch (Type) {
case ELF::R_PPC_ADDR32:
@@ -820,6 +842,8 @@ getRelocationResolver(const ObjectFile &Obj) {
switch (Obj.getArch()) {
case Triple::x86:
return {supportsX86, resolveX86};
+ case Triple::xtensa:
+ return {supportsXtensa, resolveXtensa};
case Triple::ppcle:
case Triple::ppc:
return {supportsPPC32, resolvePPC32};
@@ -885,11 +909,12 @@ uint64_t resolveRelocation(RelocationResolver Resolver, const RelocationRef &R,
if (GetRelSectionType() == ELF::SHT_RELA) {
Addend = getELFAddend(R);
- // LoongArch and RISCV relocations use both LocData and Addend.
+ // LoongArch, RISCV, and Xtensa relocations use both LocData and Addend.
if (Obj->getArch() != Triple::loongarch32 &&
Obj->getArch() != Triple::loongarch64 &&
Obj->getArch() != Triple::riscv32 &&
- Obj->getArch() != Triple::riscv64)
+ Obj->getArch() != Triple::riscv64 &&
+ Obj->getArch() != Triple::xtensa)
LocData = 0;
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/96311
More information about the llvm-commits
mailing list