[clang] 09b02f5 - [Driver][NetBSD][NFC] Some cleaning up
Brad Smith via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 21 01:47:21 PDT 2023
Author: Brad Smith
Date: 2023-10-21T04:45:41-04:00
New Revision: 09b02f5d569adbbb29186479953cd55bd6b29402
URL: https://github.com/llvm/llvm-project/commit/09b02f5d569adbbb29186479953cd55bd6b29402
DIFF: https://github.com/llvm/llvm-project/commit/09b02f5d569adbbb29186479953cd55bd6b29402.diff
LOG: [Driver][NetBSD][NFC] Some cleaning up
Added:
Modified:
clang/lib/Driver/ToolChains/NetBSD.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 1c901f70f72ca2e..e643bdf8bcbedb5 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -30,13 +30,12 @@ void netbsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {
- const toolchains::NetBSD &ToolChain =
- static_cast<const toolchains::NetBSD &>(getToolChain());
+ const auto &ToolChain = static_cast<const NetBSD &>(getToolChain());
const Driver &D = ToolChain.getDriver();
const llvm::Triple &Triple = ToolChain.getTriple();
+ ArgStringList CmdArgs;
claimNoWarnArgs(Args);
- ArgStringList CmdArgs;
// GNU as needs
diff erent flags for creating the correct output format
// on architectures with
diff erent ABIs or optional feature sets.
@@ -118,27 +117,29 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {
- const toolchains::NetBSD &ToolChain =
- static_cast<const toolchains::NetBSD &>(getToolChain());
+ const auto &ToolChain = static_cast<const NetBSD &>(getToolChain());
const Driver &D = ToolChain.getDriver();
const llvm::Triple &Triple = ToolChain.getTriple();
-
+ const llvm::Triple::ArchType Arch = ToolChain.getArch();
+ const bool Static = Args.hasArg(options::OPT_static);
+ const bool Shared = Args.hasArg(options::OPT_shared);
+ const bool Pie = Args.hasArg(options::OPT_pie);
ArgStringList CmdArgs;
if (!D.SysRoot.empty())
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
CmdArgs.push_back("--eh-frame-hdr");
- if (Args.hasArg(options::OPT_static)) {
+ if (Static) {
CmdArgs.push_back("-Bstatic");
- if (Args.hasArg(options::OPT_pie)) {
+ if (Pie) {
Args.AddAllArgs(CmdArgs, options::OPT_pie);
CmdArgs.push_back("--no-dynamic-linker");
}
} else {
if (Args.hasArg(options::OPT_rdynamic))
CmdArgs.push_back("-export-dynamic");
- if (Args.hasArg(options::OPT_shared)) {
+ if (Shared) {
CmdArgs.push_back("-shared");
} else if (!Args.hasArg(options::OPT_r)) {
Args.AddAllArgs(CmdArgs, options::OPT_pie);
@@ -149,7 +150,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// Many NetBSD architectures support more than one ABI.
// Determine the correct emulation for ld.
- switch (ToolChain.getArch()) {
+ switch (Arch) {
case llvm::Triple::x86:
CmdArgs.push_back("-m");
CmdArgs.push_back("elf_i386");
@@ -193,13 +194,13 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
case llvm::Triple::mips64el:
if (mips::hasMipsAbiArg(Args, "32")) {
CmdArgs.push_back("-m");
- if (ToolChain.getArch() == llvm::Triple::mips64)
+ if (Arch == llvm::Triple::mips64)
CmdArgs.push_back("elf32btsmip");
else
CmdArgs.push_back("elf32ltsmip");
} else if (mips::hasMipsAbiArg(Args, "64")) {
CmdArgs.push_back("-m");
- if (ToolChain.getArch() == llvm::Triple::mips64)
+ if (Arch == llvm::Triple::mips64)
CmdArgs.push_back("elf64btsmip");
else
CmdArgs.push_back("elf64ltsmip");
@@ -251,19 +252,20 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
- if (!Args.hasArg(options::OPT_shared)) {
- CmdArgs.push_back(
- Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
- }
- CmdArgs.push_back(
- Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
- if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) {
- CmdArgs.push_back(
- Args.MakeArgString(ToolChain.GetFilePath("crtbeginS.o")));
- } else {
- CmdArgs.push_back(
- Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o")));
- }
+ const char *crt0 = nullptr;
+ const char *crtbegin = nullptr;
+ if (!Shared)
+ crt0 = "crt0.o";
+
+ if (Shared || Pie)
+ crtbegin = "crtbeginS.o";
+ else
+ crtbegin = "crtbegin.o";
+
+ if (crt0)
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt0)));
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
}
Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
@@ -305,8 +307,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
// Use the static OpenMP runtime with -static-openmp
- bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
- !Args.hasArg(options::OPT_static);
+ bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) && !Static;
addOpenMPRuntime(CmdArgs, ToolChain, Args, StaticOpenMP);
if (D.CCCIsCXX()) {
@@ -323,7 +324,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-lc");
if (useLibgcc) {
- if (Args.hasArg(options::OPT_static)) {
+ if (Static) {
// libgcc_eh depends on libc, so resolve as much as possible,
// pull in any new requirements from libc and then get the rest
// of libgcc.
@@ -341,12 +342,13 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
- if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
- CmdArgs.push_back(
- Args.MakeArgString(ToolChain.GetFilePath("crtendS.o")));
+ const char *crtend = nullptr;
+ if (Shared || Pie)
+ crtend = "crtendS.o";
else
- CmdArgs.push_back(
- Args.MakeArgString(ToolChain.GetFilePath("crtend.o")));
+ crtend = "crtend.o";
+
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend)));
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
}
More information about the cfe-commits
mailing list