[llvm] [ELF/RISCV] Add definitions for XCHERIOT1 non-standard relocations on RISCV. (PR #172414)
Owen Anderson via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 15 20:19:03 PST 2025
https://github.com/resistor created https://github.com/llvm/llvm-project/pull/172414
The behavior of these relocations is specified in the CHERIoT Architecture specification, Version 1.0: https://github.com/CHERIoT-Platform/cheriot-sail/releases/download/v1.0/cheriot-architecture-v1.0.pdf
>From 8167a7818b901002aa6a1d104c312819125701be Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Mon, 15 Dec 2025 22:16:10 -0600
Subject: [PATCH] [ELF/RISCV] Add definitions for XCHERIOT1 non-standard
relocations on RISCV.
The behavior of these relocations is specified in the CHERIoT Architecture specification, Version 1.0: https://github.com/CHERIoT-Platform/cheriot-sail/releases/download/v1.0/cheriot-architecture-v1.0.pdf
---
.../llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def | 6 ++++++
llvm/unittests/Object/ELFTest.cpp | 9 +++++++++
2 files changed, 15 insertions(+)
diff --git a/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def b/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def
index 037ca64387339..34a65a6580e29 100644
--- a/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def
+++ b/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def
@@ -30,3 +30,9 @@ ELF_RISCV_NONSTANDARD_RELOC(QUALCOMM, R_RISCV_QC_E_CALL_PLT, 195)
// Andes Nonstandard Relocations
// Calculation: S + A - P (10-bit PC-relative branch offset)
ELF_RISCV_NONSTANDARD_RELOC(ANDES, R_RISCV_NDS_BRANCH_10, 241)
+
+// CHERIoT Nonstandard Relocations
+ELF_RISCV_NONSTANDARD_RELOC(XCHERIOT1, R_RISCV_CHERIOT_COMPARTMENT_HI, 220)
+ELF_RISCV_NONSTANDARD_RELOC(XCHERIOT1, R_RISCV_CHERIOT_COMPARTMENT_LO_I, 221)
+ELF_RISCV_NONSTANDARD_RELOC(XCHERIOT1, R_RISCV_CHERIOT_COMPARTMENT_LO_S, 222)
+ELF_RISCV_NONSTANDARD_RELOC(XCHERIOT1, R_RISCV_CHERIOT_COMPARTMENT_SIZE, 223)
diff --git a/llvm/unittests/Object/ELFTest.cpp b/llvm/unittests/Object/ELFTest.cpp
index 61ec78fea953a..1d218c5fe6471 100644
--- a/llvm/unittests/Object/ELFTest.cpp
+++ b/llvm/unittests/Object/ELFTest.cpp
@@ -267,6 +267,15 @@ TEST(ELFTest, getRISCVVendorRelocationTypeName) {
EXPECT_EQ("R_RISCV_NDS_BRANCH_10",
getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM241, "ANDES"));
+
+ EXPECT_EQ("R_RISCV_CHERIOT_COMPARTMENT_HI",
+ getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM220, "XCHERIOT1"));
+ EXPECT_EQ("R_RISCV_CHERIOT_COMPARTMENT_LO_I",
+ getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM221, "XCHERIOT1"));
+ EXPECT_EQ("R_RISCV_CHERIOT_COMPARTMENT_LO_S",
+ getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM222, "XCHERIOT1"));
+ EXPECT_EQ("R_RISCV_CHERIOT_COMPARTMENT_SIZE",
+ getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM222, "XCHERIOT1"));
}
TEST(ELFTest, getELFRelativeRelocationType) {
More information about the llvm-commits
mailing list