Repository: gimli-rs/object
Pull request #700 (2024-06-26 08:58:46)

Add Architecture::Sparc32Plus
This adds support for 32-bit SPARC using the V9 baseline (V8plus).


Patch:
diff --git a/src/common.rs b/src/common.rs
index 41f7191..c9db8c3 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -28,6 +28,7 @@ pub enum Architecture {
     Sbf,
     Sharc,
     Sparc,
+    Sparc32Plus,
     Sparc64,
     Wasm32,
     Wasm64,
@@ -72,6 +73,7 @@ impl Architecture {
             Architecture::Sbf => Some(AddressSize::U64),
             Architecture::Sharc => Some(AddressSize::U32),
             Architecture::Sparc => Some(AddressSize::U32),
+            Architecture::Sparc32Plus => Some(AddressSize::U32),
             Architecture::Sparc64 => Some(AddressSize::U64),
             Architecture::Wasm32 => Some(AddressSize::U32),
             Architecture::Wasm64 => Some(AddressSize::U64),
diff --git a/src/read/elf/file.rs b/src/read/elf/file.rs
index 107a521..eb74c28 100644
--- a/src/read/elf/file.rs
+++ b/src/read/elf/file.rs
@@ -227,6 +227,7 @@ where
             (elf::EM_SBF, _) => Architecture::Sbf,
             (elf::EM_SHARC, false) => Architecture::Sharc,
             (elf::EM_SPARC, false) => Architecture::Sparc,
+            (elf::EM_SPARC32PLUS, false) => Architecture::Sparc32Plus,
             (elf::EM_SPARCV9, true) => Architecture::Sparc64,
             (elf::EM_XTENSA, false) => Architecture::Xtensa,
             _ => Architecture::Unknown,
diff --git a/src/write/elf/object.rs b/src/write/elf/object.rs
index ef97f4f..0920a0d 100644
--- a/src/write/elf/object.rs
+++ b/src/write/elf/object.rs
@@ -142,6 +142,7 @@ impl<'a> Object<'a> {
             Architecture::Sbf => false,
             Architecture::Sharc => true,
             Architecture::Sparc => true,
+            Architecture::Sparc32Plus => true,
             Architecture::Sparc64 => true,
             Architecture::Xtensa => true,
             _ => {
@@ -412,7 +413,7 @@ impl<'a> Object<'a> {
                     return Err(Error(format!("unimplemented relocation {:?}", reloc)));
                 }
             },
-            Architecture::Sparc => match (kind, encoding, size) {
+            Architecture::Sparc | Architecture::Sparc32Plus => match (kind, encoding, size) {
                 // TODO: use R_SPARC_32 if aligned.
                 (RelocationKind::Absolute, _, 32) => elf::R_SPARC_UA32,
                 _ => {
@@ -640,6 +641,7 @@ impl<'a> Object<'a> {
             (Architecture::Sbf, None) => elf::EM_SBF,
             (Architecture::Sharc, None) => elf::EM_SHARC,
             (Architecture::Sparc, None) => elf::EM_SPARC,
+            (Architecture::Sparc32Plus, None) => elf::EM_SPARC32PLUS,
             (Architecture::Sparc64, None) => elf::EM_SPARCV9,
             (Architecture::Xtensa, None) => elf::EM_XTENSA,
             _ => {


Test patch:
diff --git a/tests/round_trip/mod.rs b/tests/round_trip/mod.rs
index 11eb757..3a592eb 100644
--- a/tests/round_trip/mod.rs
+++ b/tests/round_trip/mod.rs
@@ -280,6 +280,7 @@ fn elf_any() {
         (Architecture::S390x, Endianness::Big),
         (Architecture::Sbf, Endianness::Little),
         (Architecture::Sparc, Endianness::Big),
+        (Architecture::Sparc32Plus, Endianness::Big),
         (Architecture::Sparc64, Endianness::Big),
         (Architecture::Xtensa, Endianness::Little),
     ]