1e5dd7070Spatrick //===--- AIX.cpp - AIX ToolChain Implementations ----------------*- C++ -*-===//
2e5dd7070Spatrick //
3e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information.
5e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e5dd7070Spatrick //
7e5dd7070Spatrick //===----------------------------------------------------------------------===//
8e5dd7070Spatrick
9e5dd7070Spatrick #include "AIX.h"
10e5dd7070Spatrick #include "Arch/PPC.h"
11e5dd7070Spatrick #include "CommonArgs.h"
12e5dd7070Spatrick #include "clang/Driver/Compilation.h"
13e5dd7070Spatrick #include "clang/Driver/Options.h"
14e5dd7070Spatrick #include "clang/Driver/SanitizerArgs.h"
15e5dd7070Spatrick #include "llvm/Option/ArgList.h"
16*12c85518Srobert #include "llvm/ProfileData/InstrProf.h"
17ec727ea7Spatrick #include "llvm/Support/Path.h"
18e5dd7070Spatrick
19e5dd7070Spatrick using AIX = clang::driver::toolchains::AIX;
20e5dd7070Spatrick using namespace clang::driver;
21e5dd7070Spatrick using namespace clang::driver::tools;
22ec727ea7Spatrick using namespace clang::driver::toolchains;
23e5dd7070Spatrick
24e5dd7070Spatrick using namespace llvm::opt;
25ec727ea7Spatrick using namespace llvm::sys;
26e5dd7070Spatrick
ConstructJob(Compilation & C,const JobAction & JA,const InputInfo & Output,const InputInfoList & Inputs,const ArgList & Args,const char * LinkingOutput) const27e5dd7070Spatrick void aix::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
28e5dd7070Spatrick const InputInfo &Output,
29e5dd7070Spatrick const InputInfoList &Inputs,
30e5dd7070Spatrick const ArgList &Args,
31e5dd7070Spatrick const char *LinkingOutput) const {
32e5dd7070Spatrick ArgStringList CmdArgs;
33e5dd7070Spatrick
34e5dd7070Spatrick const bool IsArch32Bit = getToolChain().getTriple().isArch32Bit();
35e5dd7070Spatrick const bool IsArch64Bit = getToolChain().getTriple().isArch64Bit();
36e5dd7070Spatrick // Only support 32 and 64 bit.
37e5dd7070Spatrick if (!IsArch32Bit && !IsArch64Bit)
38e5dd7070Spatrick llvm_unreachable("Unsupported bit width value.");
39e5dd7070Spatrick
40e5dd7070Spatrick // Specify the mode in which the as(1) command operates.
41e5dd7070Spatrick if (IsArch32Bit) {
42e5dd7070Spatrick CmdArgs.push_back("-a32");
43e5dd7070Spatrick } else {
44e5dd7070Spatrick // Must be 64-bit, otherwise asserted already.
45e5dd7070Spatrick CmdArgs.push_back("-a64");
46e5dd7070Spatrick }
47e5dd7070Spatrick
48e5dd7070Spatrick // Accept any mixture of instructions.
49e5dd7070Spatrick // On Power for AIX and Linux, this behaviour matches that of GCC for both the
50e5dd7070Spatrick // user-provided assembler source case and the compiler-produced assembler
51e5dd7070Spatrick // source case. Yet XL with user-provided assembler source would not add this.
52e5dd7070Spatrick CmdArgs.push_back("-many");
53e5dd7070Spatrick
54e5dd7070Spatrick Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
55e5dd7070Spatrick
56e5dd7070Spatrick // Specify assembler output file.
57e5dd7070Spatrick assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
58e5dd7070Spatrick if (Output.isFilename()) {
59e5dd7070Spatrick CmdArgs.push_back("-o");
60e5dd7070Spatrick CmdArgs.push_back(Output.getFilename());
61e5dd7070Spatrick }
62e5dd7070Spatrick
63e5dd7070Spatrick // Specify assembler input file.
64e5dd7070Spatrick // The system assembler on AIX takes exactly one input file. The driver is
65e5dd7070Spatrick // expected to invoke as(1) separately for each assembler source input file.
66e5dd7070Spatrick if (Inputs.size() != 1)
67e5dd7070Spatrick llvm_unreachable("Invalid number of input files.");
68e5dd7070Spatrick const InputInfo &II = Inputs[0];
69e5dd7070Spatrick assert((II.isFilename() || II.isNothing()) && "Invalid input.");
70e5dd7070Spatrick if (II.isFilename())
71e5dd7070Spatrick CmdArgs.push_back(II.getFilename());
72e5dd7070Spatrick
73e5dd7070Spatrick const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
74ec727ea7Spatrick C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
75a9ac8606Spatrick Exec, CmdArgs, Inputs, Output));
76e5dd7070Spatrick }
77e5dd7070Spatrick
78*12c85518Srobert // Determine whether there are any linker options that supply an export list
79*12c85518Srobert // (or equivalent information about what to export) being sent to the linker.
hasExportListLinkerOpts(const ArgStringList & CmdArgs)80*12c85518Srobert static bool hasExportListLinkerOpts(const ArgStringList &CmdArgs) {
81*12c85518Srobert for (size_t i = 0, Size = CmdArgs.size(); i < Size; ++i) {
82*12c85518Srobert llvm::StringRef ArgString(CmdArgs[i]);
83*12c85518Srobert
84*12c85518Srobert if (ArgString.startswith("-bE:") || ArgString.startswith("-bexport:") ||
85*12c85518Srobert ArgString == "-bexpall" || ArgString == "-bexpfull")
86*12c85518Srobert return true;
87*12c85518Srobert
88*12c85518Srobert // If we split -b option, check the next opt.
89*12c85518Srobert if (ArgString == "-b" && i + 1 < Size) {
90*12c85518Srobert ++i;
91*12c85518Srobert llvm::StringRef ArgNextString(CmdArgs[i]);
92*12c85518Srobert if (ArgNextString.startswith("E:") ||
93*12c85518Srobert ArgNextString.startswith("export:") || ArgNextString == "expall" ||
94*12c85518Srobert ArgNextString == "expfull")
95*12c85518Srobert return true;
96*12c85518Srobert }
97*12c85518Srobert }
98*12c85518Srobert return false;
99*12c85518Srobert }
100*12c85518Srobert
ConstructJob(Compilation & C,const JobAction & JA,const InputInfo & Output,const InputInfoList & Inputs,const ArgList & Args,const char * LinkingOutput) const101e5dd7070Spatrick void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
102e5dd7070Spatrick const InputInfo &Output,
103e5dd7070Spatrick const InputInfoList &Inputs, const ArgList &Args,
104e5dd7070Spatrick const char *LinkingOutput) const {
105e5dd7070Spatrick const AIX &ToolChain = static_cast<const AIX &>(getToolChain());
106ec727ea7Spatrick const Driver &D = ToolChain.getDriver();
107e5dd7070Spatrick ArgStringList CmdArgs;
108e5dd7070Spatrick
109e5dd7070Spatrick const bool IsArch32Bit = ToolChain.getTriple().isArch32Bit();
110e5dd7070Spatrick const bool IsArch64Bit = ToolChain.getTriple().isArch64Bit();
111e5dd7070Spatrick // Only support 32 and 64 bit.
112e5dd7070Spatrick if (!(IsArch32Bit || IsArch64Bit))
113e5dd7070Spatrick llvm_unreachable("Unsupported bit width value.");
114e5dd7070Spatrick
115e5dd7070Spatrick // Force static linking when "-static" is present.
116e5dd7070Spatrick if (Args.hasArg(options::OPT_static))
117e5dd7070Spatrick CmdArgs.push_back("-bnso");
118e5dd7070Spatrick
119a9ac8606Spatrick // Add options for shared libraries.
120a9ac8606Spatrick if (Args.hasArg(options::OPT_shared)) {
121a9ac8606Spatrick CmdArgs.push_back("-bM:SRE");
122a9ac8606Spatrick CmdArgs.push_back("-bnoentry");
123a9ac8606Spatrick }
124a9ac8606Spatrick
125*12c85518Srobert // PGO instrumentation generates symbols belonging to special sections, and
126*12c85518Srobert // the linker needs to place all symbols in a particular section together in
127*12c85518Srobert // memory; the AIX linker does that under an option.
128*12c85518Srobert if (Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
129*12c85518Srobert false) ||
130*12c85518Srobert Args.hasFlag(options::OPT_fprofile_generate,
131*12c85518Srobert options::OPT_fno_profile_generate, false) ||
132*12c85518Srobert Args.hasFlag(options::OPT_fprofile_generate_EQ,
133*12c85518Srobert options::OPT_fno_profile_generate, false) ||
134*12c85518Srobert Args.hasFlag(options::OPT_fprofile_instr_generate,
135*12c85518Srobert options::OPT_fno_profile_instr_generate, false) ||
136*12c85518Srobert Args.hasFlag(options::OPT_fprofile_instr_generate_EQ,
137*12c85518Srobert options::OPT_fno_profile_instr_generate, false) ||
138*12c85518Srobert Args.hasFlag(options::OPT_fcs_profile_generate,
139*12c85518Srobert options::OPT_fno_profile_generate, false) ||
140*12c85518Srobert Args.hasFlag(options::OPT_fcs_profile_generate_EQ,
141*12c85518Srobert options::OPT_fno_profile_generate, false) ||
142*12c85518Srobert Args.hasArg(options::OPT_fcreate_profile) ||
143*12c85518Srobert Args.hasArg(options::OPT_coverage))
144*12c85518Srobert CmdArgs.push_back("-bdbg:namedsects:ss");
145*12c85518Srobert
146e5dd7070Spatrick // Specify linker output file.
147e5dd7070Spatrick assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
148e5dd7070Spatrick if (Output.isFilename()) {
149e5dd7070Spatrick CmdArgs.push_back("-o");
150e5dd7070Spatrick CmdArgs.push_back(Output.getFilename());
151e5dd7070Spatrick }
152e5dd7070Spatrick
153e5dd7070Spatrick // Set linking mode (i.e., 32/64-bit) and the address of
154e5dd7070Spatrick // text and data sections based on arch bit width.
155e5dd7070Spatrick if (IsArch32Bit) {
156e5dd7070Spatrick CmdArgs.push_back("-b32");
157e5dd7070Spatrick CmdArgs.push_back("-bpT:0x10000000");
158e5dd7070Spatrick CmdArgs.push_back("-bpD:0x20000000");
159e5dd7070Spatrick } else {
160e5dd7070Spatrick // Must be 64-bit, otherwise asserted already.
161e5dd7070Spatrick CmdArgs.push_back("-b64");
162e5dd7070Spatrick CmdArgs.push_back("-bpT:0x100000000");
163e5dd7070Spatrick CmdArgs.push_back("-bpD:0x110000000");
164e5dd7070Spatrick }
165e5dd7070Spatrick
166e5dd7070Spatrick auto getCrt0Basename = [&Args, IsArch32Bit] {
167e5dd7070Spatrick // Enable gprofiling when "-pg" is specified.
168e5dd7070Spatrick if (Args.hasArg(options::OPT_pg))
169e5dd7070Spatrick return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o";
170e5dd7070Spatrick // Enable profiling when "-p" is specified.
171e5dd7070Spatrick else if (Args.hasArg(options::OPT_p))
172e5dd7070Spatrick return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o";
173e5dd7070Spatrick else
174e5dd7070Spatrick return IsArch32Bit ? "crt0.o" : "crt0_64.o";
175e5dd7070Spatrick };
176e5dd7070Spatrick
177a9ac8606Spatrick if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
178a9ac8606Spatrick options::OPT_shared)) {
179e5dd7070Spatrick CmdArgs.push_back(
180e5dd7070Spatrick Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename())));
181a9ac8606Spatrick
182a9ac8606Spatrick CmdArgs.push_back(Args.MakeArgString(
183a9ac8606Spatrick ToolChain.GetFilePath(IsArch32Bit ? "crti.o" : "crti_64.o")));
184e5dd7070Spatrick }
185e5dd7070Spatrick
186a9ac8606Spatrick // Collect all static constructor and destructor functions in both C and CXX
187a9ac8606Spatrick // language link invocations. This has to come before AddLinkerInputs as the
188a9ac8606Spatrick // implied option needs to precede any other '-bcdtors' settings or
189a9ac8606Spatrick // '-bnocdtors' that '-Wl' might forward.
190ec727ea7Spatrick CmdArgs.push_back("-bcdtors:all:0:s");
191ec727ea7Spatrick
192e5dd7070Spatrick // Specify linker input file(s).
193e5dd7070Spatrick AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
194e5dd7070Spatrick
195*12c85518Srobert if (D.isUsingLTO()) {
196*12c85518Srobert assert(!Inputs.empty() && "Must have at least one input.");
197*12c85518Srobert addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
198*12c85518Srobert D.getLTOMode() == LTOK_Thin);
199*12c85518Srobert }
200*12c85518Srobert
201*12c85518Srobert if (Args.hasArg(options::OPT_shared) && !hasExportListLinkerOpts(CmdArgs)) {
202*12c85518Srobert
203*12c85518Srobert const char *CreateExportListExec = Args.MakeArgString(
204*12c85518Srobert path::parent_path(ToolChain.getDriver().ClangExecutable) +
205*12c85518Srobert "/llvm-nm");
206*12c85518Srobert ArgStringList CreateExportCmdArgs;
207*12c85518Srobert
208*12c85518Srobert std::string CreateExportListPath =
209*12c85518Srobert C.getDriver().GetTemporaryPath("CreateExportList", "exp");
210*12c85518Srobert const char *ExportList =
211*12c85518Srobert C.addTempFile(C.getArgs().MakeArgString(CreateExportListPath));
212*12c85518Srobert
213*12c85518Srobert for (const auto &II : Inputs)
214*12c85518Srobert if (II.isFilename())
215*12c85518Srobert CreateExportCmdArgs.push_back(II.getFilename());
216*12c85518Srobert
217*12c85518Srobert CreateExportCmdArgs.push_back("--export-symbols");
218*12c85518Srobert CreateExportCmdArgs.push_back("-X");
219*12c85518Srobert if (IsArch32Bit) {
220*12c85518Srobert CreateExportCmdArgs.push_back("32");
221*12c85518Srobert } else {
222*12c85518Srobert // Must be 64-bit, otherwise asserted already.
223*12c85518Srobert CreateExportCmdArgs.push_back("64");
224*12c85518Srobert }
225*12c85518Srobert
226*12c85518Srobert auto ExpCommand = std::make_unique<Command>(
227*12c85518Srobert JA, *this, ResponseFileSupport::None(), CreateExportListExec,
228*12c85518Srobert CreateExportCmdArgs, Inputs, Output);
229*12c85518Srobert ExpCommand->setRedirectFiles(
230*12c85518Srobert {std::nullopt, std::string(ExportList), std::nullopt});
231*12c85518Srobert C.addCommand(std::move(ExpCommand));
232*12c85518Srobert CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-bE:") + ExportList));
233*12c85518Srobert }
234*12c85518Srobert
235e5dd7070Spatrick // Add directory to library search path.
236e5dd7070Spatrick Args.AddAllArgs(CmdArgs, options::OPT_L);
237e5dd7070Spatrick ToolChain.AddFilePathLibArgs(Args, CmdArgs);
238a9ac8606Spatrick ToolChain.addProfileRTLibs(Args, CmdArgs);
239a9ac8606Spatrick
240a9ac8606Spatrick if (getToolChain().ShouldLinkCXXStdlib(Args))
241a9ac8606Spatrick getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
242e5dd7070Spatrick
243e5dd7070Spatrick if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
244a9ac8606Spatrick AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
245a9ac8606Spatrick
246*12c85518Srobert // Add OpenMP runtime if -fopenmp is specified.
247*12c85518Srobert if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
248*12c85518Srobert options::OPT_fno_openmp, false)) {
249*12c85518Srobert switch (ToolChain.getDriver().getOpenMPRuntime(Args)) {
250*12c85518Srobert case Driver::OMPRT_OMP:
251*12c85518Srobert CmdArgs.push_back("-lomp");
252*12c85518Srobert break;
253*12c85518Srobert case Driver::OMPRT_IOMP5:
254*12c85518Srobert CmdArgs.push_back("-liomp5");
255*12c85518Srobert break;
256*12c85518Srobert case Driver::OMPRT_GOMP:
257*12c85518Srobert CmdArgs.push_back("-lgomp");
258*12c85518Srobert break;
259*12c85518Srobert case Driver::OMPRT_Unknown:
260*12c85518Srobert // Already diagnosed.
261*12c85518Srobert break;
262*12c85518Srobert }
263*12c85518Srobert }
264*12c85518Srobert
265e5dd7070Spatrick // Support POSIX threads if "-pthreads" or "-pthread" is present.
266e5dd7070Spatrick if (Args.hasArg(options::OPT_pthreads, options::OPT_pthread))
267e5dd7070Spatrick CmdArgs.push_back("-lpthreads");
268e5dd7070Spatrick
269a9ac8606Spatrick if (D.CCCIsCXX())
270a9ac8606Spatrick CmdArgs.push_back("-lm");
271a9ac8606Spatrick
272e5dd7070Spatrick CmdArgs.push_back("-lc");
273*12c85518Srobert
274*12c85518Srobert if (Args.hasArg(options::OPT_pg)) {
275*12c85518Srobert CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
276*12c85518Srobert "/lib/profiled"));
277*12c85518Srobert CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
278*12c85518Srobert "/usr/lib/profiled"));
279*12c85518Srobert }
280e5dd7070Spatrick }
281e5dd7070Spatrick
282e5dd7070Spatrick const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
283ec727ea7Spatrick C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
284a9ac8606Spatrick Exec, CmdArgs, Inputs, Output));
285e5dd7070Spatrick }
286e5dd7070Spatrick
287e5dd7070Spatrick /// AIX - AIX tool chain which can call as(1) and ld(1) directly.
AIX(const Driver & D,const llvm::Triple & Triple,const ArgList & Args)288e5dd7070Spatrick AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
289e5dd7070Spatrick : ToolChain(D, Triple, Args) {
290a9ac8606Spatrick ParseInlineAsmUsingAsmParser = Args.hasFlag(
291a9ac8606Spatrick options::OPT_fintegrated_as, options::OPT_fno_integrated_as, true);
292a9ac8606Spatrick getLibraryPaths().push_back(getDriver().SysRoot + "/usr/lib");
293e5dd7070Spatrick }
294e5dd7070Spatrick
295ec727ea7Spatrick // Returns the effective header sysroot path to use.
296ec727ea7Spatrick // This comes from either -isysroot or --sysroot.
297ec727ea7Spatrick llvm::StringRef
GetHeaderSysroot(const llvm::opt::ArgList & DriverArgs) const298ec727ea7Spatrick AIX::GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const {
299ec727ea7Spatrick if (DriverArgs.hasArg(options::OPT_isysroot))
300ec727ea7Spatrick return DriverArgs.getLastArgValue(options::OPT_isysroot);
301ec727ea7Spatrick if (!getDriver().SysRoot.empty())
302ec727ea7Spatrick return getDriver().SysRoot;
303ec727ea7Spatrick return "/";
304ec727ea7Spatrick }
305ec727ea7Spatrick
AddClangSystemIncludeArgs(const ArgList & DriverArgs,ArgStringList & CC1Args) const306ec727ea7Spatrick void AIX::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
307ec727ea7Spatrick ArgStringList &CC1Args) const {
308ec727ea7Spatrick // Return if -nostdinc is specified as a driver option.
309ec727ea7Spatrick if (DriverArgs.hasArg(options::OPT_nostdinc))
310ec727ea7Spatrick return;
311ec727ea7Spatrick
312ec727ea7Spatrick llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
313ec727ea7Spatrick const Driver &D = getDriver();
314ec727ea7Spatrick
315ec727ea7Spatrick if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
316ec727ea7Spatrick SmallString<128> P(D.ResourceDir);
317*12c85518Srobert // Add the PowerPC intrinsic headers (<resource>/include/ppc_wrappers)
318*12c85518Srobert path::append(P, "include", "ppc_wrappers");
319*12c85518Srobert addSystemInclude(DriverArgs, CC1Args, P);
320*12c85518Srobert // Add the Clang builtin headers (<resource>/include)
321*12c85518Srobert addSystemInclude(DriverArgs, CC1Args, path::parent_path(P.str()));
322ec727ea7Spatrick }
323ec727ea7Spatrick
324ec727ea7Spatrick // Return if -nostdlibinc is specified as a driver option.
325ec727ea7Spatrick if (DriverArgs.hasArg(options::OPT_nostdlibinc))
326ec727ea7Spatrick return;
327ec727ea7Spatrick
328ec727ea7Spatrick // Add <sysroot>/usr/include.
329ec727ea7Spatrick SmallString<128> UP(Sysroot);
330ec727ea7Spatrick path::append(UP, "/usr/include");
331ec727ea7Spatrick addSystemInclude(DriverArgs, CC1Args, UP.str());
332ec727ea7Spatrick }
333ec727ea7Spatrick
AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList & DriverArgs,llvm::opt::ArgStringList & CC1Args) const334*12c85518Srobert void AIX::AddClangCXXStdlibIncludeArgs(
335*12c85518Srobert const llvm::opt::ArgList &DriverArgs,
336*12c85518Srobert llvm::opt::ArgStringList &CC1Args) const {
337*12c85518Srobert
338*12c85518Srobert if (DriverArgs.hasArg(options::OPT_nostdinc) ||
339*12c85518Srobert DriverArgs.hasArg(options::OPT_nostdincxx) ||
340*12c85518Srobert DriverArgs.hasArg(options::OPT_nostdlibinc))
341a9ac8606Spatrick return;
342*12c85518Srobert
343*12c85518Srobert switch (GetCXXStdlibType(DriverArgs)) {
344a9ac8606Spatrick case ToolChain::CST_Libstdcxx:
345*12c85518Srobert llvm::report_fatal_error(
346*12c85518Srobert "picking up libstdc++ headers is unimplemented on AIX");
347*12c85518Srobert case ToolChain::CST_Libcxx: {
348*12c85518Srobert llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
349*12c85518Srobert SmallString<128> PathCPP(Sysroot);
350*12c85518Srobert llvm::sys::path::append(PathCPP, "opt/IBM/openxlCSDK", "include", "c++",
351*12c85518Srobert "v1");
352*12c85518Srobert addSystemInclude(DriverArgs, CC1Args, PathCPP.str());
353*12c85518Srobert // Required in order to suppress conflicting C++ overloads in the system
354*12c85518Srobert // libc headers that were used by XL C++.
355*12c85518Srobert CC1Args.push_back("-D__LIBC_NO_CPP_MATH_OVERLOADS__");
356*12c85518Srobert return;
357*12c85518Srobert }
358a9ac8606Spatrick }
359a9ac8606Spatrick
360a9ac8606Spatrick llvm_unreachable("Unexpected C++ library type; only libc++ is supported.");
361a9ac8606Spatrick }
362a9ac8606Spatrick
AddCXXStdlibLibArgs(const llvm::opt::ArgList & Args,llvm::opt::ArgStringList & CmdArgs) const363*12c85518Srobert void AIX::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
364*12c85518Srobert llvm::opt::ArgStringList &CmdArgs) const {
365*12c85518Srobert switch (GetCXXStdlibType(Args)) {
366*12c85518Srobert case ToolChain::CST_Libstdcxx:
367*12c85518Srobert llvm::report_fatal_error("linking libstdc++ unimplemented on AIX");
368*12c85518Srobert case ToolChain::CST_Libcxx:
369*12c85518Srobert CmdArgs.push_back("-lc++");
370*12c85518Srobert if (Args.hasArg(options::OPT_fexperimental_library))
371*12c85518Srobert CmdArgs.push_back("-lc++experimental");
372*12c85518Srobert CmdArgs.push_back("-lc++abi");
373*12c85518Srobert return;
374*12c85518Srobert }
375*12c85518Srobert
376*12c85518Srobert llvm_unreachable("Unexpected C++ library type; only libc++ is supported.");
377*12c85518Srobert }
378*12c85518Srobert
addProfileRTLibs(const llvm::opt::ArgList & Args,llvm::opt::ArgStringList & CmdArgs) const379*12c85518Srobert void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args,
380*12c85518Srobert llvm::opt::ArgStringList &CmdArgs) const {
381*12c85518Srobert // Add linker option -u__llvm_profile_runtime to cause runtime
382*12c85518Srobert // initialization to occur.
383*12c85518Srobert if (needsProfileRT(Args))
384*12c85518Srobert CmdArgs.push_back(Args.MakeArgString(
385*12c85518Srobert Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
386*12c85518Srobert ToolChain::addProfileRTLibs(Args, CmdArgs);
387*12c85518Srobert }
388*12c85518Srobert
GetDefaultCXXStdlibType() const389a9ac8606Spatrick ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const {
390a9ac8606Spatrick return ToolChain::CST_Libcxx;
391a9ac8606Spatrick }
392a9ac8606Spatrick
GetDefaultRuntimeLibType() const393a9ac8606Spatrick ToolChain::RuntimeLibType AIX::GetDefaultRuntimeLibType() const {
394a9ac8606Spatrick return ToolChain::RLT_CompilerRT;
395a9ac8606Spatrick }
396a9ac8606Spatrick
buildAssembler() const397e5dd7070Spatrick auto AIX::buildAssembler() const -> Tool * { return new aix::Assembler(*this); }
398e5dd7070Spatrick
buildLinker() const399e5dd7070Spatrick auto AIX::buildLinker() const -> Tool * { return new aix::Linker(*this); }
400