Index: lib/Driver/ToolChains/Darwin.h =================================================================== --- lib/Driver/ToolChains/Darwin.h +++ lib/Driver/ToolChains/Darwin.h @@ -189,9 +189,9 @@ /// 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 @@ return llvm::ExceptionHandling::None; } + virtual StringRef getOSLibraryNameSuffix() const { return ""; } + /// } }; @@ -418,7 +420,7 @@ Action::OffloadKind DeviceOffloadKind) const override; StringRef getPlatformFamily() const; - StringRef getOSLibraryNameSuffix() const; + StringRef getOSLibraryNameSuffix() const override; public: static StringRef getSDKName(StringRef isysroot); Index: lib/Driver/ToolChains/Darwin.cpp =================================================================== --- lib/Driver/ToolChains/Darwin.cpp +++ lib/Driver/ToolChains/Darwin.cpp @@ -908,8 +908,17 @@ } 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ // 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 @@ // 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 @@ } 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); }