[clang] [Driver] Always use gas with -fno-integrated-as on Solaris (PR #65489)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 6 07:43:44 PDT 2023
https://github.com/rorth created https://github.com/llvm/llvm-project/pull/65489:
`clang -fno-integrated-as` doesn't currently work on Solaris: it doesn't even select between 32 and 64-bit objects. Besides, Solaris has both the native assembler (`/usr/bin/as`) and the GNU assembler (`/usr/bin/gas` resp. `/usr/gnu/bin/as`). The native sparc and x86 assemblers aren't compatible with `clang`'s assembler syntax to varying degrees, and the command line options for `as` and `gas` are completely different.
Therefore this patch chooses to always use `gas` on Solaris, using `gnutools::Assembler::ConstructJob` to pass the correct options.
Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and `x86_64-pc-linux-gnu`.
>From b867ca65e585427a6d02c245d90797a08f6dfc8e Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at CeBiTec.Uni-Bielefeld.DE>
Date: Wed, 6 Sep 2023 16:35:27 +0200
Subject: [PATCH] [Driver] Always use gas with -fno-integrated-as on Solaris
`clang -fno-integrated-as` doesn't currently work on Solaris: it doesn't
even select between 32 or 64-bit objects. Besides, Solaris has both the
native assembler (`/usr/bin/as`) and the GNU assembler (`/usr/bin/gas`
resp. `/usr/gnu/bin/as`). The native sparc and x86 assemblers aren't
compatible with `clang`'s assembler syntax to varying degrees, and the
command line options for `as` and `gas` are completely different.
Therefore this patch chooses to always use `gas` on Solaris, using
`gnutools::Assembler::ConstructJob` to pass the correct options.
Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
clang/lib/Driver/ToolChains/Gnu.cpp | 4 ++++
clang/lib/Driver/ToolChains/Solaris.cpp | 17 +++--------------
clang/lib/Driver/ToolChains/Solaris.h | 5 ++---
clang/test/Driver/solaris-as.c | 11 +++++++++++
4 files changed, 20 insertions(+), 17 deletions(-)
create mode 100644 clang/test/Driver/solaris-as.c
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index d215dd77921778..7aeb8e29ebc557 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -700,6 +700,10 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
unsigned PICLevel;
bool IsPIE;
const char *DefaultAssembler = "as";
+ // Enforce GNU as on Solaris; the native assembler's input syntax isn't fully
+ // compatible.
+ if (getToolChain().getTriple().isOSSolaris())
+ DefaultAssembler = "gas";
std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(getToolChain(), Args);
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp
index a22e4c2e47b87e..30b79b4d90e011 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -8,6 +8,7 @@
#include "Solaris.h"
#include "CommonArgs.h"
+#include "Gnu.h"
#include "clang/Basic/LangStandard.h"
#include "clang/Config/config.h"
#include "clang/Driver/Compilation.h"
@@ -32,20 +33,8 @@ void solaris::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {
- claimNoWarnArgs(Args);
- ArgStringList CmdArgs;
-
- Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
-
- CmdArgs.push_back("-o");
- CmdArgs.push_back(Output.getFilename());
-
- for (const auto &II : Inputs)
- CmdArgs.push_back(II.getFilename());
-
- const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
- C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
- Exec, CmdArgs, Inputs, Output));
+ // Just call the Gnu version, which enforces gas on Solaris.
+ gnutools::Assembler::ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput);
}
bool solaris::isLinkerGnuLd(const ToolChain &TC, const ArgList &Args) {
diff --git a/clang/lib/Driver/ToolChains/Solaris.h b/clang/lib/Driver/ToolChains/Solaris.h
index fe3e7f3a1f1b99..04b68c5053caa6 100644
--- a/clang/lib/Driver/ToolChains/Solaris.h
+++ b/clang/lib/Driver/ToolChains/Solaris.h
@@ -19,10 +19,9 @@ namespace tools {
/// solaris -- Directly call Solaris assembler and linker
namespace solaris {
-class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
+class LLVM_LIBRARY_VISIBILITY Assembler : public gnutools::Assembler {
public:
- Assembler(const ToolChain &TC)
- : Tool("solaris::Assembler", "assembler", TC) {}
+ Assembler(const ToolChain &TC) : gnutools::Assembler(TC) {}
bool hasIntegratedCPP() const override { return false; }
diff --git a/clang/test/Driver/solaris-as.c b/clang/test/Driver/solaris-as.c
new file mode 100644
index 00000000000000..bf06dd97cc3862
--- /dev/null
+++ b/clang/test/Driver/solaris-as.c
@@ -0,0 +1,11 @@
+/// General tests for assembler invocations on Solaris.
+
+/// Test that clang uses gas on Solaris.
+// RUN: %clang -x assembler %s -### -c -fno-integrated-as \
+// RUN: --target=sparc-sun-solaris2.11 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-GAS %s
+// RUN: %clang -x assembler %s -### -c -fno-integrated-as \
+// RUN: --target=sparc-sun-solaris2.11 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-GAS %s
+/// Allow for both "/usr/bin/gas" (native) and "gas" (cross) forms.
+// CHECK-GAS: gas"
More information about the cfe-commits
mailing list