clang  12.0.0git
Minix.cpp
Go to the documentation of this file.
1 //===--- Minix.cpp - Minix ToolChain Implementations ------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "Minix.h"
10 #include "CommonArgs.h"
11 #include "InputInfo.h"
13 #include "clang/Driver/Driver.h"
14 #include "clang/Driver/Options.h"
15 #include "llvm/Option/ArgList.h"
16 #include "llvm/Support/VirtualFileSystem.h"
17 
18 using namespace clang::driver;
19 using namespace clang;
20 using namespace llvm::opt;
21 
23  const InputInfo &Output,
24  const InputInfoList &Inputs,
25  const ArgList &Args,
26  const char *LinkingOutput) const {
27  claimNoWarnArgs(Args);
28  ArgStringList CmdArgs;
29 
30  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
31 
32  CmdArgs.push_back("-o");
33  CmdArgs.push_back(Output.getFilename());
34 
35  for (const auto &II : Inputs)
36  CmdArgs.push_back(II.getFilename());
37 
38  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
39  C.addCommand(std::make_unique<Command>(JA, *this,
41  Exec, CmdArgs, Inputs, Output));
42 }
43 
45  const InputInfo &Output,
46  const InputInfoList &Inputs,
47  const ArgList &Args,
48  const char *LinkingOutput) const {
49  const Driver &D = getToolChain().getDriver();
50  ArgStringList CmdArgs;
51 
52  if (Output.isFilename()) {
53  CmdArgs.push_back("-o");
54  CmdArgs.push_back(Output.getFilename());
55  } else {
56  assert(Output.isNothing() && "Invalid output.");
57  }
58 
59  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
60  CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
61  CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
62  CmdArgs.push_back(
63  Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
64  CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
65  }
66 
67  Args.AddAllArgs(CmdArgs,
68  {options::OPT_L, options::OPT_T_Group, options::OPT_e});
69 
70  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
71 
72  getToolChain().addProfileRTLibs(Args, CmdArgs);
73 
74  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
75  if (D.CCCIsCXX()) {
76  if (getToolChain().ShouldLinkCXXStdlib(Args))
77  getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
78  CmdArgs.push_back("-lm");
79  }
80  }
81 
82  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
83  if (Args.hasArg(options::OPT_pthread))
84  CmdArgs.push_back("-lpthread");
85  CmdArgs.push_back("-lc");
86  CmdArgs.push_back("-lCompilerRT-Generic");
87  CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib");
88  CmdArgs.push_back(
89  Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
90  }
91 
92  const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
93  C.addCommand(std::make_unique<Command>(JA, *this,
95  Exec, CmdArgs, Inputs, Output));
96 }
97 
98 /// Minix - Minix tool chain which can call as(1) and ld(1) directly.
99 
100 toolchains::Minix::Minix(const Driver &D, const llvm::Triple &Triple,
101  const ArgList &Args)
102  : Generic_ELF(D, Triple, Args) {
103  getFilePaths().push_back(getDriver().Dir + "/../lib");
104  getFilePaths().push_back("/usr/lib");
105 }
106 
108  return new tools::minix::Assembler(*this);
109 }
110 
112  return new tools::minix::Linker(*this);
113 }
Tool * buildAssembler() const override
Definition: Minix.cpp:107
const char * getFilename() const
Definition: InputInfo.h:83
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
path_list & getFilePaths()
Definition: ToolChain.h:243
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
Tool * buildLinker() const override
Definition: Minix.cpp:111
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: Minix.cpp:44
const Driver & getDriver() const
Definition: ToolChain.h:205
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:173
Dataflow Directional Tag Classes.
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: Minix.cpp:22
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Minix(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Minix - Minix tool chain which can call as(1) and ld(1) directly.
Definition: Minix.cpp:100
bool isNothing() const
Definition: InputInfo.h:74
static constexpr ResponseFileSupport AtFileCurCP()
Definition: Job.h:91
bool isFilename() const
Definition: InputInfo.h:75