From: Chris Bieneman Date: Wed, 15 Aug 2018 20:09:38 +0000 (+0000) Subject: Refactor Darwin driver to refer to runtimes by component X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=457610888eccc00666d72e1792f3464469b09179;p=clang Refactor Darwin driver to refer to runtimes by component Summary: In r335809, Petr Hosek lays out support for what he calls the multiarch runtimes layout. This new way of laying out the directories for runtime libraries is workable for all platforms. Petr did some of the common infrastructure and made it work for Linux and Fuscia. This patch is a cleanup to the Darwin and MachO drivers to serve as a step toward supporting it in Darwin. This patch does primarily two things: (1) Changes the APIs for how the Darwin driver refers to compiler-rt libraries to use the component names, similar to how Linux and Fuscia do (2) Removes some legacy functionality for supporting macOS versions before 10.6. This functionality is effectively dead code because in r339277, the support was removed from compiler-rt for generating the 10.4 runtime support library, and Xcode 10 (currently in beta) removes libgcc_s.10.4 and libgcc_s.10.5 from the macOS SDK. With this patch landed a subsequent patch can modify MachO::AddLinkRuntimeLib to support the multiarch runtimes layout. Worth noting: None of the removed functionality was actually covered in the test suite. So no test case updates are required. Reviewers: phosek, bruno, arphaman Reviewed By: phosek, arphaman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50618 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339807 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index 4306de154a..6c8bba5764 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -908,8 +908,17 @@ unsigned DarwinClang::GetDefaultDwarfVersion() const { } void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, - StringRef DarwinLibName, - RuntimeLinkOptions Opts) const { + StringRef Component, RuntimeLinkOptions Opts, + bool IsShared) const { + SmallString<64> DarwinLibName = StringRef("libclang_rt."); + // an Darwin the builtins compomnent is not in the library name + if (Component != "builtins") { + DarwinLibName += Component; + if (!(Opts & RLO_IsEmbedded)) + DarwinLibName += "_"; + } + DarwinLibName += getOSLibraryNameSuffix(); + DarwinLibName += IsShared ? "_dynamic.dylib" : ".a"; SmallString<128> Dir(getDriver().ResourceDir); llvm::sys::path::append( Dir, "lib", (Opts & RLO_IsEmbedded) ? "macho_embedded" : "darwin"); @@ -1013,10 +1022,8 @@ void Darwin::addProfileRTLibs(const ArgList &Args, ArgStringList &CmdArgs) const { if (!needsProfileRT(Args)) return; - AddLinkRuntimeLib( - Args, CmdArgs, - (Twine("libclang_rt.profile_") + getOSLibraryNameSuffix() + ".a").str(), - RuntimeLinkOptions(RLO_AlwaysLink | RLO_FirstLink)); + AddLinkRuntimeLib(Args, CmdArgs, "profile", + RuntimeLinkOptions(RLO_AlwaysLink | RLO_FirstLink)); // If we have a symbol export directive and we're linking in the profile // runtime, automatically export symbols necessary to implement some of the @@ -1033,12 +1040,7 @@ void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, StringRef Sanitizer, bool Shared) const { auto RLO = RuntimeLinkOptions(RLO_AlwaysLink | (Shared ? RLO_AddRPath : 0U)); - AddLinkRuntimeLib(Args, CmdArgs, - (Twine("libclang_rt.") + Sanitizer + "_" + - getOSLibraryNameSuffix() + - (Shared ? "_dynamic.dylib" : ".a")) - .str(), - RLO); + AddLinkRuntimeLib(Args, CmdArgs, Sanitizer, RLO, Shared); } ToolChain::RuntimeLibType DarwinClang::GetRuntimeLibType( @@ -1092,10 +1094,7 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, AddCXXStdlibLibArgs(Args, CmdArgs); } if (Sanitize.needsStatsRt()) { - StringRef OS = isTargetMacOS() ? "osx" : "iossim"; - AddLinkRuntimeLib(Args, CmdArgs, - (Twine("libclang_rt.stats_client_") + OS + ".a").str(), - RLO_AlwaysLink); + AddLinkRuntimeLib(Args, CmdArgs, "stats_client", RLO_AlwaysLink); AddLinkSanitizerLibArgs(Args, CmdArgs, "stats"); } if (Sanitize.needsEsanRt()) @@ -1106,52 +1105,15 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, CmdArgs.push_back("-lSystem"); // Select the dynamic runtime library and the target specific static library. - if (isTargetWatchOSBased()) { - // We currently always need a static runtime library for watchOS. - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a"); - } else if (isTargetTvOSBased()) { - // We currently always need a static runtime library for tvOS. - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a"); - } else if (isTargetIOSBased()) { + if (isTargetIOSBased()) { // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, // it never went into the SDK. // Linking against libgcc_s.1 isn't needed for iOS 5.0+ if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && getTriple().getArch() != llvm::Triple::aarch64) CmdArgs.push_back("-lgcc_s.1"); - - // We currently always need a static runtime library for iOS. - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a"); - } else { - assert(isTargetMacOS() && "unexpected non MacOS platform"); - // The dynamic runtime library was merged with libSystem for 10.6 and - // beyond; only 10.4 and 10.5 need an additional runtime library. - if (isMacosxVersionLT(10, 5)) - CmdArgs.push_back("-lgcc_s.10.4"); - else if (isMacosxVersionLT(10, 6)) - CmdArgs.push_back("-lgcc_s.10.5"); - - // Originally for OS X, we thought we would only need a static runtime - // library when targeting 10.4, to provide versions of the static functions - // which were omitted from 10.4.dylib. This led to the creation of the 10.4 - // builtins library. - // - // Unfortunately, that turned out to not be true, because Darwin system - // headers can still use eprintf on i386, and it is not exported from - // libSystem. Therefore, we still must provide a runtime library just for - // the tiny tiny handful of projects that *might* use that symbol. - // - // Then over time, we figured out it was useful to add more things to the - // runtime so we created libclang_rt.osx.a to provide new functions when - // deploying to old OS builds, and for a long time we had both eprintf and - // osx builtin libraries. Which just seems excessive. So with PR 28855, we - // are removing the eprintf library and expecting eprintf to be provided by - // the OS X builtins library. - if (isMacosxVersionLT(10, 5)) - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a"); - else - AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a"); } + AddLinkRuntimeLib(Args, CmdArgs, "builtins"); } /// Returns the most appropriate macOS target version for the current process. @@ -1992,12 +1954,12 @@ void MachO::AddLinkRuntimeLibArgs(const ArgList &Args, // Embedded targets are simple at the moment, not supporting sanitizers and // with different libraries for each member of the product { static, PIC } x // { hard-float, soft-float } - llvm::SmallString<32> CompilerRT = StringRef("libclang_rt."); + llvm::SmallString<32> CompilerRT = StringRef(""); CompilerRT += (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard) ? "hard" : "soft"; - CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a"; + CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic" : "_static"; AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, RLO_IsEmbedded); } @@ -2126,7 +2088,7 @@ llvm::ExceptionHandling Darwin::GetExceptionModel(const ArgList &Args) const { // Only watchOS uses the new DWARF/Compact unwinding method. llvm::Triple Triple(ComputeLLVMTriple(Args)); - if(Triple.isWatchABI()) + if (Triple.isWatchABI()) return llvm::ExceptionHandling::DwarfCFI; return llvm::ExceptionHandling::SjLj; @@ -2263,8 +2225,7 @@ void Darwin::addStartObjectFileArgs(const ArgList &Args, } if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) && - !isTargetWatchOS() && - isMacosxVersionLT(10, 5)) { + !isTargetWatchOS() && isMacosxVersionLT(10, 5)) { const char *Str = Args.MakeArgString(GetFilePath("crt3.o")); CmdArgs.push_back(Str); } diff --git a/lib/Driver/ToolChains/Darwin.h b/lib/Driver/ToolChains/Darwin.h index 87d553bd7e..98ad743191 100644 --- a/lib/Driver/ToolChains/Darwin.h +++ b/lib/Driver/ToolChains/Darwin.h @@ -189,9 +189,9 @@ public: /// Add a runtime library to the list of items to link. void AddLinkRuntimeLib(const llvm::opt::ArgList &Args, - llvm::opt::ArgStringList &CmdArgs, - StringRef DarwinLibName, - RuntimeLinkOptions Opts = RuntimeLinkOptions()) const; + llvm::opt::ArgStringList &CmdArgs, StringRef Component, + RuntimeLinkOptions Opts = RuntimeLinkOptions(), + bool IsShared = false) const; /// Add any profiling runtime libraries that are needed. This is essentially a /// MachO specific version of addProfileRT in Tools.cpp. @@ -252,6 +252,8 @@ public: return llvm::ExceptionHandling::None; } + virtual StringRef getOSLibraryNameSuffix() const { return ""; } + /// } }; @@ -418,7 +420,7 @@ protected: Action::OffloadKind DeviceOffloadKind) const override; StringRef getPlatformFamily() const; - StringRef getOSLibraryNameSuffix() const; + StringRef getOSLibraryNameSuffix() const override; public: static StringRef getSDKName(StringRef isysroot);