Minix.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #include "Minix.h"
  9. #include "CommonArgs.h"
  10. #include "clang/Driver/Compilation.h"
  11. #include "clang/Driver/Driver.h"
  12. #include "clang/Driver/InputInfo.h"
  13. #include "clang/Driver/Options.h"
  14. #include "llvm/Option/ArgList.h"
  15. #include "llvm/Support/VirtualFileSystem.h"
  16. using namespace clang::driver;
  17. using namespace clang;
  18. using namespace llvm::opt;
  19. void tools::minix::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
  20. const InputInfo &Output,
  21. const InputInfoList &Inputs,
  22. const ArgList &Args,
  23. const char *LinkingOutput) const {
  24. claimNoWarnArgs(Args);
  25. ArgStringList CmdArgs;
  26. Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
  27. CmdArgs.push_back("-o");
  28. CmdArgs.push_back(Output.getFilename());
  29. for (const auto &II : Inputs)
  30. CmdArgs.push_back(II.getFilename());
  31. const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
  32. C.addCommand(std::make_unique<Command>(JA, *this,
  33. ResponseFileSupport::AtFileCurCP(),
  34. Exec, CmdArgs, Inputs, Output));
  35. }
  36. void tools::minix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
  37. const InputInfo &Output,
  38. const InputInfoList &Inputs,
  39. const ArgList &Args,
  40. const char *LinkingOutput) const {
  41. const Driver &D = getToolChain().getDriver();
  42. ArgStringList CmdArgs;
  43. if (Output.isFilename()) {
  44. CmdArgs.push_back("-o");
  45. CmdArgs.push_back(Output.getFilename());
  46. } else {
  47. assert(Output.isNothing() && "Invalid output.");
  48. }
  49. if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
  50. CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
  51. CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
  52. CmdArgs.push_back(
  53. Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
  54. CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
  55. }
  56. Args.AddAllArgs(CmdArgs,
  57. {options::OPT_L, options::OPT_T_Group, options::OPT_e});
  58. AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
  59. getToolChain().addProfileRTLibs(Args, CmdArgs);
  60. if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
  61. if (D.CCCIsCXX()) {
  62. if (getToolChain().ShouldLinkCXXStdlib(Args))
  63. getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
  64. CmdArgs.push_back("-lm");
  65. }
  66. }
  67. if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
  68. if (Args.hasArg(options::OPT_pthread))
  69. CmdArgs.push_back("-lpthread");
  70. CmdArgs.push_back("-lc");
  71. CmdArgs.push_back("-lCompilerRT-Generic");
  72. CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib");
  73. CmdArgs.push_back(
  74. Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
  75. }
  76. const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
  77. C.addCommand(std::make_unique<Command>(JA, *this,
  78. ResponseFileSupport::AtFileCurCP(),
  79. Exec, CmdArgs, Inputs, Output));
  80. }
  81. /// Minix - Minix tool chain which can call as(1) and ld(1) directly.
  82. toolchains::Minix::Minix(const Driver &D, const llvm::Triple &Triple,
  83. const ArgList &Args)
  84. : Generic_ELF(D, Triple, Args) {
  85. getFilePaths().push_back(getDriver().Dir + "/../lib");
  86. getFilePaths().push_back("/usr/lib");
  87. }
  88. Tool *toolchains::Minix::buildAssembler() const {
  89. return new tools::minix::Assembler(*this);
  90. }
  91. Tool *toolchains::Minix::buildLinker() const {
  92. return new tools::minix::Linker(*this);
  93. }