[llvm] [SPARC][IAS] Set correct ELF flag values for VIS & VIS2-enabled objects (PR #130966)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 12 07:00:49 PDT 2025


https://github.com/koachan created https://github.com/llvm/llvm-project/pull/130966

None

>From 663b411342767d6a91daebdfa4fcfb7be5fc4be3 Mon Sep 17 00:00:00 2001
From: Koakuma <koachan at protonmail.com>
Date: Wed, 12 Mar 2025 21:00:24 +0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 .../Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp |  8 ++++++++
 llvm/test/MC/Sparc/elf-sparc-feature.s                | 11 +++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 llvm/test/MC/Sparc/elf-sparc-feature.s

diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp
index 3205d06b295ee..6dd89849a2b71 100644
--- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp
+++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp
@@ -27,6 +27,14 @@ static unsigned getEFlagsForFeatureSet(const MCSubtargetInfo &STI) {
   if (STI.hasFeature(Sparc::FeatureV8Plus))
     EFlags |= ELF::EF_SPARC_32PLUS;
 
+  if (STI.hasFeature(Sparc::FeatureVIS))
+    EFlags |= ELF::EF_SPARC_SUN_US1;
+
+  if (STI.hasFeature(Sparc::FeatureVIS2))
+    EFlags |= ELF::EF_SPARC_SUN_US3;
+
+  // VIS 3 and other ISA extensions doesn't set any flags.
+
   return EFlags;
 }
 
diff --git a/llvm/test/MC/Sparc/elf-sparc-feature.s b/llvm/test/MC/Sparc/elf-sparc-feature.s
new file mode 100644
index 0000000000000..db30396c950f1
--- /dev/null
+++ b/llvm/test/MC/Sparc/elf-sparc-feature.s
@@ -0,0 +1,11 @@
+## Emit correct SPARC v9 ELF flags depending on feature options.
+## - `-mattr=+vis` sets the EF_SPARC_SUN_US1 flag; and
+## - `-mattr=+vis2` sets the EF_SPARC_SUN_US3 flag.
+
+# RUN: llvm-mc -filetype=obj -triple sparcv9              %s -o - | llvm-readobj -h - | FileCheck --check-prefixes=COMMON      -DFLAG_VALUE=0x0                                %s
+# RUN: llvm-mc -filetype=obj -triple sparcv9 -mattr=+vis  %s -o - | llvm-readobj -h - | FileCheck --check-prefixes=COMMON,FLAG -DFLAG_VALUE=0x200 -DFLAG_NAME=EF_SPARC_SUN_US1 %s
+# RUN: llvm-mc -filetype=obj -triple sparcv9 -mattr=+vis2 %s -o - | llvm-readobj -h - | FileCheck --check-prefixes=COMMON,FLAG -DFLAG_VALUE=0x800 -DFLAG_NAME=EF_SPARC_SUN_US3 %s
+
+# COMMON:      Flags [ ([[FLAG_VALUE]])
+# FLAG:          [[FLAG_NAME]]
+# COMMON-NEXT: ]



More information about the llvm-commits mailing list