Skip to content

Commit fea7b65

Browse files
authored
[RISCV] Add Vendor Reloc and Fallback Names (#116974)
The trunk psABI document specifies that `R_RISCV_VENDOR` is 191, and that relocations 192-255 should be printed as `R_RISCV_CUSTOM<enum val>` in the absence of better information. The testcase shows that these parse in `.reloc` directives, and also print correctly from both the assembler and objdump.
1 parent 009368f commit fea7b65

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,68 @@ ELF_RELOC(R_RISCV_TLSDESC_HI20, 62)
6060
ELF_RELOC(R_RISCV_TLSDESC_LOAD_LO12, 63)
6161
ELF_RELOC(R_RISCV_TLSDESC_ADD_LO12, 64)
6262
ELF_RELOC(R_RISCV_TLSDESC_CALL, 65)
63+
ELF_RELOC(R_RISCV_VENDOR, 191)
64+
ELF_RELOC(R_RISCV_CUSTOM192, 192)
65+
ELF_RELOC(R_RISCV_CUSTOM193, 193)
66+
ELF_RELOC(R_RISCV_CUSTOM194, 194)
67+
ELF_RELOC(R_RISCV_CUSTOM195, 195)
68+
ELF_RELOC(R_RISCV_CUSTOM196, 196)
69+
ELF_RELOC(R_RISCV_CUSTOM197, 197)
70+
ELF_RELOC(R_RISCV_CUSTOM198, 198)
71+
ELF_RELOC(R_RISCV_CUSTOM199, 199)
72+
ELF_RELOC(R_RISCV_CUSTOM200, 200)
73+
ELF_RELOC(R_RISCV_CUSTOM201, 201)
74+
ELF_RELOC(R_RISCV_CUSTOM202, 202)
75+
ELF_RELOC(R_RISCV_CUSTOM203, 203)
76+
ELF_RELOC(R_RISCV_CUSTOM204, 204)
77+
ELF_RELOC(R_RISCV_CUSTOM205, 205)
78+
ELF_RELOC(R_RISCV_CUSTOM206, 206)
79+
ELF_RELOC(R_RISCV_CUSTOM207, 207)
80+
ELF_RELOC(R_RISCV_CUSTOM208, 208)
81+
ELF_RELOC(R_RISCV_CUSTOM209, 209)
82+
ELF_RELOC(R_RISCV_CUSTOM210, 210)
83+
ELF_RELOC(R_RISCV_CUSTOM211, 211)
84+
ELF_RELOC(R_RISCV_CUSTOM212, 212)
85+
ELF_RELOC(R_RISCV_CUSTOM213, 213)
86+
ELF_RELOC(R_RISCV_CUSTOM214, 214)
87+
ELF_RELOC(R_RISCV_CUSTOM215, 215)
88+
ELF_RELOC(R_RISCV_CUSTOM216, 216)
89+
ELF_RELOC(R_RISCV_CUSTOM217, 217)
90+
ELF_RELOC(R_RISCV_CUSTOM218, 218)
91+
ELF_RELOC(R_RISCV_CUSTOM219, 219)
92+
ELF_RELOC(R_RISCV_CUSTOM220, 220)
93+
ELF_RELOC(R_RISCV_CUSTOM221, 221)
94+
ELF_RELOC(R_RISCV_CUSTOM222, 222)
95+
ELF_RELOC(R_RISCV_CUSTOM223, 223)
96+
ELF_RELOC(R_RISCV_CUSTOM224, 224)
97+
ELF_RELOC(R_RISCV_CUSTOM225, 225)
98+
ELF_RELOC(R_RISCV_CUSTOM226, 226)
99+
ELF_RELOC(R_RISCV_CUSTOM227, 227)
100+
ELF_RELOC(R_RISCV_CUSTOM228, 228)
101+
ELF_RELOC(R_RISCV_CUSTOM229, 229)
102+
ELF_RELOC(R_RISCV_CUSTOM230, 230)
103+
ELF_RELOC(R_RISCV_CUSTOM231, 231)
104+
ELF_RELOC(R_RISCV_CUSTOM232, 232)
105+
ELF_RELOC(R_RISCV_CUSTOM233, 233)
106+
ELF_RELOC(R_RISCV_CUSTOM234, 234)
107+
ELF_RELOC(R_RISCV_CUSTOM235, 235)
108+
ELF_RELOC(R_RISCV_CUSTOM236, 236)
109+
ELF_RELOC(R_RISCV_CUSTOM237, 237)
110+
ELF_RELOC(R_RISCV_CUSTOM238, 238)
111+
ELF_RELOC(R_RISCV_CUSTOM239, 239)
112+
ELF_RELOC(R_RISCV_CUSTOM240, 240)
113+
ELF_RELOC(R_RISCV_CUSTOM241, 241)
114+
ELF_RELOC(R_RISCV_CUSTOM242, 242)
115+
ELF_RELOC(R_RISCV_CUSTOM243, 243)
116+
ELF_RELOC(R_RISCV_CUSTOM244, 244)
117+
ELF_RELOC(R_RISCV_CUSTOM245, 245)
118+
ELF_RELOC(R_RISCV_CUSTOM246, 246)
119+
ELF_RELOC(R_RISCV_CUSTOM247, 247)
120+
ELF_RELOC(R_RISCV_CUSTOM248, 248)
121+
ELF_RELOC(R_RISCV_CUSTOM249, 249)
122+
ELF_RELOC(R_RISCV_CUSTOM250, 250)
123+
ELF_RELOC(R_RISCV_CUSTOM251, 251)
124+
ELF_RELOC(R_RISCV_CUSTOM252, 252)
125+
ELF_RELOC(R_RISCV_CUSTOM253, 253)
126+
ELF_RELOC(R_RISCV_CUSTOM254, 254)
127+
ELF_RELOC(R_RISCV_CUSTOM255, 255)

llvm/test/MC/RISCV/custom_reloc.s

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# RUN: llvm-mc -triple riscv32 %s \
2+
# RUN: | FileCheck -check-prefix=CHECK-ASM %s
3+
# RUN: llvm-mc -triple riscv64 %s \
4+
# RUN: | FileCheck -check-prefix=CHECK-ASM %s
5+
6+
# RUN: llvm-mc -filetype=obj -triple riscv32 %s \
7+
# RUN: | llvm-objdump -dr -M no-aliases - \
8+
# RUN: | FileCheck -check-prefix=CHECK-OBJ %s
9+
# RUN: llvm-mc -filetype=obj -triple riscv64 %s \
10+
# RUN: | llvm-objdump -dr -M no-aliases - \
11+
# RUN: | FileCheck -check-prefix=CHECK-OBJ %s
12+
13+
# CHECK-ASM: .text
14+
# CHECK-OBJ: <.text>:
15+
16+
nop
17+
# CHECK-ASM: nop
18+
# CHECK-OBJ: addi zero, zero, 0x0
19+
20+
.reloc ., R_RISCV_VENDOR, VENDOR_NAME
21+
.reloc ., R_RISCV_CUSTOM192, my_foo + 1
22+
addi a0, a0, 0
23+
# CHECK-ASM: [[L1:.L[^:]+]]:
24+
# CHECK-ASM-NEXT: .reloc [[L1]], R_RISCV_VENDOR, VENDOR_NAME
25+
# CHECK-ASM-NEXT: [[L2:.L[^:]+]]:
26+
# CHECK-ASM-NEXT: .reloc [[L2]], R_RISCV_CUSTOM192, my_foo+1
27+
# CHECK-ASM-NEXT: mv a0, a0
28+
29+
# CHECK-OBJ: addi a0, a0, 0
30+
# CHECK-OBJ-NEXT: R_RISCV_VENDOR VENDOR_NAME
31+
# CHECK-OBJ-NEXT: R_RISCV_CUSTOM192 my_foo+0x1
32+
33+
nop
34+
# CHECK-ASM: nop
35+
# CHECK-OBJ: addi zero, zero, 0x0

0 commit comments

Comments
 (0)