diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -219,9 +219,8 @@ !Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) CmdArgs.push_back("-demangle"); - // FIXME: Pass most of the flags below that check Version if LinkerIsLLD too. - - if (Args.hasArg(options::OPT_rdynamic) && Version >= VersionTuple(137)) + if (Args.hasArg(options::OPT_rdynamic) && + (Version >= VersionTuple(137) || LinkerIsLLD)) CmdArgs.push_back("-export_dynamic"); // If we are using App Extension restrictions, pass a flag to the linker @@ -230,7 +229,8 @@ options::OPT_fno_application_extension, false)) CmdArgs.push_back("-application_extension"); - if (D.isUsingLTO() && Version >= VersionTuple(116) && NeedsTempPath(Inputs)) { + if (D.isUsingLTO() && (Version >= VersionTuple(116) || LinkerIsLLD) && + NeedsTempPath(Inputs)) { std::string TmpPathName; if (D.getLTOMode() == LTOK_Full) { // If we are using full LTO, then automatically create a temporary file @@ -269,8 +269,11 @@ CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath)); } - // ld64 version 262 and above run the deduplicate pass by default. - if (Version >= VersionTuple(262) && shouldLinkerNotDedup(C.getJobs().empty(), Args)) + // ld64 version 262 and above runs the deduplicate pass by default. + // FIXME: lld doesn't dedup by default. Should we pass `--icf=safe` + // if `!shouldLinkerNotDedup()` if LinkerIsLLD here? + if (Version >= VersionTuple(262) && + shouldLinkerNotDedup(C.getJobs().empty(), Args)) CmdArgs.push_back("-no_deduplicate"); // Derived from the "link" spec. @@ -368,6 +371,7 @@ // Check if the toolchain supports bitcode build flow. if (MachOTC.SupportsEmbeddedBitcode()) { CmdArgs.push_back("-bitcode_bundle"); + // FIXME: Pass this if LinkerIsLLD too, once it implements this flag. if (C.getDriver().embedBitcodeMarkerOnly() && Version >= VersionTuple(278)) { CmdArgs.push_back("-bitcode_process_mode"); diff --git a/clang/test/Driver/darwin-ld-lto-lld.c b/clang/test/Driver/darwin-ld-lto-lld.c new file mode 100644 --- /dev/null +++ b/clang/test/Driver/darwin-ld-lto-lld.c @@ -0,0 +1,19 @@ +// REQUIRES: shell + +// Check that lld gets "-lto_library". +// (Separate test file since darwin-ld-lto requires system-darwin but this +// test doesn't require that.) + +// Check that -object_lto_path is passed correctly to ld64 +// RUN: %clang -fuse-ld=lld -B%S/Inputs/lld -target x86_64-apple-darwin10 \ +// RUN: %s -flto=full -### 2>&1 \ +// RUN: | FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s +// FULL_LTO_OBJECT_PATH: {{ld(.exe)?"}} +// FULL_LTO_OBJECT_PATH-SAME: "-object_path_lto" +// FULL_LTO_OBJECT_PATH-SAME: {{cc\-[a-zA-Z0-9_]+.o}}" +// RUN: %clang -fuse-ld=lld -B%S/Inputs/lld -target x86_64-apple-darwin10 \ +// RUN: %s -flto=thin -### 2>&1 \ +// RUN: | FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s +// THIN_LTO_OBJECT_PATH: {{ld(.exe)?"}} +// THIN_LTO_OBJECT_PATH-SAME: "-object_path_lto" +// THIN_LTO_OBJECT_PATH-SAME: {{thinlto\-[a-zA-Z0-9_]+}} diff --git a/clang/test/Driver/darwin-ld-lto.c b/clang/test/Driver/darwin-ld-lto.c --- a/clang/test/Driver/darwin-ld-lto.c +++ b/clang/test/Driver/darwin-ld-lto.c @@ -20,13 +20,13 @@ // Check that -object_lto_path is passed correctly to ld64 -// RUN: %clang -target x86_64-apple-darwin10 %s -flto=full -### 2>&1 | \ -// RUN: FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s +// RUN: %clang -fuse-ld= -target x86_64-apple-darwin10 %s -flto=full -### 2>&1 \ +// RUN: | FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s // FULL_LTO_OBJECT_PATH: {{ld(.exe)?"}} // FULL_LTO_OBJECT_PATH-SAME: "-object_path_lto" // FULL_LTO_OBJECT_PATH-SAME: {{cc\-[a-zA-Z0-9_]+.o}}" -// RUN: %clang -target x86_64-apple-darwin10 %s -flto=thin -### 2>&1 | \ -// RUN: FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s +// RUN: %clang -fuse-ld= -target x86_64-apple-darwin10 %s -flto=thin -### 2>&1 \ +// RUN: | FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s // THIN_LTO_OBJECT_PATH: {{ld(.exe)?"}} // THIN_LTO_OBJECT_PATH-SAME: "-object_path_lto" // THIN_LTO_OBJECT_PATH-SAME: {{thinlto\-[a-zA-Z0-9_]+}} diff --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c --- a/clang/test/Driver/darwin-ld.c +++ b/clang/test/Driver/darwin-ld.c @@ -236,6 +236,9 @@ // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \ // RUN: -fuse-ld= -mlinker-version=137 2> %t.log // RUN: FileCheck -check-prefix=LINK_EXPORT_DYNAMIC %s < %t.log +// RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \ +// RUN: -fuse-ld=lld -B%S/Inputs/lld -mlinker-version=100 2> %t.log +// RUN: FileCheck -check-prefix=LINK_EXPORT_DYNAMIC %s < %t.log // LINK_EXPORT_DYNAMIC: {{ld(.exe)?"}} // LINK_EXPORT_DYNAMIC: "-export_dynamic"