|
| 1 | +//===--- AIX.cpp - AIX 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 "AIX.h" |
| 10 | +#include "Arch/PPC.h" |
| 11 | +#include "CommonArgs.h" |
| 12 | +#include "clang/Driver/Compilation.h" |
| 13 | +#include "clang/Driver/Options.h" |
| 14 | +#include "clang/Driver/SanitizerArgs.h" |
| 15 | +#include "llvm/Option/ArgList.h" |
| 16 | + |
| 17 | +namespace aix = clang::driver::tools::aix; |
| 18 | +using AIX = clang::driver::toolchains::AIX; |
| 19 | + |
| 20 | +using namespace llvm::opt; |
| 21 | + |
| 22 | +void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, |
| 23 | + const InputInfo &Output, |
| 24 | + const InputInfoList &Inputs, const ArgList &Args, |
| 25 | + const char *LinkingOutput) const { |
| 26 | + const AIX &ToolChain = static_cast<const AIX &>(getToolChain()); |
| 27 | + ArgStringList CmdArgs; |
| 28 | + |
| 29 | + const bool IsArch32Bit = ToolChain.getTriple().isArch32Bit(); |
| 30 | + const bool IsArch64Bit = ToolChain.getTriple().isArch64Bit(); |
| 31 | + // Only support 32 and 64 bit. |
| 32 | + if (!(IsArch32Bit || IsArch64Bit)) |
| 33 | + llvm_unreachable("Unsupported bit width value."); |
| 34 | + |
| 35 | + // Force static linking when "-static" is present. |
| 36 | + if (Args.hasArg(options::OPT_static)) |
| 37 | + CmdArgs.push_back("-bnso"); |
| 38 | + |
| 39 | + // Specify linker output file. |
| 40 | + assert((Output.isFilename() || Output.isNothing()) && "Invalid output."); |
| 41 | + if (Output.isFilename()) { |
| 42 | + CmdArgs.push_back("-o"); |
| 43 | + CmdArgs.push_back(Output.getFilename()); |
| 44 | + } |
| 45 | + |
| 46 | + // Set linking mode (i.e., 32/64-bit) and the address of |
| 47 | + // text and data sections based on arch bit width. |
| 48 | + if (IsArch32Bit) { |
| 49 | + CmdArgs.push_back("-b32"); |
| 50 | + CmdArgs.push_back("-bpT:0x10000000"); |
| 51 | + CmdArgs.push_back("-bpD:0x20000000"); |
| 52 | + } else { |
| 53 | + // Must be 64-bit, otherwise asserted already. |
| 54 | + CmdArgs.push_back("-b64"); |
| 55 | + CmdArgs.push_back("-bpT:0x100000000"); |
| 56 | + CmdArgs.push_back("-bpD:0x110000000"); |
| 57 | + } |
| 58 | + |
| 59 | + auto getCrt0Basename = [&Args, IsArch32Bit] { |
| 60 | + // Enable gprofiling when "-pg" is specified. |
| 61 | + if (Args.hasArg(options::OPT_pg)) |
| 62 | + return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o"; |
| 63 | + // Enable profiling when "-p" is specified. |
| 64 | + else if (Args.hasArg(options::OPT_p)) |
| 65 | + return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o"; |
| 66 | + else |
| 67 | + return IsArch32Bit ? "crt0.o" : "crt0_64.o"; |
| 68 | + }; |
| 69 | + |
| 70 | + if (!Args.hasArg(options::OPT_nostdlib)) { |
| 71 | + CmdArgs.push_back( |
| 72 | + Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename()))); |
| 73 | + } |
| 74 | + |
| 75 | + // Specify linker input file(s). |
| 76 | + AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); |
| 77 | + |
| 78 | + // Add directory to library search path. |
| 79 | + Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 80 | + ToolChain.AddFilePathLibArgs(Args, CmdArgs); |
| 81 | + |
| 82 | + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { |
| 83 | + // Support POSIX threads if "-pthreads" or "-pthread" is present. |
| 84 | + if (Args.hasArg(options::OPT_pthreads, options::OPT_pthread)) |
| 85 | + CmdArgs.push_back("-lpthreads"); |
| 86 | + |
| 87 | + CmdArgs.push_back("-lc"); |
| 88 | + } |
| 89 | + |
| 90 | + const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); |
| 91 | + C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); |
| 92 | +} |
| 93 | + |
| 94 | +/// AIX - AIX tool chain which can call ld(1) directly. |
| 95 | +// TODO: Enable direct call to as(1). |
| 96 | +AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) |
| 97 | + : ToolChain(D, Triple, Args) { |
| 98 | + getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); |
| 99 | +} |
| 100 | + |
| 101 | +auto AIX::buildLinker() const -> Tool * { return new aix::Linker(*this); } |
0 commit comments