thakis created this revision. thakis added a reviewer: hans. thakis requested review of this revision.
New MachO LLD doesn't implement the old -macos_version_min (etc) flags, but it understands the modern platform_version flag. So make the clang driver pass that when using new MachO LLD. Also, while here, don't pass -lto_library to LLD, since it links in LTO libraries statically (which it can because it's versioned alongside clang). https://reviews.llvm.org/D92037 Files: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/Darwin.cpp clang/lib/Driver/ToolChains/Darwin.h clang/test/Driver/darwin-ld-platform-version-ios.c clang/test/Driver/darwin-ld-platform-version-macos.c clang/test/Driver/darwin-ld-platform-version-tvos.c clang/test/Driver/darwin-ld-platform-version-watchos.c
Index: clang/test/Driver/darwin-ld-platform-version-watchos.c =================================================================== --- clang/test/Driver/darwin-ld-platform-version-watchos.c +++ clang/test/Driver/darwin-ld-platform-version-watchos.c @@ -1,12 +1,24 @@ // RUN: touch %t.o -// RUN: %clang -target arm64_32-apple-watchos5.2 -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=0 -### %t.o 2>&1 \ +// RUN: %clang -target arm64_32-apple-watchos5.2 \ +// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=0 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-OLD %s -// RUN: %clang -target arm64_32-apple-watchos5.2 -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=400 -### %t.o 2>&1 \ +// RUN: %clang -target arm64_32-apple-watchos5.2 \ +// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=400 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-OLD %s -// RUN: %clang -target arm64_32-apple-watchos5.2 -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target arm64_32-apple-watchos5.2 -fuse-ld=lld.darwinnew \ +// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=0 \ +// RUN: -### %t.o -B%S/Inputs/lld 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-NEW %s -// RUN: %clang -target x86_64-apple-watchos6-simulator -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target arm64_32-apple-watchos5.2 \ +// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ +// RUN: | FileCheck --check-prefix=LINKER-NEW %s +// RUN: %clang -target x86_64-apple-watchos6-simulator \ +// RUN: -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=SIMUL %s // LINKER-OLD: "-watchos_version_min" "5.2.0" Index: clang/test/Driver/darwin-ld-platform-version-tvos.c =================================================================== --- clang/test/Driver/darwin-ld-platform-version-tvos.c +++ clang/test/Driver/darwin-ld-platform-version-tvos.c @@ -1,12 +1,24 @@ // RUN: touch %t.o -// RUN: %clang -target arm64-apple-tvos12.3 -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=0 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-tvos12.3 \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=0 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-OLD %s -// RUN: %clang -target arm64-apple-tvos12.3 -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=400 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-tvos12.3 \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=400 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-OLD %s -// RUN: %clang -target arm64-apple-tvos12.3 -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-tvos12.3 -fuse-ld=lld.darwinnew \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=0 \ +// RUN: -### %t.o -B%S/Inputs/lld 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-NEW %s -// RUN: %clang -target x86_64-apple-tvos13-simulator -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-tvos12.3 \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ +// RUN: | FileCheck --check-prefix=LINKER-NEW %s +// RUN: %clang -target x86_64-apple-tvos13-simulator \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=SIMUL %s // LINKER-OLD: "-tvos_version_min" "12.3.0" Index: clang/test/Driver/darwin-ld-platform-version-macos.c =================================================================== --- clang/test/Driver/darwin-ld-platform-version-macos.c +++ clang/test/Driver/darwin-ld-platform-version-macos.c @@ -1,20 +1,42 @@ // RUN: touch %t.o -// RUN: %clang -target x86_64-apple-macos10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=0 -### %t.o 2>&1 \ +// RUN: %clang -target x86_64-apple-macos10.13 \ +// RUN: -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=0 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-OLD %s -// RUN: %clang -target x86_64-apple-macos10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=400 -### %t.o 2>&1 \ +// RUN: %clang -target x86_64-apple-macos10.13 -fuse-ld=lld.darwinnew \ +// RUN: -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=0 \ +// RUN: -### %t.o -B%S/Inputs/lld 2>&1 \ +// RUN: | FileCheck --check-prefix=LINKER-NEW %s +// RUN: %clang -target x86_64-apple-macos10.13 \ +// RUN: -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=400 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-OLD %s -// RUN: env SDKROOT=%S/Inputs/MacOSX10.14.sdk %clang -target x86_64-apple-macos10.13.0.1 -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: env SDKROOT=%S/Inputs/MacOSX10.14.sdk %clang \ +// RUN: -target x86_64-apple-macos10.13.0.1 -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-NEW %s -// RUN: %clang -target arm64-apple-macos10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-macos10.13 \ +// RUN: -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=400 \ +// RUN: -### %t.o 2>&1 \ +// RUN: | FileCheck --check-prefix=ARM64_OLD %s +// RUN: %clang -target arm64-apple-macos10.13 -fuse-ld=lld.darwinnew \ +// RUN: -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=400 \ +// RUN: -### %t.o -B%S/Inputs/lld 2>&1 \ // RUN: | FileCheck --check-prefix=ARM64_NEW %s -// RUN: %clang -target arm64-apple-darwin19 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-macos10.13 \ +// RUN: -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=ARM64_NEW %s -// RUN: %clang -target arm64-apple-macos11.1 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-darwin19 \ +// RUN: -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ +// RUN: | FileCheck --check-prefix=ARM64_NEW %s +// RUN: %clang -target arm64-apple-macos11.1 \ +// RUN: -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=ARM64_NEW_1 %s -// RUN: %clang -target arm64-apple-macos10.13 -isysroot %S/Inputs/MacOSX10.14.sdk -mlinker-version=400 -### %t.o 2>&1 \ -// RUN: | FileCheck --check-prefix=ARM64_OLD %s // LINKER-OLD: "-macosx_version_min" "10.13.0" // LINKER-NEW: "-platform_version" "macos" "10.13.0" "10.14" @@ -23,6 +45,7 @@ // ARM64_NEW_1: "-platform_version" "macos" "11.1.0" "10.14" // ARM64_OLD: "-macosx_version_min" "11.0.0" -// RUN: %clang -target x86_64-apple-macos10.13 -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target x86_64-apple-macos10.13 -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=NOSDK %s // NOSDK: "-platform_version" "macos" "10.13.0" "0.0.0" Index: clang/test/Driver/darwin-ld-platform-version-ios.c =================================================================== --- clang/test/Driver/darwin-ld-platform-version-ios.c +++ clang/test/Driver/darwin-ld-platform-version-ios.c @@ -1,12 +1,28 @@ // RUN: touch %t.o -// RUN: %clang -target arm64-apple-ios12.3 -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=0 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-ios12.3 \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=0 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-OLD %s -// RUN: %clang -target arm64-apple-ios12.3 -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=400 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-ios12.3 \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=400 \ +// RUN: -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-OLD %s -// RUN: %clang -target arm64-apple-ios12.3 -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target arm64-apple-ios12.3 \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ +// RUN: | FileCheck --check-prefix=LINKER-NEW %s +// RUN: %clang -target arm64-apple-ios12.3 -fuse-ld=lld.darwinnew \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=0 \ +// RUN: -### %t.o -B%S/Inputs/lld 2>&1 \ // RUN: | FileCheck --check-prefix=LINKER-NEW %s -// RUN: %clang -target x86_64-apple-ios13-simulator -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=520 -### %t.o 2>&1 \ +// RUN: %clang -target x86_64-apple-ios13-simulator \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=520 \ +// RUN: -### %t.o 2>&1 \ +// RUN: | FileCheck --check-prefix=SIMUL %s +// RUN: %clang -target x86_64-apple-ios13-simulator -fuse-ld=lld.darwinnew \ +// RUN: -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=0 \ +// RUN: -### %t.o -B%S/Inputs/lld 2>&1 \ // RUN: | FileCheck --check-prefix=SIMUL %s // LINKER-OLD: "-iphoneos_version_min" "12.3.0" Index: clang/lib/Driver/ToolChains/Darwin.h =================================================================== --- clang/lib/Driver/ToolChains/Darwin.h +++ clang/lib/Driver/ToolChains/Darwin.h @@ -64,7 +64,7 @@ void AddLinkArgs(Compilation &C, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfoList &Inputs, unsigned Version[5], - bool LinkerIsLLD) const; + bool LinkerIsLLD, bool LinkerIsLLDDarwinNew) const; public: Linker(const ToolChain &TC) : MachOTool("darwin::Linker", "linker", TC) {} Index: clang/lib/Driver/ToolChains/Darwin.cpp =================================================================== --- clang/lib/Driver/ToolChains/Darwin.cpp +++ clang/lib/Driver/ToolChains/Darwin.cpp @@ -204,7 +204,8 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args, ArgStringList &CmdArgs, const InputInfoList &Inputs, - unsigned Version[5], bool LinkerIsLLD) const { + unsigned Version[5], bool LinkerIsLLD, + bool LinkerIsLLDDarwinNew) const { const Driver &D = getToolChain().getDriver(); const toolchains::MachO &MachOTC = getMachOToolChain(); @@ -252,7 +253,9 @@ // Since this is passed unconditionally, ld64 will never look for libLTO.dylib // next to it. That's ok since ld64 using a libLTO.dylib not matching the // clang version won't work anyways. - if (Version[0] >= 133) { + // lld is built at the same revision as clang and statically links in + // LLVM libraries, so it doesn't need libLTO.dylib. + if (Version[0] >= 133 && !LinkerIsLLD) { // Search for libLTO in <InstalledDir>/../lib/libLTO.dylib StringRef P = llvm::sys::path::parent_path(D.Dir); SmallString<128> LibLTOPath(P); @@ -335,7 +338,7 @@ Args.AddAllArgs(CmdArgs, options::OPT_init); // Add the deployment target. - if (Version[0] >= 520) + if (Version[0] >= 520 || LinkerIsLLDDarwinNew) MachOTC.addPlatformVersionArgs(Args, CmdArgs); else MachOTC.addMinVersionArgs(Args, CmdArgs); @@ -536,13 +539,14 @@ << A->getAsString(Args); } - bool LinkerIsLLD = false; - const char *Exec = - Args.MakeArgString(getToolChain().GetLinkerPath(&LinkerIsLLD)); + bool LinkerIsLLD, LinkerIsLLDDarwinNew; + const char *Exec = Args.MakeArgString( + getToolChain().GetLinkerPath(&LinkerIsLLD, &LinkerIsLLDDarwinNew)); // I'm not sure why this particular decomposition exists in gcc, but // we follow suite for ease of comparison. - AddLinkArgs(C, Args, CmdArgs, Inputs, Version, LinkerIsLLD); + AddLinkArgs(C, Args, CmdArgs, Inputs, Version, LinkerIsLLD, + LinkerIsLLDDarwinNew); if (willEmitRemarks(Args) && checkRemarksOptions(getToolChain().getDriver(), Args, Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -548,9 +548,12 @@ return D.GetProgramPath(Name, *this); } -std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const { +std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD, + bool *LinkerIsLLDDarwinNew) const { if (LinkerIsLLD) *LinkerIsLLD = false; + if (LinkerIsLLDDarwinNew) + *LinkerIsLLDDarwinNew = false; // Get -fuse-ld= first to prevent -Wunused-command-line-argument. -fuse-ld= is // considered as the linker flavor, e.g. "bfd", "gold", or "lld". @@ -603,9 +606,11 @@ std::string LinkerPath(GetProgramPath(LinkerName.c_str())); if (llvm::sys::fs::can_execute(LinkerPath)) { + // FIXME: Remove lld.darwinnew here once it's the only MachO lld. if (LinkerIsLLD) - // FIXME: Remove lld.darwinnew here once it's the only MachO lld. *LinkerIsLLD = UseLinker == "lld" || UseLinker == "lld.darwinnew"; + if (LinkerIsLLDDarwinNew) + *LinkerIsLLDDarwinNew = UseLinker == "lld.darwinnew"; return LinkerPath; } } Index: clang/include/clang/Driver/ToolChain.h =================================================================== --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -331,7 +331,10 @@ /// is LLD. If it's set, it can be assumed that the linker is LLD built /// at the same revision as clang, and clang can make assumptions about /// LLD's supported flags, error output, etc. - std::string GetLinkerPath(bool *LinkerIsLLD = nullptr) const; + /// If LinkerIsLLDDarwinNew is non-nullptr, it's set if it's the in-progress + /// new version in lld/MachO. + std::string GetLinkerPath(bool *LinkerIsLLD = nullptr, + bool *LinkerIsLLDDarwinNew = nullptr) const; /// Returns the linker path for emitting a static library. std::string GetStaticLibToolPath() const;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits