1 //===--- Minix.cpp - Minix ToolChain Implementations ------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include "CommonArgs.h"
11 #include "clang/Driver/Compilation.h"
12 #include "clang/Driver/Driver.h"
13 #include "clang/Driver/InputInfo.h"
14 #include "clang/Driver/Options.h"
15 #include "llvm/Option/ArgList.h"
16 #include "llvm/Support/VirtualFileSystem.h"
18 using namespace clang::driver
;
19 using namespace clang
;
20 using namespace llvm::opt
;
22 void tools::minix::Assembler::ConstructJob(Compilation
&C
, const JobAction
&JA
,
23 const InputInfo
&Output
,
24 const InputInfoList
&Inputs
,
26 const char *LinkingOutput
) const {
27 claimNoWarnArgs(Args
);
28 ArgStringList CmdArgs
;
30 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
, options::OPT_Xassembler
);
32 CmdArgs
.push_back("-o");
33 CmdArgs
.push_back(Output
.getFilename());
35 for (const auto &II
: Inputs
)
36 CmdArgs
.push_back(II
.getFilename());
38 const char *Exec
= Args
.MakeArgString(getToolChain().GetProgramPath("as"));
39 C
.addCommand(std::make_unique
<Command
>(JA
, *this,
40 ResponseFileSupport::AtFileCurCP(),
41 Exec
, CmdArgs
, Inputs
, Output
));
44 void tools::minix::Linker::ConstructJob(Compilation
&C
, const JobAction
&JA
,
45 const InputInfo
&Output
,
46 const InputInfoList
&Inputs
,
48 const char *LinkingOutput
) const {
49 const Driver
&D
= getToolChain().getDriver();
50 ArgStringList CmdArgs
;
52 if (Output
.isFilename()) {
53 CmdArgs
.push_back("-o");
54 CmdArgs
.push_back(Output
.getFilename());
56 assert(Output
.isNothing() && "Invalid output.");
59 if (!Args
.hasArg(options::OPT_nostdlib
, options::OPT_nostartfiles
,
61 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath("crt1.o")));
62 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
64 Args
.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
65 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath("crtn.o")));
68 Args
.AddAllArgs(CmdArgs
,
69 {options::OPT_L
, options::OPT_T_Group
, options::OPT_e
});
71 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
, JA
);
73 getToolChain().addProfileRTLibs(Args
, CmdArgs
);
75 if (!Args
.hasArg(options::OPT_nostdlib
, options::OPT_nodefaultlibs
,
78 if (getToolChain().ShouldLinkCXXStdlib(Args
))
79 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
80 CmdArgs
.push_back("-lm");
84 if (!Args
.hasArg(options::OPT_nostdlib
, options::OPT_nostartfiles
,
86 if (Args
.hasArg(options::OPT_pthread
))
87 CmdArgs
.push_back("-lpthread");
88 CmdArgs
.push_back("-lc");
89 CmdArgs
.push_back("-lCompilerRT-Generic");
90 CmdArgs
.push_back("-L/usr/pkg/compiler-rt/lib");
92 Args
.MakeArgString(getToolChain().GetFilePath("crtend.o")));
95 const char *Exec
= Args
.MakeArgString(getToolChain().GetLinkerPath());
96 C
.addCommand(std::make_unique
<Command
>(JA
, *this,
97 ResponseFileSupport::AtFileCurCP(),
98 Exec
, CmdArgs
, Inputs
, Output
));
101 /// Minix - Minix tool chain which can call as(1) and ld(1) directly.
103 toolchains::Minix::Minix(const Driver
&D
, const llvm::Triple
&Triple
,
105 : Generic_ELF(D
, Triple
, Args
) {
106 getFilePaths().push_back(getDriver().Dir
+ "/../lib");
107 getFilePaths().push_back("/usr/lib");
110 Tool
*toolchains::Minix::buildAssembler() const {
111 return new tools::minix::Assembler(*this);
114 Tool
*toolchains::Minix::buildLinker() const {
115 return new tools::minix::Linker(*this);