[llvm] [BOLT] Refactor AArch64 Relocation Print (PR #101895)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 4 08:51:57 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: sinan (linsinan1995)
<details>
<summary>Changes</summary>
AArch64 relocations are not sequentially numbered (more details on llvm/include/llvm/BinaryFormat/ELFRelocs/AArch64.def), so directly mapping the relocation type to its name can trigger a debug assertion `assert(Type < ArrayRef(AArch64RelocNames).size())`.
Refactor the AArch64 relocation print based on how RISC-V arch does.
---
Full diff: https://github.com/llvm/llvm-project/pull/101895.diff
1 Files Affected:
- (modified) bolt/lib/Core/Relocation.cpp (+10-5)
``````````diff
diff --git a/bolt/lib/Core/Relocation.cpp b/bolt/lib/Core/Relocation.cpp
index 4e888a5b147ac..48362191fafe2 100644
--- a/bolt/lib/Core/Relocation.cpp
+++ b/bolt/lib/Core/Relocation.cpp
@@ -1071,13 +1071,18 @@ void Relocation::print(raw_ostream &OS) const {
break;
case Triple::aarch64:
- static const char *const AArch64RelocNames[] = {
-#define ELF_RELOC(name, value) #name,
+ // AArch64 relocations are not sequentially numbered so we cannot use an
+ // array
+ switch (Type) {
+ default:
+ llvm_unreachable("illegal AArch64 relocation");
+#define ELF_RELOC(name, value) \
+ case value: \
+ OS << #name; \
+ break;
#include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
#undef ELF_RELOC
- };
- assert(Type < ArrayRef(AArch64RelocNames).size());
- OS << AArch64RelocNames[Type];
+ }
break;
case Triple::riscv64:
``````````
</details>
https://github.com/llvm/llvm-project/pull/101895
More information about the llvm-commits
mailing list