|
9 | 9 | #include "Haiku.h"
|
10 | 10 | #include "CommonArgs.h"
|
11 | 11 | #include "clang/Config/config.h"
|
| 12 | +#include "clang/Driver/Compilation.h" |
12 | 13 | #include "llvm/Support/Path.h"
|
13 | 14 |
|
14 | 15 | using namespace clang::driver;
|
| 16 | +using namespace clang::driver::tools; |
15 | 17 | using namespace clang::driver::toolchains;
|
16 | 18 | using namespace clang;
|
17 | 19 | using namespace llvm::opt;
|
18 | 20 |
|
| 21 | +void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA, |
| 22 | + const InputInfo &Output, |
| 23 | + const InputInfoList &Inputs, |
| 24 | + const ArgList &Args, |
| 25 | + const char *LinkingOutput) const { |
| 26 | + const toolchains::Haiku &ToolChain = |
| 27 | + static_cast<const toolchains::Haiku &>(getToolChain()); |
| 28 | + const Driver &D = ToolChain.getDriver(); |
| 29 | + const llvm::Triple::ArchType Arch = ToolChain.getArch(); |
| 30 | + const bool Static = Args.hasArg(options::OPT_static); |
| 31 | + const bool Shared = Args.hasArg(options::OPT_shared); |
| 32 | + ArgStringList CmdArgs; |
| 33 | + |
| 34 | + // Silence warning for "clang -g foo.o -o foo" |
| 35 | + Args.ClaimAllArgs(options::OPT_g_Group); |
| 36 | + // and "clang -emit-llvm foo.o -o foo" |
| 37 | + Args.ClaimAllArgs(options::OPT_emit_llvm); |
| 38 | + // and for "clang -w foo.o -o foo". Other warning options are already |
| 39 | + // handled somewhere else. |
| 40 | + Args.ClaimAllArgs(options::OPT_w); |
| 41 | + |
| 42 | + // Silence warning for "clang -pie foo.o -o foo" |
| 43 | + Args.ClaimAllArgs(options::OPT_pie); |
| 44 | + |
| 45 | + if (!D.SysRoot.empty()) |
| 46 | + CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 47 | + |
| 48 | + CmdArgs.push_back("--eh-frame-hdr"); |
| 49 | + if (Static) { |
| 50 | + CmdArgs.push_back("-Bstatic"); |
| 51 | + } else { |
| 52 | + if (Args.hasArg(options::OPT_rdynamic)) |
| 53 | + CmdArgs.push_back("-export-dynamic"); |
| 54 | + if (Shared) |
| 55 | + CmdArgs.push_back("-shared"); |
| 56 | + CmdArgs.push_back("--enable-new-dtags"); |
| 57 | + } |
| 58 | + |
| 59 | + CmdArgs.push_back("-shared"); |
| 60 | + |
| 61 | + if (!Shared) |
| 62 | + CmdArgs.push_back("--no-undefined"); |
| 63 | + |
| 64 | + if (Arch == llvm::Triple::riscv64) |
| 65 | + CmdArgs.push_back("-X"); |
| 66 | + |
| 67 | + assert((Output.isFilename() || Output.isNothing()) && "Invalid output."); |
| 68 | + if (Output.isFilename()) { |
| 69 | + CmdArgs.push_back("-o"); |
| 70 | + CmdArgs.push_back(Output.getFilename()); |
| 71 | + } |
| 72 | + |
| 73 | + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, |
| 74 | + options::OPT_r)) { |
| 75 | + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); |
| 76 | + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbeginS.o"))); |
| 77 | + if (!Shared) |
| 78 | + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("start_dyn.o"))); |
| 79 | + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("init_term_dyn.o"))); |
| 80 | + } |
| 81 | + |
| 82 | + Args.AddAllArgs(CmdArgs, |
| 83 | + {options::OPT_L, options::OPT_T_Group, options::OPT_s, |
| 84 | + options::OPT_t, options::OPT_Z_Flag, options::OPT_r}); |
| 85 | + ToolChain.AddFilePathLibArgs(Args, CmdArgs); |
| 86 | + |
| 87 | + addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs); |
| 88 | + AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); |
| 89 | + |
| 90 | + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, |
| 91 | + options::OPT_r)) { |
| 92 | + // Use the static OpenMP runtime with -static-openmp |
| 93 | + bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) && !Static; |
| 94 | + addOpenMPRuntime(CmdArgs, ToolChain, Args, StaticOpenMP); |
| 95 | + |
| 96 | + if (D.CCCIsCXX() && ToolChain.ShouldLinkCXXStdlib(Args)) |
| 97 | + ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
| 98 | + |
| 99 | + CmdArgs.push_back("-lgcc"); |
| 100 | + |
| 101 | + CmdArgs.push_back("--push-state"); |
| 102 | + CmdArgs.push_back("--as-needed"); |
| 103 | + CmdArgs.push_back("-lgcc_s"); |
| 104 | + CmdArgs.push_back("--no-as-needed"); |
| 105 | + CmdArgs.push_back("--pop-state"); |
| 106 | + |
| 107 | + CmdArgs.push_back("-lroot"); |
| 108 | + |
| 109 | + CmdArgs.push_back("-lgcc"); |
| 110 | + |
| 111 | + CmdArgs.push_back("--push-state"); |
| 112 | + CmdArgs.push_back("--as-needed"); |
| 113 | + CmdArgs.push_back("-lgcc_s"); |
| 114 | + CmdArgs.push_back("--no-as-needed"); |
| 115 | + CmdArgs.push_back("--pop-state"); |
| 116 | + } |
| 117 | + |
| 118 | + // No need to do anything for pthreads. Claim argument to avoid warning. |
| 119 | + Args.claimAllArgs(options::OPT_pthread, options::OPT_pthreads); |
| 120 | + |
| 121 | + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, |
| 122 | + options::OPT_r)) { |
| 123 | + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); |
| 124 | + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
| 125 | + } |
| 126 | + |
| 127 | + ToolChain.addProfileRTLibs(Args, CmdArgs); |
| 128 | + |
| 129 | + const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); |
| 130 | + C.addCommand(std::make_unique<Command>(JA, *this, |
| 131 | + ResponseFileSupport::AtFileCurCP(), |
| 132 | + Exec, CmdArgs, Inputs, Output)); |
| 133 | +} |
| 134 | + |
19 | 135 | /// Haiku - Haiku tool chain which can call as(1) and ld(1) directly.
|
20 | 136 |
|
21 | 137 | Haiku::Haiku(const Driver &D, const llvm::Triple& Triple, const ArgList &Args)
|
22 | 138 | : Generic_ELF(D, Triple, Args) {
|
23 | 139 |
|
| 140 | + GCCInstallation.init(Triple, Args); |
| 141 | + |
24 | 142 | getFilePaths().push_back(concat(getDriver().SysRoot, "/boot/system/lib"));
|
25 | 143 | getFilePaths().push_back(concat(getDriver().SysRoot, "/boot/system/develop/lib"));
|
| 144 | + |
| 145 | + if (GCCInstallation.isValid()) |
| 146 | + getFilePaths().push_back(GCCInstallation.getInstallPath().str()); |
26 | 147 | }
|
27 | 148 |
|
28 | 149 | void Haiku::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
|
@@ -128,8 +249,6 @@ void Haiku::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
|
128 | 249 | concat(getDriver().SysRoot, "/boot/system/develop/headers/c++/v1"));
|
129 | 250 | }
|
130 | 251 |
|
131 |
| -void Haiku::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
132 |
| - llvm::opt::ArgStringList &CC1Args) const { |
133 |
| - addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/boot/system/develop/headers/c++"), |
134 |
| - getTriple().str(), "", DriverArgs, CC1Args); |
135 |
| -} |
| 252 | +Tool *Haiku::buildLinker() const { return new tools::haiku::Linker(*this); } |
| 253 | + |
| 254 | +bool Haiku::HasNativeLLVMSupport() const { return true; } |
0 commit comments