David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 1 | //===--- Minix.cpp - Minix ToolChain Implementations ------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "Minix.h" |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 10 | #include "CommonArgs.h" |
Jonas Devlieghere | fc51490 | 2018-10-10 13:27:25 +0000 | [diff] [blame] | 11 | #include "InputInfo.h" |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Compilation.h" |
| 13 | #include "clang/Driver/Driver.h" |
| 14 | #include "clang/Driver/Options.h" |
| 15 | #include "llvm/Option/ArgList.h" |
Jonas Devlieghere | fc51490 | 2018-10-10 13:27:25 +0000 | [diff] [blame] | 16 | #include "llvm/Support/VirtualFileSystem.h" |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace clang::driver; |
| 19 | using namespace clang; |
| 20 | using namespace llvm::opt; |
| 21 | |
| 22 | void tools::minix::Assembler::ConstructJob(Compilation &C, const JobAction &JA, |
| 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")); |
Jonas Devlieghere | 2b3d49b | 2019-08-14 23:04:18 +0000 | [diff] [blame] | 39 | C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void tools::minix::Linker::ConstructJob(Compilation &C, const JobAction &JA, |
| 43 | const InputInfo &Output, |
| 44 | const InputInfoList &Inputs, |
| 45 | const ArgList &Args, |
| 46 | const char *LinkingOutput) const { |
| 47 | const Driver &D = getToolChain().getDriver(); |
| 48 | ArgStringList CmdArgs; |
| 49 | |
| 50 | if (Output.isFilename()) { |
| 51 | CmdArgs.push_back("-o"); |
| 52 | CmdArgs.push_back(Output.getFilename()); |
| 53 | } else { |
| 54 | assert(Output.isNothing() && "Invalid output."); |
| 55 | } |
| 56 | |
| 57 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { |
| 58 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o"))); |
| 59 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); |
| 60 | CmdArgs.push_back( |
| 61 | Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); |
| 62 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); |
| 63 | } |
| 64 | |
| 65 | Args.AddAllArgs(CmdArgs, |
| 66 | {options::OPT_L, options::OPT_T_Group, options::OPT_e}); |
| 67 | |
| 68 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); |
| 69 | |
| 70 | getToolChain().addProfileRTLibs(Args, CmdArgs); |
| 71 | |
| 72 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { |
| 73 | if (D.CCCIsCXX()) { |
Nico Weber | 0ee47d9 | 2017-07-25 18:02:57 +0000 | [diff] [blame] | 74 | if (getToolChain().ShouldLinkCXXStdlib(Args)) |
| 75 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 76 | CmdArgs.push_back("-lm"); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { |
| 81 | if (Args.hasArg(options::OPT_pthread)) |
| 82 | CmdArgs.push_back("-lpthread"); |
| 83 | CmdArgs.push_back("-lc"); |
| 84 | CmdArgs.push_back("-lCompilerRT-Generic"); |
| 85 | CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib"); |
| 86 | CmdArgs.push_back( |
| 87 | Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); |
| 88 | } |
| 89 | |
| 90 | const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); |
Jonas Devlieghere | 2b3d49b | 2019-08-14 23:04:18 +0000 | [diff] [blame] | 91 | C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /// Minix - Minix tool chain which can call as(1) and ld(1) directly. |
| 95 | |
| 96 | toolchains::Minix::Minix(const Driver &D, const llvm::Triple &Triple, |
| 97 | const ArgList &Args) |
| 98 | : Generic_ELF(D, Triple, Args) { |
| 99 | getFilePaths().push_back(getDriver().Dir + "/../lib"); |
| 100 | getFilePaths().push_back("/usr/lib"); |
| 101 | } |
| 102 | |
| 103 | Tool *toolchains::Minix::buildAssembler() const { |
| 104 | return new tools::minix::Assembler(*this); |
| 105 | } |
| 106 | |
| 107 | Tool *toolchains::Minix::buildLinker() const { |
| 108 | return new tools::minix::Linker(*this); |
| 109 | } |