[llvm] [RISCV][llvm-readobj, llvm-objdump] Use getRISCVVendorRelocationTypeNa… (PR #172811)
Jessica Clarke via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 18 05:14:30 PST 2025
================
@@ -0,0 +1,64 @@
+# RUN: llvm-mc -triple riscv32 %s -filetype=obj -o %t32.o
+# RUN: llvm-mc -triple riscv64 %s -filetype=obj -o %t64.o
+
+## Test llvm-objdump -r (relocation dump mode)
+# RUN: llvm-objdump -r %t32.o | FileCheck %s --check-prefix=RELOC
+# RUN: llvm-objdump -r %t64.o | FileCheck %s --check-prefix=RELOC
+
+## Test llvm-objdump -dr (disassembly with relocations)
+# RUN: llvm-objdump -dr %t32.o | FileCheck %s --check-prefix=DISASM
+# RUN: llvm-objdump -dr %t64.o | FileCheck %s --check-prefix=DISASM
+
+## Test that llvm-objdump correctly resolves RISCV vendor-specific relocation
+## names when preceded by R_RISCV_VENDOR, and falls back to R_RISCV_CUSTOM*
+## when there is no preceding vendor relocation or the vendor is unknown.
+
+.text
+ nop
+
+## Test 1: Known vendor (QUALCOMM) - should resolve to vendor-specific name
+ .reloc ., R_RISCV_VENDOR, QUALCOMM
+ .reloc ., R_RISCV_CUSTOM192, foo
+ nop
+
+## Test 2: Vendor symbol is consumed after one use per RISC-V psABI.
+## The second R_RISCV_CUSTOM192 without a preceding R_RISCV_VENDOR should
+## remain as R_RISCV_CUSTOM192.
+ .reloc ., R_RISCV_CUSTOM192, bar
+ nop
+
+## Test 3: Known vendor (ANDES) - should resolve to vendor-specific name
+ .reloc ., R_RISCV_VENDOR, ANDES
+ .reloc ., R_RISCV_CUSTOM241, baz
+ nop
+
+## Test 4: Unknown vendor - should fall back to R_RISCV_CUSTOM*
+ .reloc ., R_RISCV_VENDOR, UNKNOWN_VENDOR
+ .reloc ., R_RISCV_CUSTOM200, qux
+ nop
+
+## Test 5: Another known vendor after unknown - should work correctly
+ .reloc ., R_RISCV_VENDOR, QUALCOMM
+ .reloc ., R_RISCV_CUSTOM193, quux
+ nop
+
----------------
jrtc27 wrote:
```
## Test 6: An unpaired R_RISCV_VENDOR followed by an R_RISCV_CUSTOM* at a different offset
.reloc . - 1, R_RISCV_VENDOR, QUALCOMM
.reloc ., R_RISCV_CUSTOM193, barney
## Test 7: A non-R_RISCV_CUSTOM* in between a vendor relocation pair
.reloc ., R_RISCV_VENDOR, QUALCOMM
.reloc ., R_RISCV_32, snork
.reloc ., R_RISCV_CUSTOM193, zot
```
I believe those are currently handled incorrectly, both will be treated as valid vendor relocation pairs but neither are.
https://github.com/llvm/llvm-project/pull/172811
More information about the llvm-commits
mailing list