[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 21:39:03 PST 2025


https://github.com/resistor updated https://github.com/llvm/llvm-project/pull/172414

>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 1/3] [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) {

>From 00c4803854e44b5343cc2f14aac0a65643225e17 Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Mon, 15 Dec 2025 22:42:52 -0600
Subject: [PATCH 2/3] Fix typo in test.

---
 llvm/unittests/Object/ELFTest.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/unittests/Object/ELFTest.cpp b/llvm/unittests/Object/ELFTest.cpp
index 1d218c5fe6471..b26d542ac152a 100644
--- a/llvm/unittests/Object/ELFTest.cpp
+++ b/llvm/unittests/Object/ELFTest.cpp
@@ -275,7 +275,7 @@ TEST(ELFTest, getRISCVVendorRelocationTypeName) {
   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"));
+            getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM223, "XCHERIOT1"));
 }
 
 TEST(ELFTest, getELFRelativeRelocationType) {

>From 095454b0e961d1ed47b3ca83283ad321686b0940 Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Mon, 15 Dec 2025 23:38:36 -0600
Subject: [PATCH 3/3] Drop X prefix and include version number in relocation
 names.

---
 .../BinaryFormat/ELFRelocs/RISCV_nonstandard.def |  8 ++++----
 llvm/unittests/Object/ELFTest.cpp                | 16 ++++++++--------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def b/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def
index 34a65a6580e29..fb0e29b2aaae5 100644
--- a/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def
+++ b/llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def
@@ -32,7 +32,7 @@ ELF_RISCV_NONSTANDARD_RELOC(QUALCOMM, R_RISCV_QC_E_CALL_PLT, 195)
 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)
+ELF_RISCV_NONSTANDARD_RELOC(CHERIOT1, R_RISCV_CHERIOT1_COMPARTMENT_HI, 220)
+ELF_RISCV_NONSTANDARD_RELOC(CHERIOT1, R_RISCV_CHERIOT1_COMPARTMENT_LO_I, 221)
+ELF_RISCV_NONSTANDARD_RELOC(CHERIOT1, R_RISCV_CHERIOT1_COMPARTMENT_LO_S, 222)
+ELF_RISCV_NONSTANDARD_RELOC(CHERIOT1, R_RISCV_CHERIOT1_COMPARTMENT_SIZE, 223)
diff --git a/llvm/unittests/Object/ELFTest.cpp b/llvm/unittests/Object/ELFTest.cpp
index b26d542ac152a..b0faf073e4ab5 100644
--- a/llvm/unittests/Object/ELFTest.cpp
+++ b/llvm/unittests/Object/ELFTest.cpp
@@ -268,14 +268,14 @@ 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_CUSTOM223, "XCHERIOT1"));
+  EXPECT_EQ("R_RISCV_CHERIOT1_COMPARTMENT_HI",
+            getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM220, "CHERIOT1"));
+  EXPECT_EQ("R_RISCV_CHERIOT1_COMPARTMENT_LO_I",
+            getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM221, "CHERIOT1"));
+  EXPECT_EQ("R_RISCV_CHERIOT1_COMPARTMENT_LO_S",
+            getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM222, "CHERIOT1"));
+  EXPECT_EQ("R_RISCV_CHERIOT1_COMPARTMENT_SIZE",
+            getRISCVVendorRelocationTypeName(R_RISCV_CUSTOM223, "CHERIOT1"));
 }
 
 TEST(ELFTest, getELFRelativeRelocationType) {



More information about the llvm-commits mailing list