Skip to content

Commit a633851

Browse files
jrtc27resistor
authored andcommitted
[RISCV] Use new %code(expr) for lowerCheriCodeReference
1 parent 37d9cb8 commit a633851

File tree

8 files changed

+32
-16
lines changed

8 files changed

+32
-16
lines changed

lld/test/ELF/cheri/exception-table.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
; MIPS-OBJ-RELOCS-NEXT: R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE .L_Z9test_weakll$local 0x34
1616
; MIPS-OBJ-RELOCS-NEXT: }
1717
; RV64-OBJ-RELOCS: Section ({{.+}}) .rela.gcc_except_table {
18-
; RV64-OBJ-RELOCS-NEXT: 0x20 R_RISCV_CHERI_CAPABILITY .L_Z4testll$local 0x5C
19-
; RV64-OBJ-RELOCS-NEXT: 0x40 R_RISCV_CHERI_CAPABILITY .L_Z4testll$local 0x48
20-
; RV64-OBJ-RELOCS-NEXT: 0x80 R_RISCV_CHERI_CAPABILITY .L_Z5test2ll$local 0x44
18+
; RV64-OBJ-RELOCS-NEXT: 0x20 R_RISCV_CHERI_CAPABILITY_CODE .L_Z4testll$local 0x5C
19+
; RV64-OBJ-RELOCS-NEXT: 0x40 R_RISCV_CHERI_CAPABILITY_CODE .L_Z4testll$local 0x48
20+
; RV64-OBJ-RELOCS-NEXT: 0x80 R_RISCV_CHERI_CAPABILITY_CODE .L_Z5test2ll$local 0x44
2121
; RV64-OBJ-RELOCS-NEXT: 0xA4 R_RISCV_ADD32 .L_ZTIl.DW.stub 0x0
2222
; RV64-OBJ-RELOCS-NEXT: 0xA4 R_RISCV_SUB32 .L0 0x0
23-
; RV64-OBJ-RELOCS-NEXT: 0xC0 R_RISCV_CHERI_CAPABILITY .L_Z9test_weakll$local 0x1C
23+
; RV64-OBJ-RELOCS-NEXT: 0xC0 R_RISCV_CHERI_CAPABILITY_CODE .L_Z9test_weakll$local 0x1C
2424
; RV64-OBJ-RELOCS-NEXT: }
2525

2626
;; This should work with both -z text and -z notext
@@ -94,11 +94,11 @@
9494
; RV64-RELOCS-OVERRIDE: [[#%.16x,TEST_WEAK_OVERRIDE_ADDR:]] 8 FUNC GLOBAL DEFAULT 9 _Z9test_weakll{{$}}
9595

9696
; RV64-RELOCS: CHERI __cap_relocs [
97-
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+92) Length: 116 Perms: Function
98-
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+72) Length: 116 Perms: Function
99-
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST2_ADDR]] (.L_Z5test2ll$local+68) Length: 124 Perms: Function
97+
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+92) Length: 116 Perms: Code
98+
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST_ADDR]] (.L_Z4testll$local+72) Length: 116 Perms: Code
99+
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST2_ADDR]] (.L_Z5test2ll$local+68) Length: 124 Perms: Code
100100
; Next one references the local symbol, and uses that length rather than the override:
101-
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST_WEAK_ADDR]] (.L_Z9test_weakll$local+28) Length: 52 Perms: Function
101+
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,TEST_WEAK_ADDR]] (.L_Z9test_weakll$local+28) Length: 52 Perms: Code
102102
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,PLT0_ADDR:]] (<unknown symbol>+0) Length: 80 Perms: Code
103103
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,PLT0_ADDR]] (<unknown symbol>+0) Length: 80 Perms: Code
104104
; RV64-RELOCS-NEXT: 0x003{{.+}} Base: 0x[[#%x,PLT0_ADDR]] (<unknown symbol>+0) Length: 80 Perms: Code

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/BinaryFormat/ELF.h"
1818
#include "llvm/MC/MCAssembler.h"
1919
#include "llvm/MC/MCContext.h"
20+
#include "llvm/MC/MCObjectWriter.h"
2021
#include "llvm/MC/MCStreamer.h"
2122
#include "llvm/MC/MCValue.h"
2223
#include "llvm/Support/Casting.h"

llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,14 @@ int RISCVELFTargetObjectFile::getCheriCapabilitySize(
210210
const RISCVTargetMachine &RTM = static_cast<const RISCVTargetMachine &>(TM);
211211
return RTM.IsRV64() ? 16 : 8;
212212
}
213+
214+
const MCExpr *
215+
RISCVELFTargetObjectFile::lowerCheriCodeReference(const MCSymbol *Sym,
216+
const MCExpr *Addend) const {
217+
const MCExpr *Expr = MCSymbolRefExpr::create(Sym, getContext());
218+
if (Addend != nullptr)
219+
Expr = MCBinaryExpr::createAdd(Expr, Addend, getContext());
220+
Expr = MCSpecifierExpr::create(Expr, ELF::R_RISCV_CHERI_CAPABILITY_CODE,
221+
getContext());
222+
return Expr;
223+
}

llvm/lib/Target/RISCV/RISCVTargetObjectFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class RISCVELFTargetObjectFile : public TargetLoweringObjectFileELF {
6262
const TargetMachine &TM) const override;
6363

6464
int getCheriCapabilitySize(const TargetMachine &TM) const override;
65+
66+
const MCExpr *lowerCheriCodeReference(const MCSymbol *Sym,
67+
const MCExpr *Addend) const override;
6568
};
6669

6770
} // end namespace llvm

