/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/Ananas.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- Ananas.cpp - Ananas 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 "Ananas.h" |
10 | | #include "CommonArgs.h" |
11 | | #include "clang/Driver/Compilation.h" |
12 | | #include "clang/Driver/Driver.h" |
13 | | #include "clang/Driver/InputInfo.h" |
14 | | #include "clang/Driver/Options.h" |
15 | | #include "llvm/ADT/SmallString.h" |
16 | | #include "llvm/Option/ArgList.h" |
17 | | #include "llvm/Support/Path.h" |
18 | | |
19 | | using namespace clang::driver; |
20 | | using namespace clang::driver::tools; |
21 | | using namespace clang::driver::toolchains; |
22 | | using namespace clang; |
23 | | using namespace llvm::opt; |
24 | | |
25 | | void ananas::Assembler::ConstructJob(Compilation &C, const JobAction &JA, |
26 | | const InputInfo &Output, |
27 | | const InputInfoList &Inputs, |
28 | | const ArgList &Args, |
29 | 0 | const char *LinkingOutput) const { |
30 | 0 | claimNoWarnArgs(Args); |
31 | 0 | ArgStringList CmdArgs; |
32 | |
|
33 | 0 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); |
34 | |
|
35 | 0 | CmdArgs.push_back("-o"); |
36 | 0 | CmdArgs.push_back(Output.getFilename()); |
37 | |
|
38 | 0 | for (const auto &II : Inputs) |
39 | 0 | CmdArgs.push_back(II.getFilename()); |
40 | |
|
41 | 0 | const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); |
42 | 0 | C.addCommand(std::make_unique<Command>(JA, *this, |
43 | 0 | ResponseFileSupport::AtFileCurCP(), |
44 | 0 | Exec, CmdArgs, Inputs, Output)); |
45 | 0 | } |
46 | | |
47 | | void ananas::Linker::ConstructJob(Compilation &C, const JobAction &JA, |
48 | | const InputInfo &Output, |
49 | | const InputInfoList &Inputs, |
50 | | const ArgList &Args, |
51 | 3 | const char *LinkingOutput) const { |
52 | 3 | const ToolChain &ToolChain = getToolChain(); |
53 | 3 | const Driver &D = ToolChain.getDriver(); |
54 | 3 | ArgStringList CmdArgs; |
55 | | |
56 | | // Silence warning for "clang -g foo.o -o foo" |
57 | 3 | Args.ClaimAllArgs(options::OPT_g_Group); |
58 | | // and "clang -emit-llvm foo.o -o foo" |
59 | 3 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
60 | | // and for "clang -w foo.o -o foo". Other warning options are already |
61 | | // handled somewhere else. |
62 | 3 | Args.ClaimAllArgs(options::OPT_w); |
63 | | |
64 | 3 | if (!D.SysRoot.empty()) |
65 | 2 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
66 | | |
67 | 3 | if (Args.hasArg(options::OPT_static)) { |
68 | 1 | CmdArgs.push_back("-Bstatic"); |
69 | 2 | } else { |
70 | 2 | if (Args.hasArg(options::OPT_rdynamic)) |
71 | 0 | CmdArgs.push_back("-export-dynamic"); |
72 | 2 | if (Args.hasArg(options::OPT_shared)) { |
73 | 1 | CmdArgs.push_back("-Bshareable"); |
74 | 1 | } else if (!Args.hasArg(options::OPT_r)) { |
75 | 0 | Args.AddAllArgs(CmdArgs, options::OPT_pie); |
76 | 0 | CmdArgs.push_back("-dynamic-linker"); |
77 | 0 | CmdArgs.push_back("/lib/ld-ananas.so"); |
78 | 0 | } |
79 | 2 | } |
80 | | |
81 | 3 | if (Output.isFilename()) { |
82 | 3 | CmdArgs.push_back("-o"); |
83 | 3 | CmdArgs.push_back(Output.getFilename()); |
84 | 3 | } else { |
85 | 0 | assert(Output.isNothing() && "Invalid output."); |
86 | 0 | } |
87 | | |
88 | 3 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, |
89 | 3 | options::OPT_r)) { |
90 | 2 | if (!Args.hasArg(options::OPT_shared)) { |
91 | 1 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o"))); |
92 | 1 | } |
93 | 2 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); |
94 | 2 | if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)1 ) { |
95 | 1 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbeginS.o"))); |
96 | 1 | } else { |
97 | 1 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o"))); |
98 | 1 | } |
99 | 2 | } |
100 | | |
101 | 3 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
102 | 3 | ToolChain.AddFilePathLibArgs(Args, CmdArgs); |
103 | 3 | Args.AddAllArgs(CmdArgs, |
104 | 3 | {options::OPT_T_Group, options::OPT_s, options::OPT_t, |
105 | 3 | options::OPT_Z_Flag, options::OPT_r}); |
106 | | |
107 | 3 | if (D.isUsingLTO()) { |
108 | 0 | assert(!Inputs.empty() && "Must have at least one input."); |
109 | 0 | addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0], |
110 | 0 | D.getLTOMode() == LTOK_Thin); |
111 | 0 | } |
112 | | |
113 | 3 | AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); |
114 | | |
115 | 3 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, |
116 | 3 | options::OPT_r)) { |
117 | 2 | if (ToolChain.ShouldLinkCXXStdlib(Args)) |
118 | 0 | ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
119 | 2 | CmdArgs.push_back("-lc"); |
120 | 2 | } |
121 | | |
122 | 3 | if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, |
123 | 3 | options::OPT_r)) { |
124 | 2 | if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)1 ) |
125 | 1 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); |
126 | 1 | else |
127 | 1 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); |
128 | 2 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
129 | 2 | } |
130 | | |
131 | 3 | const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); |
132 | 3 | C.addCommand(std::make_unique<Command>(JA, *this, |
133 | 3 | ResponseFileSupport::AtFileCurCP(), |
134 | 3 | Exec, CmdArgs, Inputs, Output)); |
135 | 3 | } |
136 | | |
137 | | // Ananas - Ananas tool chain which can call as(1) and ld(1) directly. |
138 | | |
139 | | Ananas::Ananas(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
140 | 3 | : Generic_ELF(D, Triple, Args) { |
141 | 3 | getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
142 | 3 | } |
143 | | |
144 | 0 | Tool *Ananas::buildAssembler() const { |
145 | 0 | return new tools::ananas::Assembler(*this); |
146 | 0 | } |
147 | | |
148 | 3 | Tool *Ananas::buildLinker() const { return new tools::ananas::Linker(*this); } |