/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/Haiku.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- Haiku.cpp - Haiku 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 "Haiku.h" |
10 | | #include "CommonArgs.h" |
11 | | #include "clang/Config/config.h" |
12 | | #include "clang/Driver/Compilation.h" |
13 | | #include "llvm/Support/Path.h" |
14 | | |
15 | | using namespace clang::driver; |
16 | | using namespace clang::driver::tools; |
17 | | using namespace clang::driver::toolchains; |
18 | | using namespace clang; |
19 | | using namespace llvm::opt; |
20 | | |
21 | | void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA, |
22 | | const InputInfo &Output, |
23 | | const InputInfoList &Inputs, |
24 | | const ArgList &Args, |
25 | 8 | const char *LinkingOutput) const { |
26 | 8 | const auto &ToolChain = static_cast<const Haiku &>(getToolChain()); |
27 | 8 | const Driver &D = ToolChain.getDriver(); |
28 | 8 | const llvm::Triple::ArchType Arch = ToolChain.getArch(); |
29 | 8 | const bool Static = Args.hasArg(options::OPT_static); |
30 | 8 | const bool Shared = Args.hasArg(options::OPT_shared); |
31 | 8 | ArgStringList CmdArgs; |
32 | | |
33 | | // Silence warning for "clang -g foo.o -o foo" |
34 | 8 | Args.ClaimAllArgs(options::OPT_g_Group); |
35 | | // and "clang -emit-llvm foo.o -o foo" |
36 | 8 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
37 | | // and for "clang -w foo.o -o foo". Other warning options are already |
38 | | // handled somewhere else. |
39 | 8 | Args.ClaimAllArgs(options::OPT_w); |
40 | | |
41 | | // Silence warning for "clang -pie foo.o -o foo" |
42 | 8 | Args.ClaimAllArgs(options::OPT_pie); |
43 | | |
44 | | // -rdynamic is a no-op with Haiku. Claim argument to avoid warning. |
45 | 8 | Args.ClaimAllArgs(options::OPT_rdynamic); |
46 | | |
47 | 8 | if (!D.SysRoot.empty()) |
48 | 4 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
49 | | |
50 | 8 | CmdArgs.push_back("--eh-frame-hdr"); |
51 | 8 | if (Static) { |
52 | 0 | CmdArgs.push_back("-Bstatic"); |
53 | 8 | } else { |
54 | 8 | if (Shared) |
55 | 1 | CmdArgs.push_back("-shared"); |
56 | 8 | CmdArgs.push_back("--enable-new-dtags"); |
57 | 8 | } |
58 | | |
59 | 8 | CmdArgs.push_back("-shared"); |
60 | | |
61 | 8 | if (!Shared) |
62 | 7 | CmdArgs.push_back("--no-undefined"); |
63 | | |
64 | 8 | if (Arch == llvm::Triple::riscv64) |
65 | 0 | CmdArgs.push_back("-X"); |
66 | | |
67 | 8 | assert((Output.isFilename() || Output.isNothing()) && "Invalid output."); |
68 | 8 | if (Output.isFilename()) { |
69 | 8 | CmdArgs.push_back("-o"); |
70 | 8 | CmdArgs.push_back(Output.getFilename()); |
71 | 8 | } |
72 | | |
73 | 8 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, |
74 | 8 | options::OPT_r)) { |
75 | 8 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); |
76 | 8 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbeginS.o"))); |
77 | 8 | if (!Shared) |
78 | 7 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("start_dyn.o"))); |
79 | 8 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("init_term_dyn.o"))); |
80 | 8 | } |
81 | | |
82 | 8 | Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, |
83 | 8 | options::OPT_s, options::OPT_t, options::OPT_r}); |
84 | 8 | ToolChain.AddFilePathLibArgs(Args, CmdArgs); |
85 | | |
86 | 8 | addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs); |
87 | 8 | AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); |
88 | | |
89 | 8 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, |
90 | 8 | options::OPT_r)) { |
91 | | // Use the static OpenMP runtime with -static-openmp |
92 | 8 | bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) && !Static0 ; |
93 | 8 | addOpenMPRuntime(CmdArgs, ToolChain, Args, StaticOpenMP); |
94 | | |
95 | 8 | if (D.CCCIsCXX() && ToolChain.ShouldLinkCXXStdlib(Args)2 ) |
96 | 2 | ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
97 | | |
98 | | // Silence warnings when linking C code with a C++ '-stdlib' argument. |
99 | 8 | Args.ClaimAllArgs(options::OPT_stdlib_EQ); |
100 | | |
101 | | // Additional linker set-up and flags for Fortran. This is required in order |
102 | | // to generate executables. As Fortran runtime depends on the C runtime, |
103 | | // these dependencies need to be listed before the C runtime below (i.e. |
104 | | // AddRunTimeLibs). |
105 | 8 | if (D.IsFlangMode()) { |
106 | 0 | addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs); |
107 | 0 | addFortranRuntimeLibs(ToolChain, Args, CmdArgs); |
108 | 0 | } |
109 | | |
110 | 8 | CmdArgs.push_back("-lgcc"); |
111 | | |
112 | 8 | CmdArgs.push_back("--push-state"); |
113 | 8 | CmdArgs.push_back("--as-needed"); |
114 | 8 | CmdArgs.push_back("-lgcc_s"); |
115 | 8 | CmdArgs.push_back("--no-as-needed"); |
116 | 8 | CmdArgs.push_back("--pop-state"); |
117 | | |
118 | 8 | CmdArgs.push_back("-lroot"); |
119 | | |
120 | 8 | CmdArgs.push_back("-lgcc"); |
121 | | |
122 | 8 | CmdArgs.push_back("--push-state"); |
123 | 8 | CmdArgs.push_back("--as-needed"); |
124 | 8 | CmdArgs.push_back("-lgcc_s"); |
125 | 8 | CmdArgs.push_back("--no-as-needed"); |
126 | 8 | CmdArgs.push_back("--pop-state"); |
127 | 8 | } |
128 | | |
129 | | // No need to do anything for pthreads. Claim argument to avoid warning. |
130 | 8 | Args.claimAllArgs(options::OPT_pthread, options::OPT_pthreads); |
131 | | |
132 | 8 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, |
133 | 8 | options::OPT_r)) { |
134 | 8 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); |
135 | 8 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
136 | 8 | } |
137 | | |
138 | 8 | ToolChain.addProfileRTLibs(Args, CmdArgs); |
139 | | |
140 | 8 | const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); |
141 | 8 | C.addCommand(std::make_unique<Command>(JA, *this, |
142 | 8 | ResponseFileSupport::AtFileCurCP(), |
143 | 8 | Exec, CmdArgs, Inputs, Output)); |
144 | 8 | } |
145 | | |
146 | | /// Haiku - Haiku tool chain which can call as(1) and ld(1) directly. |
147 | | |
148 | | Haiku::Haiku(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |
149 | 15 | : Generic_ELF(D, Triple, Args) { |
150 | | |
151 | 15 | GCCInstallation.init(Triple, Args); |
152 | | |
153 | 15 | getFilePaths().push_back(concat(getDriver().SysRoot, "/boot/system/lib")); |
154 | 15 | getFilePaths().push_back(concat(getDriver().SysRoot, "/boot/system/develop/lib")); |
155 | | |
156 | 15 | if (GCCInstallation.isValid()) |
157 | 4 | getFilePaths().push_back(GCCInstallation.getInstallPath().str()); |
158 | 15 | } |
159 | | |
160 | | void Haiku::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, |
161 | 15 | llvm::opt::ArgStringList &CC1Args) const { |
162 | 15 | const Driver &D = getDriver(); |
163 | | |
164 | 15 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
165 | 0 | return; |
166 | | |
167 | 15 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
168 | 15 | SmallString<128> Dir(D.ResourceDir); |
169 | 15 | llvm::sys::path::append(Dir, "include"); |
170 | 15 | addSystemInclude(DriverArgs, CC1Args, Dir.str()); |
171 | 15 | } |
172 | | |
173 | 15 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
174 | 0 | return; |
175 | | |
176 | | // Add dirs specified via 'configure --with-c-include-dirs'. |
177 | 15 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
178 | 15 | if (!CIncludeDirs.empty()) { |
179 | 0 | SmallVector<StringRef, 5> dirs; |
180 | 0 | CIncludeDirs.split(dirs, ":"); |
181 | 0 | for (StringRef dir : dirs) { |
182 | 0 | StringRef Prefix = |
183 | 0 | llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : ""; |
184 | 0 | addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); |
185 | 0 | } |
186 | 0 | return; |
187 | 0 | } |
188 | | |
189 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
190 | 15 | "/boot/system/non-packaged/develop/headers")); |
191 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
192 | 15 | "/boot/system/develop/headers/os")); |
193 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
194 | 15 | "/boot/system/develop/headers/os/app")); |
195 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
196 | 15 | "/boot/system/develop/headers/os/device")); |
197 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
198 | 15 | "/boot/system/develop/headers/os/drivers")); |
199 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
200 | 15 | "/boot/system/develop/headers/os/game")); |
201 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
202 | 15 | "/boot/system/develop/headers/os/interface")); |
203 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
204 | 15 | "/boot/system/develop/headers/os/kernel")); |
205 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
206 | 15 | "/boot/system/develop/headers/os/locale")); |
207 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
208 | 15 | "/boot/system/develop/headers/os/mail")); |
209 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
210 | 15 | "/boot/system/develop/headers/os/media")); |
211 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
212 | 15 | "/boot/system/develop/headers/os/midi")); |
213 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
214 | 15 | "/boot/system/develop/headers/os/midi2")); |
215 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
216 | 15 | "/boot/system/develop/headers/os/net")); |
217 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
218 | 15 | "/boot/system/develop/headers/os/opengl")); |
219 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
220 | 15 | "/boot/system/develop/headers/os/storage")); |
221 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
222 | 15 | "/boot/system/develop/headers/os/support")); |
223 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
224 | 15 | "/boot/system/develop/headers/os/translation")); |
225 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
226 | 15 | "/boot/system/develop/headers/os/add-ons/graphics")); |
227 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
228 | 15 | "/boot/system/develop/headers/os/add-ons/input_server")); |
229 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
230 | 15 | "/boot/system/develop/headers/os/add-ons/mail_daemon")); |
231 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
232 | 15 | "/boot/system/develop/headers/os/add-ons/registrar")); |
233 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
234 | 15 | "/boot/system/develop/headers/os/add-ons/screen_saver")); |
235 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
236 | 15 | "/boot/system/develop/headers/os/add-ons/tracker")); |
237 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
238 | 15 | "/boot/system/develop/headers/os/be_apps/Deskbar")); |
239 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
240 | 15 | "/boot/system/develop/headers/os/be_apps/NetPositive")); |
241 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
242 | 15 | "/boot/system/develop/headers/os/be_apps/Tracker")); |
243 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
244 | 15 | "/boot/system/develop/headers/3rdparty")); |
245 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
246 | 15 | "/boot/system/develop/headers/bsd")); |
247 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
248 | 15 | "/boot/system/develop/headers/glibc")); |
249 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
250 | 15 | "/boot/system/develop/headers/gnu")); |
251 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
252 | 15 | "/boot/system/develop/headers/posix")); |
253 | 15 | addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, |
254 | 15 | "/boot/system/develop/headers")); |
255 | 15 | } |
256 | | |
257 | | void Haiku::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
258 | 1 | llvm::opt::ArgStringList &CC1Args) const { |
259 | 1 | addSystemInclude(DriverArgs, CC1Args, |
260 | 1 | concat(getDriver().SysRoot, "/boot/system/develop/headers/c++/v1")); |
261 | 1 | } |
262 | | |
263 | 8 | Tool *Haiku::buildLinker() const { return new tools::haiku::Linker(*this); } |
264 | | |
265 | 8 | bool Haiku::HasNativeLLVMSupport() const { return true; } |