Skip to content

[SPARC][Driver] Set correct IAS mode defaults for Linux and Free/OpenBSD #130108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2025

Conversation

koachan
Copy link
Contributor

@koachan koachan commented Mar 6, 2025

On those OSes, clang should set the assembler to enable VIS by default. This is already the case when clang calls an external assembler, so make sure clang+IAS use the same defaults.

This should fix issue #125124.

On those OSes, clang should set the assembler to enable VIS by default.
This is already the case when clang calls an external assembler, so make sure
clang+IAS use the same defaults.

This should fix [issue llvm#125124](llvm#125124).
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Mar 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Koakuma (koachan)

Changes

On those OSes, clang should set the assembler to enable VIS by default. This is already the case when clang calls an external assembler, so make sure clang+IAS use the same defaults.

This should fix issue #125124.


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

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+11)
  • (modified) clang/test/Driver/sparc-ias-Wa.s (+9)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 4ebbd241d2f0b..e70833cc4a38e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2876,6 +2876,17 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
     CmdArgs.push_back("-target-feature");
     CmdArgs.push_back(MipsTargetFeature);
   }
+
+  // Those OSes default to enabling VIS on 64-bit SPARC.
+  // See also the corresponding code for external assemblers in
+  // sparc::getSparcAsmModeForCPU().
+  bool IsSparcV9ATarget =
+      (C.getDefaultToolChain().getArch() == llvm::Triple::sparcv9) &&
+      (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
+  if (IsSparcV9ATarget && SparcTargetFeatures.empty()) {
+    CmdArgs.push_back("-target-feature");
+    CmdArgs.push_back("+vis");
+  }
   for (const char *Feature : SparcTargetFeatures) {
     CmdArgs.push_back("-target-feature");
     CmdArgs.push_back(Feature);
diff --git a/clang/test/Driver/sparc-ias-Wa.s b/clang/test/Driver/sparc-ias-Wa.s
index 79456c02935be..c031f237297d3 100644
--- a/clang/test/Driver/sparc-ias-Wa.s
+++ b/clang/test/Driver/sparc-ias-Wa.s
@@ -58,3 +58,12 @@
 // V9D: "-target-feature" "+vis"
 // V9D: "-target-feature" "+vis2"
 // V9D: "-target-feature" "+vis3"
+
+// RUN: %clang --target=sparc64-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=VIS-DEFAULT %s
+// RUN: %clang --target=sparc64-freebsd -### -fintegrated-as -c %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=VIS-DEFAULT %s
+// RUN: %clang --target=sparc64-openbsd -### -fintegrated-as -c %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=VIS-DEFAULT %s
+// VIS-DEFAULT: -cc1as
+// VIS-DEFAULT: "-target-feature" "+vis"

@koachan
Copy link
Contributor Author

koachan commented Mar 6, 2025

Pinging @bsdkurt for this too.

@bsdkurt
Copy link

bsdkurt commented Mar 8, 2025

I back ported this to llvm 19 and confirm it works to set VIS by default on OpenBSD. Thanks for the fix.

bob-beck pushed a commit to openbsd/ports that referenced this pull request Mar 10, 2025
SPARC architecture and for setting the default to vis/-Av9a.
Needed for building base and xenocara on sparc64.
llvm/llvm-project#125151
llvm/llvm-project#130108
@brad0
Copy link
Contributor

brad0 commented Mar 11, 2025

@s-barannikov

@koachan
Copy link
Contributor Author

koachan commented Mar 19, 2025

Ping?

@koachan koachan merged commit 3853116 into llvm:main Mar 23, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sparcv9 unsupported argument '-Av9b' to option '-Wa,'
5 participants