[llvm] [SPARC][IAS] Add v8plus feature bit (PR #101367)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 01:52:27 PDT 2024


================
@@ -21,11 +21,16 @@ using namespace llvm;
 namespace {
   class SparcELFObjectWriter : public MCELFObjectTargetWriter {
   public:
-    SparcELFObjectWriter(bool Is64Bit, bool HasV9, uint8_t OSABI)
+    SparcELFObjectWriter(bool Is64Bit, bool IsV8Plus, bool HasV9, uint8_t OSABI)
         : MCELFObjectTargetWriter(
               Is64Bit, OSABI,
-              Is64Bit ? ELF::EM_SPARCV9
-                      : (HasV9 ? ELF::EM_SPARC32PLUS : ELF::EM_SPARC),
+              Is64Bit
+                  ? ELF::EM_SPARCV9
+                  // Note that we still need to emit an EM_SPARC32PLUS object
+                  // even when V8+ isn't explicitly requested, if we're
+                  // targeting a V9-capable CPU. This matches GAS behavior upon
+                  // encountering any V9 instructions in its input.
+                  : ((IsV8Plus || HasV9) ? ELF::EM_SPARC32PLUS : ELF::EM_SPARC),
----------------
s-barannikov wrote:

> A binary that uses SPARC V9 and UltraSPARC features, referred to as a V8+ binary, must contain an indication of this in its ELF header since it will not execute in a vanilla V8 environment.

The V9 and UltraSPARC features are probably those specified in section 2:

> Chapter 2, “Differences”, is comprised of definitions and discussions of the
> differences between SPARC V8+ and SPARC V8; also, the SPARC V9 and
> UltraSPARC™ features, which comprise the V8+ specification.


> In any case, though, the kernel does set `-mv8plus` in its CFLAGS, so I suppose it would be fine too if we create V8+ objects only when requested?

Let's do it then.


https://github.com/llvm/llvm-project/pull/101367


More information about the llvm-commits mailing list