Mercurial > hg > CbC > CbC_llvm
diff clang/lib/Driver/ToolChains/AIX.cpp @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 1d019706d866 |
children | 5f17cb93ff66 |
line wrap: on
line diff
--- a/clang/lib/Driver/ToolChains/AIX.cpp Tue Jun 15 19:13:43 2021 +0900 +++ b/clang/lib/Driver/ToolChains/AIX.cpp Tue Jun 15 19:15:29 2021 +0900 @@ -13,12 +13,15 @@ #include "clang/Driver/Options.h" #include "clang/Driver/SanitizerArgs.h" #include "llvm/Option/ArgList.h" +#include "llvm/Support/Path.h" using AIX = clang::driver::toolchains::AIX; using namespace clang::driver; using namespace clang::driver::tools; +using namespace clang::driver::toolchains; using namespace llvm::opt; +using namespace llvm::sys; void aix::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, @@ -41,12 +44,6 @@ CmdArgs.push_back("-a64"); } - // Accept an undefined symbol as an extern so that an error message is not - // displayed. Otherwise, undefined symbols are flagged with error messages. - // FIXME: This should be removed when the assembly generation from the - // compiler is able to write externs properly. - CmdArgs.push_back("-u"); - // Accept any mixture of instructions. // On Power for AIX and Linux, this behaviour matches that of GCC for both the // user-provided assembler source case and the compiler-produced assembler @@ -73,7 +70,8 @@ CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); - C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), + Exec, CmdArgs, Inputs, Output)); } void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -81,6 +79,7 @@ const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { const AIX &ToolChain = static_cast<const AIX &>(getToolChain()); + const Driver &D = ToolChain.getDriver(); ArgStringList CmdArgs; const bool IsArch32Bit = ToolChain.getTriple().isArch32Bit(); @@ -93,6 +92,12 @@ if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("-bnso"); + // Add options for shared libraries. + if (Args.hasArg(options::OPT_shared)) { + CmdArgs.push_back("-bM:SRE"); + CmdArgs.push_back("-bnoentry"); + } + // Specify linker output file. assert((Output.isFilename() || Output.isNothing()) && "Invalid output."); if (Output.isFilename()) { @@ -124,34 +129,113 @@ return IsArch32Bit ? "crt0.o" : "crt0_64.o"; }; - if (!Args.hasArg(options::OPT_nostdlib)) { + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, + options::OPT_shared)) { CmdArgs.push_back( Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename()))); + + CmdArgs.push_back(Args.MakeArgString( + ToolChain.GetFilePath(IsArch32Bit ? "crti.o" : "crti_64.o"))); } + // Collect all static constructor and destructor functions in both C and CXX + // language link invocations. This has to come before AddLinkerInputs as the + // implied option needs to precede any other '-bcdtors' settings or + // '-bnocdtors' that '-Wl' might forward. + CmdArgs.push_back("-bcdtors:all:0:s"); + // Specify linker input file(s). AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); // Add directory to library search path. Args.AddAllArgs(CmdArgs, options::OPT_L); ToolChain.AddFilePathLibArgs(Args, CmdArgs); + ToolChain.addProfileRTLibs(Args, CmdArgs); + + if (getToolChain().ShouldLinkCXXStdlib(Args)) + getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { + AddRunTimeLibs(ToolChain, D, CmdArgs, Args); + // Support POSIX threads if "-pthreads" or "-pthread" is present. if (Args.hasArg(options::OPT_pthreads, options::OPT_pthread)) CmdArgs.push_back("-lpthreads"); + if (D.CCCIsCXX()) + CmdArgs.push_back("-lm"); + CmdArgs.push_back("-lc"); } const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); - C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), + Exec, CmdArgs, Inputs, Output)); } /// AIX - AIX tool chain which can call as(1) and ld(1) directly. AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : ToolChain(D, Triple, Args) { - getFilePaths().push_back(getDriver().SysRoot + "/usr/lib"); + getLibraryPaths().push_back(getDriver().SysRoot + "/usr/lib"); +} + +// Returns the effective header sysroot path to use. +// This comes from either -isysroot or --sysroot. +llvm::StringRef +AIX::GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const { + if (DriverArgs.hasArg(options::OPT_isysroot)) + return DriverArgs.getLastArgValue(options::OPT_isysroot); + if (!getDriver().SysRoot.empty()) + return getDriver().SysRoot; + return "/"; +} + +void AIX::AddClangSystemIncludeArgs(const ArgList &DriverArgs, + ArgStringList &CC1Args) const { + // Return if -nostdinc is specified as a driver option. + if (DriverArgs.hasArg(options::OPT_nostdinc)) + return; + + llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs); + const Driver &D = getDriver(); + + // Add the Clang builtin headers (<resource>/include). + if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { + SmallString<128> P(D.ResourceDir); + path::append(P, "/include"); + addSystemInclude(DriverArgs, CC1Args, P.str()); + } + + // Return if -nostdlibinc is specified as a driver option. + if (DriverArgs.hasArg(options::OPT_nostdlibinc)) + return; + + // Add <sysroot>/usr/include. + SmallString<128> UP(Sysroot); + path::append(UP, "/usr/include"); + addSystemInclude(DriverArgs, CC1Args, UP.str()); +} + +void AIX::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const { + switch (GetCXXStdlibType(Args)) { + case ToolChain::CST_Libcxx: + CmdArgs.push_back("-lc++"); + CmdArgs.push_back("-lc++abi"); + return; + case ToolChain::CST_Libstdcxx: + llvm::report_fatal_error("linking libstdc++ unimplemented on AIX"); + } + + llvm_unreachable("Unexpected C++ library type; only libc++ is supported."); +} + +ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const { + return ToolChain::CST_Libcxx; +} + +ToolChain::RuntimeLibType AIX::GetDefaultRuntimeLibType() const { + return ToolChain::RLT_CompilerRT; } auto AIX::buildAssembler() const -> Tool * { return new aix::Assembler(*this); }