llvm/test/CodeGen/CHERI-Generic/Inputs/landingpad-non-preemptible.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ declare dso_local void @__cxa_end_catch() local_unnamed_addr addrspace(200)
7575
; CHECK-NEXT: [[CS_DIRECTIVE]] .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1
7676
; Note: RISC-V uses DW_EH_PE_udata4, so the 0xc marker uses 4 bytes instead of 1
7777
; CHECK-NEXT: [[SMALL_CS_DIRECTIVE:(\.byte)|(\.word)]] 12 # (landing pad is a capability)
78-
; CHECK-NEXT: .chericap .Llpad0 # jumps to .Llpad0
78+
@IF-MIPS@; CHECK-NEXT: .chericap .Llpad0 # jumps to .Llpad0
79+
@IF-RISCV@; CHECK-NEXT: .chericap %code(.L_Z8do_catchv$local+(.Ltmp2-.Lfunc_begin0)) # jumps to .Ltmp2
7980
; CHECK-NEXT: .byte 3 # On action: 2
8081
; CHECK-NEXT: [[CS_DIRECTIVE]] .Ltmp1-.Lfunc_begin0 # >> Call Site 2 <<
8182
; CHECK-NEXT: [[CS_DIRECTIVE]] .Lfunc_end0-.Ltmp1 # Call between .Ltmp1 and .Lfunc_end0
@@ -104,7 +105,7 @@ declare dso_local void @__cxa_end_catch() local_unnamed_addr addrspace(200)
104105
; RELOCS-LABEL: Section ({{.+}}) .rela.gcc_except_table {
105106
@IF-MIPS@; RELOCS-NEXT: 0x10 R_MIPS_CHERI_CAPABILITY/R_MIPS_NONE/R_MIPS_NONE .Llpad0 0x0{{$}}
106107
@IF-MIPS@; RELOCS-NEXT: R_MIPS_PC32/R_MIPS_NONE/R_MIPS_NONE .L_ZTIi.DW.stub 0x0
107-
@IF-RISCV@; RELOCS-NEXT: R_RISCV_CHERI_CAPABILITY .Llpad0 0x0{{$}}
108+
@IF-RISCV@; RELOCS-NEXT: R_RISCV_CHERI_CAPABILITY_CODE .Llpad0 0x0{{$}}
108109
@IF-RISCV@; RELOCS-NEXT: R_RISCV_ADD32 <null> 0x0
109110
@IF-RISCV@; RELOCS-NEXT: R_RISCV_SUB32 <null> 0x0
110111
@IF-RISCV@; RELOCS-NEXT: R_RISCV_ADD32 .L_ZTIi.DW.stub 0x0

llvm/test/CodeGen/CHERI-Generic/RISCV32/landingpad-non-preemptible.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ declare dso_local void @__cxa_end_catch() local_unnamed_addr addrspace(200)
111111
; CHECK-NEXT: [[CS_DIRECTIVE]] .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1
112112
; Note: RISC-V uses DW_EH_PE_udata4, so the 0xc marker uses 4 bytes instead of 1
113113
; CHECK-NEXT: [[SMALL_CS_DIRECTIVE:(\.byte)|(\.word)]] 12 # (landing pad is a capability)
114-
; CHECK-NEXT: .chericap .L_Z8do_catchv$local+(.Ltmp2-.Lfunc_begin0) # jumps to .Ltmp2
114+
; CHECK-NEXT: .chericap %code(.L_Z8do_catchv$local+(.Ltmp2-.Lfunc_begin0)) # jumps to .Ltmp2
115115
; CHECK-NEXT: .byte 3 # On action: 2
116116
; CHECK-NEXT: [[CS_DIRECTIVE]] .Ltmp1-.Lfunc_begin0 # >> Call Site 2 <<
117117
; CHECK-NEXT: [[CS_DIRECTIVE]] .Lfunc_end0-.Ltmp1 # Call between .Ltmp1 and .Lfunc_end0
@@ -138,7 +138,7 @@ declare dso_local void @__cxa_end_catch() local_unnamed_addr addrspace(200)
138138

139139
; RELOCS-LABEL: Relocations [
140140
; RELOCS-LABEL: Section ({{.+}}) .rela.gcc_except_table {
141-
; RELOCS-NEXT: R_RISCV_CHERI_CAPABILITY .L_Z8do_catchv$local 0x24
141+
; RELOCS-NEXT: R_RISCV_CHERI_CAPABILITY_CODE .L_Z8do_catchv$local 0x24
142142
; RELOCS-NEXT: R_RISCV_ADD32 .L_ZTIi.DW.stub 0x0
143143
; RELOCS-NEXT: R_RISCV_SUB32 .L0 0x0
144144
; RELOCS-NEXT: }

llvm/test/CodeGen/CHERI-Generic/RISCV64/landingpad-non-preemptible.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ declare dso_local void @__cxa_end_catch() local_unnamed_addr addrspace(200)
111111
; CHECK-NEXT: [[CS_DIRECTIVE]] .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1
112112
; Note: RISC-V uses DW_EH_PE_udata4, so the 0xc marker uses 4 bytes instead of 1
113113
; CHECK-NEXT: [[SMALL_CS_DIRECTIVE:(\.byte)|(\.word)]] 12 # (landing pad is a capability)
114-
; CHECK-NEXT: .chericap .L_Z8do_catchv$local+(.Ltmp2-.Lfunc_begin0) # jumps to .Ltmp2
114+
; CHECK-NEXT: .chericap %code(.L_Z8do_catchv$local+(.Ltmp2-.Lfunc_begin0)) # jumps to .Ltmp2
115115
; CHECK-NEXT: .byte 3 # On action: 2
116116
; CHECK-NEXT: [[CS_DIRECTIVE]] .Ltmp1-.Lfunc_begin0 # >> Call Site 2 <<
117117
; CHECK-NEXT: [[CS_DIRECTIVE]] .Lfunc_end0-.Ltmp1 # Call between .Ltmp1 and .Lfunc_end0
@@ -138,7 +138,7 @@ declare dso_local void @__cxa_end_catch() local_unnamed_addr addrspace(200)
138138

139139
; RELOCS-LABEL: Relocations [
140140
; RELOCS-LABEL: Section ({{.+}}) .rela.gcc_except_table {
141-
; RELOCS-NEXT: R_RISCV_CHERI_CAPABILITY .L_Z8do_catchv$local 0x24
141+
; RELOCS-NEXT: R_RISCV_CHERI_CAPABILITY_CODE .L_Z8do_catchv$local 0x24
142142
; RELOCS-NEXT: R_RISCV_ADD32 .L_ZTIi.DW.stub 0x0
143143
; RELOCS-NEXT: R_RISCV_SUB32 .L0 0x0
144144
; RELOCS-NEXT: }

llvm/test/CodeGen/RISCV/cheri/function-start-directives.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ declare dso_local void @__cxa_end_catch() local_unnamed_addr addrspace(200)
6464

6565
; CHECK: .section .gcc_except_table
6666
; CHECK: .word 12 # (landing pad is a capability)
67-
; CHECK-NEXT: .chericap .L_Z4testv$local+(.Ltmp2-.Lfunc_begin0) # jumps to .Ltmp2
67+
; CHECK-NEXT: .chericap %code(.L_Z4testv$local+(.Ltmp2-.Lfunc_begin0)) # jumps to .Ltmp2
6868

6969
; OBJ-LABEL: Relocation section '.rela.gcc_except_table' at offset
7070
; OBJ: Offset Info Type Symbol's Value Symbol's Name + Addend
71-
; OBJ: 0000000000000020 0000000{{.}}000000c1 R_RISCV_CHERI_CAPABILITY
71+
; OBJ: 0000000000000020 0000000{{.}}000000c3 R_RISCV_CHERI_CAPABILITY_CODE
7272

7373
; OBJ-LABEL: Symbol table '.symtab' contains
7474
; OBJ: Value Size Type Bind Vis Ndx Name

0 commit comments

Comments
 (0)