Skip to content

Commit c13388a

Browse files
jrtc27resistor
authored andcommitted
[ELF][RISCV] Stop using CSub for capability subtraction
This code is currently dead since we emit an all-zeroes PLT header on CHERI-RISC-V, but will soon be used. Fixes: 05652b9 ("[CHERI-RISC-V] Remove CSub")
1 parent 7225b82 commit c13388a

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

lld/ELF/Arch/RISCV.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ enum Op {
7878
CIncOffsetImm = 0x105b,
7979
CLC_64 = 0x3003,
8080
CLC_128 = 0x200f,
81-
CSub = 0x2800005b,
8281

8382
AUIPCC = 0x17,
8483
AUICGP = 0x7b,
@@ -272,12 +271,12 @@ void RISCV::writePltHeader(uint8_t *buf) const {
272271
// (c)sub t1, (c)t1, (c)t3
273272
// l[wdc] (c)t3, %pcrel_lo(1b)((c)t2); (c)t3 = _dl_runtime_resolve
274273
// addi t1, t1, -pltHeaderSize-12; t1 = &.plt[i] - &.plt[0]
275-
// addi t0, t2, %pcrel_lo(1b)
276-
// srli t1, t1, (rv64?1:2); t1 = &.got.plt[i] - &.got.plt[0]
277-
// l[wd] t0, Wordsize(t0); t0 = link_map
278-
// jr t3
274+
// addi/cincoffset (c)t0, (c)t2, %pcrel_lo(1b)
275+
// (if shift != 0): srli t1, t1, shift; t1 = &.got.plt[i] - &.got.plt[0]
276+
// l[wdc] (c)t0, Ptrsize((c)t0); (c)t0 = link_map
277+
// (c)jr (c)t3
278+
// (if shift == 0): nop
279279
uint32_t offset = ctx.in.gotPlt->getVA() - ctx.in.plt->getVA();
280-
uint32_t ptrsub = ctx.arg.isCheriAbi ? CSub : SUB;
281280
uint32_t ptrload = ctx.arg.isCheriAbi ? ctx.arg.is64 ? CLC_128 : CLC_64
282281
: ctx.arg.is64 ? LD
283282
: LW;
@@ -287,7 +286,7 @@ void RISCV::writePltHeader(uint8_t *buf) const {
287286
uint32_t ptrsize =
288287
ctx.arg.isCheriAbi ? ctx.arg.capabilitySize : ctx.arg.wordsize;
289288
write32le(buf + 0, utype(AUIPC, X_T2, hi20(offset)));
290-
write32le(buf + 4, rtype(ptrsub, X_T1, X_T1, X_T3));
289+
write32le(buf + 4, rtype(SUB, X_T1, X_T1, X_T3));
291290
write32le(buf + 8, itype(ptrload, X_T3, X_T2, lo12(offset)));
292291
write32le(buf + 12, itype(ADDI, X_T1, X_T1, -ctx.target->pltHeaderSize - 12));
293292
write32le(buf + 16, itype(ptraddi, X_T0, X_T2, lo12(offset)));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ELF_RELOC(R_RISCV_VENDOR, 191)
6464
// ELF_RELOC(R_RISCV_CUSTOM192, 192)
6565
// ELF_RELOC(R_RISCV_CUSTOM193, 193)
6666
ELF_RELOC(R_RISCV_CUSTOM194, 194)
67-
// ELF_RELOC(R_RISCV_CUSTOM195, 195)
67+
ELF_RELOC(R_RISCV_CUSTOM195, 195)
6868
// ELF_RELOC(R_RISCV_CUSTOM196, 196)
6969
// ELF_RELOC(R_RISCV_CUSTOM197, 197)
7070
// ELF_RELOC(R_RISCV_CUSTOM198, 198)

llvm/test/MC/RISCV/rv32-relaxation-xqci.s

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ start:
4040
# CHECK: qc.e.j {{0x[0-9a-f]+}} <EXT_JUMP_NEGATIVE>
4141
c.j undef
4242
# CHECK: qc.e.j {{0x[0-9a-f]+}} <start+{{0x[0-9a-f]+}}>
43-
# CHECK: R_RISCV_CHERI_SIZE undef
43+
# CHECK: R_RISCV_CUSTOM195 undef
4444

4545
c.jal NEAR
4646
# CHECK: c.jal {{0x[0-9a-f]+}} <NEAR>
@@ -56,7 +56,7 @@ start:
5656
# CHECK: qc.e.jal {{0x[0-9a-f]+}} <EXT_JUMP_NEGATIVE>
5757
c.jal undef
5858
# CHECK: qc.e.jal {{0x[0-9a-f]+}} <start+{{0x[0-9a-f]+}}>
59-
# CHECK: R_RISCV_CHERI_SIZE undef
59+
# CHECK: R_RISCV_CUSTOM195 undef
6060

6161
jal zero, NEAR
6262
# CHECK: c.j {{0x[0-9a-f]+}} <NEAR>
@@ -72,7 +72,7 @@ start:
7272
# CHECK: qc.e.j {{0x[0-9a-f]+}} <EXT_JUMP_NEGATIVE>
7373
jal zero, undef
7474
# CHECK: qc.e.j {{0x[0-9a-f]+}} <start+{{0x[0-9a-f]+}}>
75-
# CHECK: R_RISCV_CHERI_SIZE undef
75+
# CHECK: R_RISCV_CUSTOM195 undef
7676

7777
jal ra, NEAR
7878
# CHECK: c.jal {{0x[0-9a-f]+}} <NEAR>
@@ -88,7 +88,7 @@ start:
8888
# CHECK: qc.e.jal {{0x[0-9a-f]+}} <EXT_JUMP_NEGATIVE>
8989
jal ra, undef
9090
# CHECK: qc.e.jal {{0x[0-9a-f]+}} <start+{{0x[0-9a-f]+}}>
91-
# CHECK: R_RISCV_CHERI_SIZE undef
91+
# CHECK: R_RISCV_CUSTOM195 undef
9292

9393
qc.e.j NEAR
9494
# CHECK: c.j {{0x[0-9a-f]+}} <NEAR>
@@ -104,7 +104,7 @@ start:
104104
# CHECK: qc.e.j {{0x[0-9a-f]+}} <EXT_JUMP_NEGATIVE>
105105
qc.e.j undef
106106
# CHECK: qc.e.j {{0x[0-9a-f]+}} <start+{{0x[0-9a-f]+}}>
107-
# CHECK: R_RISCV_CHERI_SIZE undef
107+
# CHECK: R_RISCV_CUSTOM195 undef
108108

109109
qc.e.jal NEAR
110110
# CHECK: c.jal {{0x[0-9a-f]+}} <NEAR>
@@ -120,7 +120,7 @@ start:
120120
# CHECK: qc.e.jal {{0x[0-9a-f]+}} <EXT_JUMP_NEGATIVE>
121121
qc.e.jal undef
122122
# CHECK: qc.e.jal {{0x[0-9a-f]+}} <start+{{0x[0-9a-f]+}}>
123-
# CHECK: R_RISCV_CHERI_SIZE undef
123+
# CHECK: R_RISCV_CUSTOM195 undef
124124

125125

126126

llvm/test/MC/RISCV/xqcibi-linker-relaxation.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ branch_over_relaxable:
1515
jal x1, foo
1616
# CHECK: qc.e.jal 0x0 <branch_over_relaxable>
1717
# CHECK-NEXT: R_RISCV_VENDOR QUALCOMM
18-
# CHECK-NEXT: R_RISCV_CHERI_SIZE foo
18+
# CHECK-NEXT: R_RISCV_CUSTOM195 foo
1919
# CHECK-NEXT: R_RISCV_RELAX *ABS*
2020
bne a0, a1, branch_over_relaxable
2121
# CHECK-NEXT: bne a0, a1, 0x6 <branch_over_relaxable+0x6>

llvm/test/MC/RISCV/xqcilb-relocations.s

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ this_section:
2121
# ASM: qc.e.j undef
2222
# OBJ: qc.e.j 0x0 <this_section>
2323
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
24-
# OBJ-NEXT: R_RISCV_CHERI_SIZE undef{{$}}
24+
# OBJ-NEXT: R_RISCV_CUSTOM195 undef{{$}}
2525
qc.e.j undef
2626

2727
# ASM: qc.e.jal undef
2828
# OBJ-NEXT: qc.e.jal 0x6 <this_section+0x6>
2929
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
30-
# OBJ-NEXT: R_RISCV_CHERI_SIZE undef{{$}}
30+
# OBJ-NEXT: R_RISCV_CUSTOM195 undef{{$}}
3131
qc.e.jal undef
3232

3333

@@ -42,26 +42,26 @@ qc.e.jal same_section
4242
# ASM: qc.e.j same_section_extern
4343
# OBJ-NEXT: qc.e.j 0x18 <this_section+0x18>
4444
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
45-
# OBJ-NEXT: R_RISCV_CHERI_SIZE same_section_extern{{$}}
45+
# OBJ-NEXT: R_RISCV_CUSTOM195 same_section_extern{{$}}
4646
qc.e.j same_section_extern
4747

4848
# ASM: qc.e.jal same_section_extern
4949
# OBJ-NEXT: qc.e.jal 0x1e <this_section+0x1e>
5050
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
51-
# OBJ-NEXT: R_RISCV_CHERI_SIZE same_section_extern{{$}}
51+
# OBJ-NEXT: R_RISCV_CUSTOM195 same_section_extern{{$}}
5252
qc.e.jal same_section_extern
5353

5454

5555
# ASM: qc.e.j other_section
5656
# OBJ-NEXT: qc.e.j 0x24 <this_section+0x24>
5757
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
58-
# OBJ-NEXT: R_RISCV_CHERI_SIZE other_section{{$}}
58+
# OBJ-NEXT: R_RISCV_CUSTOM195 other_section{{$}}
5959
qc.e.j other_section
6060

6161
# ASM: qc.e.jal other_section
6262
# OBJ-NEXT: qc.e.jal 0x2a <this_section+0x2a>
6363
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
64-
# OBJ-NEXT: R_RISCV_CHERI_SIZE other_section{{$}}
64+
# OBJ-NEXT: R_RISCV_CUSTOM195 other_section{{$}}
6565
qc.e.jal other_section
6666

6767

@@ -81,14 +81,14 @@ same_section_extern:
8181
# ASM: qc.e.j same_section
8282
# OBJ: qc.e.j 0x38 <same_section_extern+0x4>
8383
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
84-
# OBJ-NEXT: R_RISCV_CHERI_SIZE same_section{{$}}
84+
# OBJ-NEXT: R_RISCV_CUSTOM195 same_section{{$}}
8585
# OBJ-NEXT: R_RISCV_RELAX
8686
qc.e.j same_section
8787

8888
# ASM: qc.e.jal same_section
8989
# OBJ-NEXT: qc.e.jal 0x3e <same_section_extern+0xa>
9090
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
91-
# OBJ-NEXT: R_RISCV_CHERI_SIZE same_section{{$}}
91+
# OBJ-NEXT: R_RISCV_CUSTOM195 same_section{{$}}
9292
# OBJ-NEXT: R_RISCV_RELAX
9393
qc.e.jal same_section
9494

@@ -99,14 +99,14 @@ qc.e.j undef
9999
# ASM: j undef
100100
# OBJ: qc.e.j 0x44 <same_section_extern+0x10>
101101
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
102-
# OBJ-NEXT: R_RISCV_CHERI_SIZE undef{{$}}
102+
# OBJ-NEXT: R_RISCV_CUSTOM195 undef{{$}}
103103
# OBJ-NEXT: R_RISCV_RELAX
104104

105105
qc.e.jal undef
106106
# ASM: jal undef
107107
# OBJ: qc.e.jal 0x4a <same_section_extern+0x16>
108108
# OBJ-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
109-
# OBJ-NEXT: R_RISCV_CHERI_SIZE undef{{$}}
109+
# OBJ-NEXT: R_RISCV_CUSTOM195 undef{{$}}
110110
# OBJ-NEXT: R_RISCV_RELAX
111111

112112
.section .text.other, "ax", @progbits

0 commit comments

Comments
 (0)