15#include "llvm/Option/ArgList.h"
16#include "llvm/Support/Path.h"
21using llvm::opt::ArgList;
22using llvm::opt::ArgStringList;
27 const char *LinkingOutput)
const {
31 ArgStringList CmdArgs;
34 switch (TC.getArch()) {
36 llvm_unreachable(
"unsupported architecture");
37 case llvm::Triple::arm:
38 case llvm::Triple::thumb:
39 case llvm::Triple::aarch64:
41 case llvm::Triple::x86:
42 CmdArgs.push_back(
"--32");
44 case llvm::Triple::x86_64:
45 CmdArgs.push_back(
"--64");
49 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
51 CmdArgs.push_back(
"-o");
54 for (
const auto &Input : Inputs)
55 CmdArgs.push_back(Input.getFilename());
57 const std::string
Assembler = TC.GetProgramPath(
"as");
61 Exec, CmdArgs, Inputs, Output));
67 const char *LinkingOutput)
const {
70 const llvm::Triple &
T = TC.getTriple();
71 const Driver &
D = TC.getDriver();
73 ArgStringList CmdArgs;
77 Args.ClaimAllArgs(options::OPT_g_Group);
79 Args.ClaimAllArgs(options::OPT_emit_llvm);
81 Args.ClaimAllArgs(options::OPT_w);
84 if (!
D.SysRoot.empty())
85 CmdArgs.push_back(Args.MakeArgString(
"--sysroot=" +
D.SysRoot));
87 if (Args.hasArg(options::OPT_pie))
88 CmdArgs.push_back(
"-pie");
89 if (Args.hasArg(options::OPT_rdynamic))
90 CmdArgs.push_back(
"-export-dynamic");
91 if (Args.hasArg(options::OPT_s))
92 CmdArgs.push_back(
"--strip-all");
94 CmdArgs.push_back(
"-m");
95 switch (TC.getArch()) {
97 D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
99 case llvm::Triple::arm:
100 case llvm::Triple::thumb:
102 CmdArgs.push_back(
"thumb2pe");
104 case llvm::Triple::aarch64:
105 CmdArgs.push_back(
"arm64pe");
107 case llvm::Triple::x86:
108 CmdArgs.push_back(
"i386pe");
109 EntryPoint.append(
"_");
111 case llvm::Triple::x86_64:
112 CmdArgs.push_back(
"i386pep");
116 if (Args.hasArg(options::OPT_shared)) {
117 switch (
T.getArch()) {
119 llvm_unreachable(
"unsupported architecture");
120 case llvm::Triple::aarch64:
121 case llvm::Triple::arm:
122 case llvm::Triple::thumb:
123 case llvm::Triple::x86_64:
124 EntryPoint.append(
"_DllMainCRTStartup");
126 case llvm::Triple::x86:
127 EntryPoint.append(
"_DllMainCRTStartup@12");
131 CmdArgs.push_back(
"-shared");
132 CmdArgs.push_back(Args.hasArg(options::OPT_static) ?
"-Bstatic"
135 CmdArgs.push_back(
"--enable-auto-image-base");
137 CmdArgs.push_back(
"--entry");
138 CmdArgs.push_back(Args.MakeArgString(EntryPoint));
140 EntryPoint.append(
"mainCRTStartup");
142 CmdArgs.push_back(Args.hasArg(options::OPT_static) ?
"-Bstatic"
145 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
146 CmdArgs.push_back(
"--entry");
147 CmdArgs.push_back(Args.MakeArgString(EntryPoint));
154 CmdArgs.push_back(
"--allow-multiple-definition");
156 CmdArgs.push_back(
"-o");
159 if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_rdynamic)) {
161 llvm::sys::path::replace_extension(ImpLib,
".lib");
163 CmdArgs.push_back(
"--out-implib");
164 CmdArgs.push_back(Args.MakeArgString(ImpLib));
167 Args.AddAllArgs(CmdArgs, options::OPT_L);
168 TC.AddFilePathLibArgs(Args, CmdArgs);
171 if (TC.ShouldLinkCXXStdlib(Args)) {
172 bool StaticCXX = Args.hasArg(options::OPT_static_libstdcxx) &&
173 !Args.hasArg(options::OPT_static);
175 CmdArgs.push_back(
"-Bstatic");
176 TC.AddCXXStdlibLibArgs(Args, CmdArgs);
178 CmdArgs.push_back(
"-Bdynamic");
181 if (!Args.hasArg(options::OPT_nostdlib)) {
182 if (!Args.hasArg(options::OPT_nodefaultlibs)) {
184 CmdArgs.push_back(
"-lmsvcrt");
189 if (TC.getSanitizerArgs(Args).needsAsanRt()) {
191 if (Args.hasArg(options::OPT_shared)) {
192 CmdArgs.push_back(TC.getCompilerRTArgString(Args,
"asan_dll_thunk"));
194 for (
const auto &Lib : {
"asan_dynamic",
"asan_dynamic_runtime_thunk"})
195 CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
198 CmdArgs.push_back(Args.MakeArgString(
"--undefined"));
199 CmdArgs.push_back(Args.MakeArgString(TC.getArch() == llvm::Triple::x86
200 ?
"___asan_seh_interceptor"
201 :
"__asan_seh_interceptor"));
205 Exec = Args.MakeArgString(TC.GetLinkerPath());
207 C.addCommand(std::make_unique<Command>(JA, *
this,
209 Exec, CmdArgs, Inputs, Output));
213 const llvm::Triple &
T,
214 const llvm::opt::ArgList &Args)
225 return getArch() == llvm::Triple::x86_64;
229 return getArch() == llvm::Triple::x86_64;
233 return getArch() == llvm::Triple::x86_64;
238 llvm::opt::ArgStringList &CC1Args)
const {
240 const std::string &SysRoot =
D.SysRoot;
242 auto AddSystemAfterIncludes = [&]() {
243 for (
const auto &
P : DriverArgs.getAllArgValues(options::OPT_isystem_after))
247 if (DriverArgs.hasArg(options::OPT_nostdinc)) {
248 AddSystemAfterIncludes();
253 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
255 llvm::sys::path::append(ResourceDir,
"include");
258 AddSystemAfterIncludes();
264 llvm::opt::ArgStringList &CC1Args)
const {
267 if (DriverArgs.hasArg(options::OPT_nostdinc) ||
268 DriverArgs.hasArg(options::OPT_nostdincxx))
277 llvm::opt::ArgStringList &CmdArgs)
const {
279 CmdArgs.push_back(
"-lc++");
280 if (Args.hasArg(options::OPT_fexperimental_library))
281 CmdArgs.push_back(
"-lc++experimental");
287 Res |= SanitizerKind::Address;
288 Res |= SanitizerKind::PointerCompare;
289 Res |= SanitizerKind::PointerSubtract;
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
std::string SysRoot
sysroot, if present
const FunctionProtoType * T
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.
static constexpr ResponseFileSupport AtFileUTF8()