[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:01:24 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-sparc

Author: Koakuma (koachan)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/130966.diff


2 Files Affected:

- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcTargetStreamer.cpp (+8) 
- (added) llvm/test/MC/Sparc/elf-sparc-feature.s (+11) 


``````````diff
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: ]

``````````

</details>


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


More information about the llvm-commits mailing list