Skip to content

Commit a9eeb16

Browse files
committed
[RISCV] Add Vendor Reloc and Fallbacks
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.
1 parent b17f607 commit a9eeb16

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

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

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

llvm/test/MC/RISCV/custom_reloc.s

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
15+
# If `.set` is used instead, the relocation expression will be evaluated.
16+
# This leaves an undef, global symbol called VENDOR_NAME, which I'm not happy
17+
# about.
18+
.global VENDOR_NAME
19+
20+
# CHECK-OBJ: <.text>:
21+
22+
nop
23+
# CHECK-ASM: nop
24+
# CHECK-OBJ: addi zero, zero, 0x0
25+
26+
.reloc ., R_RISCV_VENDOR, VENDOR_NAME
27+
.reloc ., R_RISCV_CUSTOM192, my_foo + 1
28+
addi a0, a0, 0
29+
# CHECK-ASM: [[L1:.L[^:]+]]:
30+
# CHECK-ASM-NEXT: .reloc [[L1]], R_RISCV_VENDOR, VENDOR_NAME
31+
# CHECK-ASM-NEXT: [[L2:.L[^:]+]]:
32+
# CHECK-ASM-NEXT: .reloc [[L2]], R_RISCV_CUSTOM192, my_foo+1
33+
# CHECK-ASM-NEXT: mv a0, a0
34+
35+
# CHECK-OBJ: addi a0, a0, 0
36+
# CHECK-OBJ-NEXT: R_RISCV_VENDOR VENDOR_NAME
37+
# CHECK-OBJ-NEXT: R_RISCV_CUSTOM192 my_foo+0x1
38+
39+
nop
40+
# CHECK-ASM: nop
41+
# CHECK-OBJ: addi zero, zero, 0x0
42+
43+

0 commit comments

Comments
 (0)