/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/clang/lib/Driver/ToolChains/Myriad.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- Myriad.cpp - Myriad ToolChain Implementations ----------*- C++ -*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | |
10 | | #include "Myriad.h" |
11 | | #include "CommonArgs.h" |
12 | | #include "clang/Driver/Compilation.h" |
13 | | #include "clang/Driver/Driver.h" |
14 | | #include "clang/Driver/DriverDiagnostic.h" |
15 | | #include "clang/Driver/Options.h" |
16 | | #include "llvm/Option/ArgList.h" |
17 | | |
18 | | using namespace clang::driver; |
19 | | using namespace clang::driver::toolchains; |
20 | | using namespace clang; |
21 | | using namespace llvm::opt; |
22 | | |
23 | | using tools::addPathIfExists; |
24 | | |
25 | | void tools::SHAVE::Compiler::ConstructJob(Compilation &C, const JobAction &JA, |
26 | | const InputInfo &Output, |
27 | | const InputInfoList &Inputs, |
28 | | const ArgList &Args, |
29 | 7 | const char *LinkingOutput) const { |
30 | 7 | ArgStringList CmdArgs; |
31 | 7 | assert(Inputs.size() == 1); |
32 | 7 | const InputInfo &II = Inputs[0]; |
33 | 7 | assert(II.getType() == types::TY_C || II.getType() == types::TY_CXX || |
34 | 7 | II.getType() == types::TY_PP_CXX); |
35 | 7 | |
36 | 7 | if (JA.getKind() == Action::PreprocessJobClass7 ) { |
37 | 1 | Args.ClaimAllArgs(); |
38 | 1 | CmdArgs.push_back("-E"); |
39 | 7 | } else { |
40 | 6 | assert(Output.getType() == types::TY_PP_Asm); // Require preprocessed asm. |
41 | 6 | CmdArgs.push_back("-S"); |
42 | 6 | CmdArgs.push_back("-fno-exceptions"); // Always do this even if unspecified. |
43 | 6 | } |
44 | 7 | CmdArgs.push_back("-DMYRIAD2"); |
45 | 7 | |
46 | 7 | // Append all -I, -iquote, -isystem paths, defines/undefines, 'f' |
47 | 7 | // flags, 'g' flags, 'M' flags, optimize flags, warning options, |
48 | 7 | // mcpu flags, mllvm flags, and Xclang flags. |
49 | 7 | // These are spelled the same way in clang and moviCompile. |
50 | 7 | Args.AddAllArgsExcept( |
51 | 7 | CmdArgs, |
52 | 7 | {options::OPT_I_Group, options::OPT_clang_i_Group, options::OPT_std_EQ, |
53 | 7 | options::OPT_D, options::OPT_U, options::OPT_f_Group, |
54 | 7 | options::OPT_f_clang_Group, options::OPT_g_Group, options::OPT_M_Group, |
55 | 7 | options::OPT_O_Group, options::OPT_W_Group, options::OPT_mcpu_EQ, |
56 | 7 | options::OPT_mllvm, options::OPT_Xclang}, |
57 | 7 | {options::OPT_fno_split_dwarf_inlining}); |
58 | 7 | Args.hasArg(options::OPT_fno_split_dwarf_inlining); // Claim it if present. |
59 | 7 | |
60 | 7 | // If we're producing a dependency file, and assembly is the final action, |
61 | 7 | // then the name of the target in the dependency file should be the '.o' |
62 | 7 | // file, not the '.s' file produced by this step. For example, instead of |
63 | 7 | // /tmp/mumble.s: mumble.c .../someheader.h |
64 | 7 | // the filename on the lefthand side should be "mumble.o" |
65 | 7 | if (Args.getLastArg(options::OPT_MF) && 7 !Args.getLastArg(options::OPT_MT)2 && |
66 | 2 | C.getActions().size() == 1 && |
67 | 7 | C.getActions()[0]->getKind() == Action::AssembleJobClass2 ) { |
68 | 2 | Arg *A = Args.getLastArg(options::OPT_o); |
69 | 2 | if (A2 ) { |
70 | 1 | CmdArgs.push_back("-MT"); |
71 | 1 | CmdArgs.push_back(Args.MakeArgString(A->getValue())); |
72 | 1 | } |
73 | 2 | } |
74 | 7 | |
75 | 7 | CmdArgs.push_back(II.getFilename()); |
76 | 7 | CmdArgs.push_back("-o"); |
77 | 7 | CmdArgs.push_back(Output.getFilename()); |
78 | 7 | |
79 | 7 | std::string Exec = |
80 | 7 | Args.MakeArgString(getToolChain().GetProgramPath("moviCompile")); |
81 | 7 | C.addCommand(llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Exec), |
82 | 7 | CmdArgs, Inputs)); |
83 | 7 | } |
84 | | |
85 | | void tools::SHAVE::Assembler::ConstructJob(Compilation &C, const JobAction &JA, |
86 | | const InputInfo &Output, |
87 | | const InputInfoList &Inputs, |
88 | | const ArgList &Args, |
89 | 5 | const char *LinkingOutput) const { |
90 | 5 | ArgStringList CmdArgs; |
91 | 5 | |
92 | 5 | assert(Inputs.size() == 1); |
93 | 5 | const InputInfo &II = Inputs[0]; |
94 | 5 | assert(II.getType() == types::TY_PP_Asm); // Require preprocessed asm input. |
95 | 5 | assert(Output.getType() == types::TY_Object); |
96 | 5 | |
97 | 5 | CmdArgs.push_back("-no6thSlotCompression"); |
98 | 5 | const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ); |
99 | 5 | if (CPUArg) |
100 | 1 | CmdArgs.push_back( |
101 | 1 | Args.MakeArgString("-cv:" + StringRef(CPUArg->getValue()))); |
102 | 5 | CmdArgs.push_back("-noSPrefixing"); |
103 | 5 | CmdArgs.push_back("-a"); // Mystery option. |
104 | 5 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); |
105 | 4 | for (const Arg *A : Args.filtered(options::OPT_I, options::OPT_isystem)) { |
106 | 4 | A->claim(); |
107 | 4 | CmdArgs.push_back( |
108 | 4 | Args.MakeArgString(std::string("-i:") + A->getValue(0))); |
109 | 4 | } |
110 | 5 | CmdArgs.push_back("-elf"); // Output format. |
111 | 5 | CmdArgs.push_back(II.getFilename()); |
112 | 5 | CmdArgs.push_back( |
113 | 5 | Args.MakeArgString(std::string("-o:") + Output.getFilename())); |
114 | 5 | |
115 | 5 | std::string Exec = |
116 | 5 | Args.MakeArgString(getToolChain().GetProgramPath("moviAsm")); |
117 | 5 | C.addCommand(llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Exec), |
118 | 5 | CmdArgs, Inputs)); |
119 | 5 | } |
120 | | |
121 | | void tools::Myriad::Linker::ConstructJob(Compilation &C, const JobAction &JA, |
122 | | const InputInfo &Output, |
123 | | const InputInfoList &Inputs, |
124 | | const ArgList &Args, |
125 | 5 | const char *LinkingOutput) const { |
126 | 5 | const auto &TC = |
127 | 5 | static_cast<const toolchains::MyriadToolChain &>(getToolChain()); |
128 | 5 | const llvm::Triple &T = TC.getTriple(); |
129 | 5 | ArgStringList CmdArgs; |
130 | 5 | bool UseStartfiles = |
131 | 5 | !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles); |
132 | 5 | bool UseDefaultLibs = |
133 | 5 | !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs); |
134 | 5 | // Silence warning if the args contain both -nostdlib and -stdlib=. |
135 | 5 | Args.getLastArg(options::OPT_stdlib_EQ); |
136 | 5 | |
137 | 5 | if (T.getArch() == llvm::Triple::sparc) |
138 | 3 | CmdArgs.push_back("-EB"); |
139 | 5 | else // SHAVE assumes little-endian, and sparcel is expressly so. |
140 | 2 | CmdArgs.push_back("-EL"); |
141 | 5 | |
142 | 5 | // The remaining logic is mostly like gnutools::Linker::ConstructJob, |
143 | 5 | // but we never pass through a --sysroot option and various other bits. |
144 | 5 | // For example, there are no sanitizers (yet) nor gold linker. |
145 | 5 | |
146 | 5 | // Eat some arguments that may be present but have no effect. |
147 | 5 | Args.ClaimAllArgs(options::OPT_g_Group); |
148 | 5 | Args.ClaimAllArgs(options::OPT_w); |
149 | 5 | Args.ClaimAllArgs(options::OPT_static_libgcc); |
150 | 5 | |
151 | 5 | if (Args.hasArg(options::OPT_s)) // Pass the 'strip' option. |
152 | 0 | CmdArgs.push_back("-s"); |
153 | 5 | |
154 | 5 | CmdArgs.push_back("-o"); |
155 | 5 | CmdArgs.push_back(Output.getFilename()); |
156 | 5 | |
157 | 5 | if (UseStartfiles5 ) { |
158 | 4 | // If you want startfiles, it means you want the builtin crti and crtbegin, |
159 | 4 | // but not crt0. Myriad link commands provide their own crt0.o as needed. |
160 | 4 | CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crti.o"))); |
161 | 4 | CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtbegin.o"))); |
162 | 4 | } |
163 | 5 | |
164 | 5 | Args.AddAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, |
165 | 5 | options::OPT_e, options::OPT_s, options::OPT_t, |
166 | 5 | options::OPT_Z_Flag, options::OPT_r}); |
167 | 5 | |
168 | 5 | TC.AddFilePathLibArgs(Args, CmdArgs); |
169 | 5 | |
170 | 5 | bool NeedsSanitizerDeps = addSanitizerRuntimes(TC, Args, CmdArgs); |
171 | 5 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); |
172 | 5 | |
173 | 5 | if (UseDefaultLibs5 ) { |
174 | 4 | if (NeedsSanitizerDeps) |
175 | 1 | linkSanitizerRuntimeDeps(TC, CmdArgs); |
176 | 4 | if (C.getDriver().CCCIsCXX()4 ) { |
177 | 1 | if (TC.GetCXXStdlibType(Args) == ToolChain::CST_Libcxx1 ) { |
178 | 0 | CmdArgs.push_back("-lc++"); |
179 | 0 | CmdArgs.push_back("-lc++abi"); |
180 | 0 | } else |
181 | 1 | CmdArgs.push_back("-lstdc++"); |
182 | 1 | } |
183 | 4 | if (T.getOS() == llvm::Triple::RTEMS4 ) { |
184 | 2 | CmdArgs.push_back("--start-group"); |
185 | 2 | CmdArgs.push_back("-lc"); |
186 | 2 | CmdArgs.push_back("-lgcc"); // circularly dependent on rtems |
187 | 2 | // You must provide your own "-L" option to enable finding these. |
188 | 2 | CmdArgs.push_back("-lrtemscpu"); |
189 | 2 | CmdArgs.push_back("-lrtemsbsp"); |
190 | 2 | CmdArgs.push_back("--end-group"); |
191 | 4 | } else { |
192 | 2 | CmdArgs.push_back("-lc"); |
193 | 2 | CmdArgs.push_back("-lgcc"); |
194 | 2 | } |
195 | 4 | } |
196 | 5 | if (UseStartfiles5 ) { |
197 | 4 | CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtend.o"))); |
198 | 4 | CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtn.o"))); |
199 | 4 | } |
200 | 5 | |
201 | 5 | std::string Exec = |
202 | 5 | Args.MakeArgString(TC.GetProgramPath("sparc-myriad-elf-ld")); |
203 | 5 | C.addCommand(llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Exec), |
204 | 5 | CmdArgs, Inputs)); |
205 | 5 | } |
206 | | |
207 | | MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, |
208 | | const ArgList &Args) |
209 | 22 | : Generic_ELF(D, Triple, Args) { |
210 | 22 | // If a target of 'sparc-myriad-elf' is specified to clang, it wants to use |
211 | 22 | // 'sparc-myriad--elf' (note the unknown OS) as the canonical triple. |
212 | 22 | // This won't work to find gcc. Instead we give the installation detector an |
213 | 22 | // extra triple, which is preferable to further hacks of the logic that at |
214 | 22 | // present is based solely on getArch(). In particular, it would be wrong to |
215 | 22 | // choose the myriad installation when targeting a non-myriad sparc install. |
216 | 22 | switch (Triple.getArch()) { |
217 | 1 | default: |
218 | 1 | D.Diag(clang::diag::err_target_unsupported_arch) |
219 | 1 | << Triple.getArchName() << "myriad"; |
220 | 1 | LLVM_FALLTHROUGH; |
221 | 22 | case llvm::Triple::sparc: |
222 | 22 | case llvm::Triple::sparcel: |
223 | 22 | case llvm::Triple::shave: |
224 | 22 | GCCInstallation.init(Triple, Args, {"sparc-myriad-elf"}); |
225 | 22 | } |
226 | 22 | |
227 | 22 | if (22 GCCInstallation.isValid()22 ) { |
228 | 3 | // This directory contains crt{i,n,begin,end}.o as well as libgcc. |
229 | 3 | // These files are tied to a particular version of gcc. |
230 | 3 | SmallString<128> CompilerSupportDir(GCCInstallation.getInstallPath()); |
231 | 3 | addPathIfExists(D, CompilerSupportDir, getFilePaths()); |
232 | 3 | } |
233 | 22 | // libstd++ and libc++ must both be found in this one place. |
234 | 22 | addPathIfExists(D, D.Dir + "/../sparc-myriad-elf/lib", getFilePaths()); |
235 | 22 | } |
236 | | |
237 | 22 | MyriadToolChain::~MyriadToolChain() {} |
238 | | |
239 | | void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
240 | 15 | ArgStringList &CC1Args) const { |
241 | 15 | if (!DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) |
242 | 14 | addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); |
243 | 15 | } |
244 | | |
245 | 1 | std::string MyriadToolChain::findLibCxxIncludePath() const { |
246 | 1 | std::string Path(getDriver().getInstalledDir()); |
247 | 1 | return Path + "/../include/c++/v1"; |
248 | 1 | } |
249 | | |
250 | | void MyriadToolChain::addLibStdCxxIncludePaths( |
251 | | const llvm::opt::ArgList &DriverArgs, |
252 | 2 | llvm::opt::ArgStringList &CC1Args) const { |
253 | 2 | StringRef LibDir = GCCInstallation.getParentLibPath(); |
254 | 2 | const GCCVersion &Version = GCCInstallation.getVersion(); |
255 | 2 | StringRef TripleStr = GCCInstallation.getTriple().str(); |
256 | 2 | const Multilib &Multilib = GCCInstallation.getMultilib(); |
257 | 2 | addLibStdCXXIncludePaths( |
258 | 2 | LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text, |
259 | 2 | "", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args); |
260 | 2 | } |
261 | | |
262 | | // MyriadToolChain handles several triples: |
263 | | // {shave,sparc{,el}}-myriad-{rtems,unknown}-elf |
264 | 40 | Tool *MyriadToolChain::SelectTool(const JobAction &JA) const { |
265 | 40 | // The inherited method works fine if not targeting the SHAVE. |
266 | 40 | if (!isShaveCompilation(getTriple())) |
267 | 28 | return ToolChain::SelectTool(JA); |
268 | 12 | switch (JA.getKind()) { |
269 | 7 | case Action::PreprocessJobClass: |
270 | 7 | case Action::CompileJobClass: |
271 | 7 | if (!Compiler) |
272 | 7 | Compiler.reset(new tools::SHAVE::Compiler(*this)); |
273 | 7 | return Compiler.get(); |
274 | 5 | case Action::AssembleJobClass: |
275 | 5 | if (!Assembler) |
276 | 5 | Assembler.reset(new tools::SHAVE::Assembler(*this)); |
277 | 5 | return Assembler.get(); |
278 | 0 | default: |
279 | 0 | return ToolChain::getTool(JA.getKind()); |
280 | 0 | } |
281 | 0 | } |
282 | | |
283 | 5 | Tool *MyriadToolChain::buildLinker() const { |
284 | 5 | return new tools::Myriad::Linker(*this); |
285 | 5 | } |
286 | | |
287 | 15 | SanitizerMask MyriadToolChain::getSupportedSanitizers() const { |
288 | 15 | return SanitizerKind::Address; |
289 | 15 | } |