[clang] [Driver][Solaris][NFC] A little bit of clean up (PR #69867)
Brad Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 26 19:35:49 PDT 2023
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/69867
>From 813cdfc23027f3b5494115653b458bc1df3ee2f2 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Sun, 22 Oct 2023 00:55:07 -0400
Subject: [PATCH] [Driver][Solaris][NFC] A little bit of clean up
---
clang/lib/Driver/ToolChains/Solaris.cpp | 68 ++++++++++++-------------
1 file changed, 34 insertions(+), 34 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp
index 3d5a710842eca44..c8240e2283f3ff7 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -87,10 +87,12 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {
- const Driver &D = getToolChain().getDriver();
- const bool IsPIE = getPIE(Args, getToolChain());
+ const auto &ToolChain = static_cast<const Solaris &>(getToolChain());
+ const Driver &D = ToolChain.getDriver();
+ const llvm::Triple::ArchType Arch = ToolChain.getArch();
+ const bool IsPIE = getPIE(Args, ToolChain);
+ const bool LinkerIsGnuLd = isLinkerGnuLd(ToolChain, Args);
ArgStringList CmdArgs;
- bool LinkerIsGnuLd = isLinkerGnuLd(getToolChain(), Args);
// Demangle C++ names in errors. GNU ld already defaults to --demangle.
if (!LinkerIsGnuLd)
@@ -126,9 +128,6 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (LinkerIsGnuLd) {
// Set the correct linker emulation for 32- and 64-bit Solaris.
- const auto &ToolChain = static_cast<const Solaris &>(getToolChain());
- const llvm::Triple::ArchType Arch = ToolChain.getArch();
-
switch (Arch) {
case llvm::Triple::x86:
CmdArgs.push_back("-m");
@@ -169,9 +168,9 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_r)) {
if (!Args.hasArg(options::OPT_shared))
CmdArgs.push_back(
- Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
+ Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
- CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
const Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);
bool HaveAnsi = false;
@@ -186,46 +185,46 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// Use values-Xc.o for -ansi, -std=c*, -std=iso9899:199409.
if (HaveAnsi || (LangStd && !LangStd->isGNUMode()))
values_X = "values-Xc.o";
- CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(values_X)));
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(values_X)));
const char *values_xpg = "values-xpg6.o";
// Use values-xpg4.o for -std=c90, -std=gnu90, -std=iso9899:199409.
if (LangStd && LangStd->getLanguage() == Language::C && !LangStd->isC99())
values_xpg = "values-xpg4.o";
CmdArgs.push_back(
- Args.MakeArgString(getToolChain().GetFilePath(values_xpg)));
+ Args.MakeArgString(ToolChain.GetFilePath(values_xpg)));
const char *crtbegin = nullptr;
if (Args.hasArg(options::OPT_shared) || IsPIE)
crtbegin = "crtbeginS.o";
else
crtbegin = "crtbegin.o";
- CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(crtbegin)));
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
// Add crtfastmath.o if available and fast math is enabled.
- getToolChain().addFastMathRuntimeIfAvailable(Args, CmdArgs);
+ ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs);
}
- getToolChain().AddFilePathLibArgs(Args, CmdArgs);
+ ToolChain.AddFilePathLibArgs(Args, CmdArgs);
Args.addAllArgs(CmdArgs,
{options::OPT_L, options::OPT_T_Group, options::OPT_r});
- bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, CmdArgs);
- AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+ bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+ AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
if (D.CCCIsCXX()) {
- if (getToolChain().ShouldLinkCXXStdlib(Args))
- getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
+ if (ToolChain.ShouldLinkCXXStdlib(Args))
+ ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
CmdArgs.push_back("-lm");
}
// Additional linker set-up and flags for Fortran. This is required in order
// to generate executables. As Fortran runtime depends on the C runtime,
// these dependencies need to be listed before the C runtime below.
if (D.IsFlangMode()) {
- addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
- addFortranRuntimeLibs(getToolChain(), CmdArgs);
+ addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
+ addFortranRuntimeLibs(ToolChain, CmdArgs);
CmdArgs.push_back("-lm");
}
if (Args.hasArg(options::OPT_fstack_protector) ||
@@ -237,26 +236,26 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
// LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
// forcibly link with libatomic as a workaround.
- if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
- addAsNeededOption(getToolChain(), Args, CmdArgs, true);
+ if (Arch == llvm::Triple::sparc) {
+ addAsNeededOption(ToolChain, Args, CmdArgs, true);
CmdArgs.push_back("-latomic");
- addAsNeededOption(getToolChain(), Args, CmdArgs, false);
+ addAsNeededOption(ToolChain, Args, CmdArgs, false);
}
- addAsNeededOption(getToolChain(), Args, CmdArgs, true);
+ addAsNeededOption(ToolChain, Args, CmdArgs, true);
CmdArgs.push_back("-lgcc_s");
- addAsNeededOption(getToolChain(), Args, CmdArgs, false);
+ addAsNeededOption(ToolChain, Args, CmdArgs, false);
CmdArgs.push_back("-lc");
if (!Args.hasArg(options::OPT_shared)) {
CmdArgs.push_back("-lgcc");
}
- const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args);
+ const SanitizerArgs &SA = ToolChain.getSanitizerArgs(Args);
if (NeedsSanitizerDeps) {
- linkSanitizerRuntimeDeps(getToolChain(), Args, CmdArgs);
+ linkSanitizerRuntimeDeps(ToolChain, Args, CmdArgs);
// Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
// However, ld -z relax=transtls is available since Solaris 11.2, but not
// in Illumos.
- if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
+ if (Arch == llvm::Triple::x86_64 &&
(SA.needsAsanRt() || SA.needsStatsRt() ||
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime())) &&
!LinkerIsGnuLd) {
@@ -265,7 +264,7 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}
// Avoid AsanInitInternal cycle, Issue #64126.
- if (getToolChain().getTriple().isX86() && SA.needsSharedRt() &&
+ if (ToolChain.getTriple().isX86() && SA.needsSharedRt() &&
SA.needsAsanRt()) {
CmdArgs.push_back("-z");
CmdArgs.push_back("now");
@@ -274,17 +273,18 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
+ const char *crtend = nullptr;
if (Args.hasArg(options::OPT_shared) || IsPIE)
- CmdArgs.push_back(
- Args.MakeArgString(getToolChain().GetFilePath("crtendS.o")));
+ crtend = "crtendS.o";
else
- CmdArgs.push_back(
- Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
+ crtend = "crtend.o";
+ CmdArgs.push_back(
+ Args.MakeArgString(ToolChain.GetFilePath(crtend)));
CmdArgs.push_back(
- Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
+ Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
}
- getToolChain().addProfileRTLibs(Args, CmdArgs);
+ ToolChain.addProfileRTLibs(Args, CmdArgs);
const char *Exec = Args.MakeArgString(getLinkerPath(Args));
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
More information about the cfe-commits
mailing list