r339807 - Refactor Darwin driver to refer to runtimes by component
Hans Wennborg via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 17 03:38:23 PDT 2018
Just a heads up that this broke the Chromium build on Mac:
https://crbug.com/874997
Apparently we have some target that explicitly targets 10.5. I don't
know if that's really necessary, but the fact that we ran into this at
all suggests others will too, so maybe this change warrants a release
notes entry.
Thanks,
Hans
On Wed, Aug 15, 2018 at 10:09 PM, Chris Bieneman via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Author: cbieneman
> Date: Wed Aug 15 13:09:38 2018
> New Revision: 339807
>
> URL: http://llvm.org/viewvc/llvm-project?rev=339807&view=rev
> Log:
> 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
>
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
> cfe/trunk/lib/Driver/ToolChains/Darwin.h
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=339807&r1=339806&r2=339807&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Wed Aug 15 13:09:38 2018
> @@ -908,8 +908,17 @@ unsigned DarwinClang::GetDefaultDwarfVer
> }
>
> 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 ArgL
> 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::AddLinkSanitizerLibArg
> 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(
> 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(
> 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
> // 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::GetExcep
>
> // 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(cons
> }
>
> 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);
> }
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.h?rev=339807&r1=339806&r2=339807&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/ToolChains/Darwin.h (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Darwin.h Wed Aug 15 13:09:38 2018
> @@ -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);
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list