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" 12 #include "clang/Driver/Compilation.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 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")); 39 C.addCommand(std::make_unique<Command>( 40 JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); 41 } 42 43 void tools::minix::Linker::ConstructJob(Compilation &C, const JobAction &JA, 44 const InputInfo &Output, 45 const InputInfoList &Inputs, 46 const ArgList &Args, 47 const char *LinkingOutput) const { 48 const Driver &D = getToolChain().getDriver(); 49 ArgStringList CmdArgs; 50 51 if (Output.isFilename()) { 52 CmdArgs.push_back("-o"); 53 CmdArgs.push_back(Output.getFilename()); 54 } else { 55 assert(Output.isNothing() && "Invalid output."); 56 } 57 58 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { 59 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o"))); 60 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); 61 CmdArgs.push_back( 62 Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); 63 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); 64 } 65 66 Args.AddAllArgs(CmdArgs, 67 {options::OPT_L, options::OPT_T_Group, options::OPT_e}); 68 69 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); 70 71 getToolChain().addProfileRTLibs(Args, CmdArgs); 72 73 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { 74 if (D.CCCIsCXX()) { 75 if (getToolChain().ShouldLinkCXXStdlib(Args)) 76 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); 77 CmdArgs.push_back("-lm"); 78 } 79 } 80 81 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { 82 if (Args.hasArg(options::OPT_pthread)) 83 CmdArgs.push_back("-lpthread"); 84 CmdArgs.push_back("-lc"); 85 CmdArgs.push_back("-lCompilerRT-Generic"); 86 CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib"); 87 CmdArgs.push_back( 88 Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); 89 } 90 91 const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); 92 C.addCommand(std::make_unique<Command>( 93 JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); 94 } 95 96 /// Minix - Minix tool chain which can call as(1) and ld(1) directly. 97 98 toolchains::Minix::Minix(const Driver &D, const llvm::Triple &Triple, 99 const ArgList &Args) 100 : Generic_ELF(D, Triple, Args) { 101 getFilePaths().push_back(getDriver().Dir + "/../lib"); 102 getFilePaths().push_back("/usr/lib"); 103 } 104 105 Tool *toolchains::Minix::buildAssembler() const { 106 return new tools::minix::Assembler(*this); 107 } 108 109 Tool *toolchains::Minix::buildLinker() const { 110 return new tools::minix::Linker(*this); 111 } 112