thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added subscribers: ormris, steven_wu, hiraditya.
thakis requested review of this revision.

- ld64.lld now completely supports -export_dynamic (D119372 
<https://reviews.llvm.org/D119372>), so map -rdynamic to -export_dynamic like 
already done for ld64

- ld64.lld has been supporting -object_path_lto for well over a year (D92537 
<https://reviews.llvm.org/D92537>), so pass it like already done for ld64

- ld64.lld has been doing ICF for a while, so pass -no_deduplicate in -O0 and 
-O1 builds like already done for ld64


https://reviews.llvm.org/D119612

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-ld-dedup.c
  clang/test/Driver/darwin-ld-lto.c
  clang/test/Driver/darwin-ld.c

Index: clang/test/Driver/darwin-ld.c
===================================================================
--- clang/test/Driver/darwin-ld.c
+++ clang/test/Driver/darwin-ld.c
@@ -235,6 +235,8 @@
 
 // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
 // RUN:   -fuse-ld= -mlinker-version=137 2> %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
+// RUN:   -fuse-ld=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"
Index: clang/test/Driver/darwin-ld-lto.c
===================================================================
--- clang/test/Driver/darwin-ld-lto.c
+++ clang/test/Driver/darwin-ld-lto.c
@@ -20,13 +20,17 @@
 
 
 // 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 -### \
+// RUN:     2>&1 | FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s
+// RUN: %clang -fuse-ld=lld -target x86_64-apple-darwin10 %s -flto=full -### \
+// RUN:     2>&1 | 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 -### \
+// RUN:     2>&1 | FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s
+// RUN: %clang -fuse-ld=lld -target x86_64-apple-darwin10 %s -flto=thin -### \
+// RUN:     2>&1 | 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_]+}}
Index: clang/test/Driver/darwin-ld-dedup.c
===================================================================
--- clang/test/Driver/darwin-ld-dedup.c
+++ clang/test/Driver/darwin-ld-dedup.c
@@ -1,42 +1,58 @@
 // REQUIRES: system-darwin
 
-// -no_deduplicate is only present from ld64 version 262 and later.
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// -no_deduplicate is only present from ld64 version 262 and later, or lld.
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=261 -O0 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
 
 // Add -no_deduplicate when either -O0 or -O1 is explicitly specified
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -O0 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld=lld %s \
+// RUN:   -mlinker-version=261 -O0 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -O1 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld=lld %s \
+// RUN:   -mlinker-version=261 -O1 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
 
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -O2 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld=lld %s \
+// RUN:   -mlinker-version=262 -O2 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -O3 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -Os 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -O4 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
 // RUN:   -mlinker-version=262 -Ofast 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
 
 // Add -no_deduplicate when no -O option is specified *and* this is a compile+link
 // (implicit -O0)
-// RUN: %clang -target x86_64-apple-darwin10 -### %s \
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld= %s \
+// RUN:   -mlinker-version=262 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 -### -fuse-ld=lld %s \
 // RUN:   -mlinker-version=262 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
 
 // Do *not* add -no_deduplicate when no -O option is specified and this is just a link
 // (since we can't imply -O0)
 // RUN: rm -f %t.o %t.bin
 // RUN: yaml2obj %S/Inputs/empty-x86_64-apple-darwin.yaml -o %t.o
-// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -mlinker-version=262 \
+// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -fuse-ld= -mlinker-version=262 \
+// RUN:   -o %t.bin 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -fuse-ld=lld -mlinker-version=262 \
 // RUN:   -o %t.bin 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -mlinker-version=262 \
+// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -fuse-ld= -mlinker-version=262 \
 // RUN:   -O0 -o %t.bin 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -mlinker-version=262 \
+// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -fuse-ld=lld -mlinker-version=262 \
+// RUN:   -O0 -o %t.bin 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -fuse-ld= -mlinker-version=262 \
+// RUN:   -O1 -o %t.bin 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -fuse-ld=lld -mlinker-version=262 \
 // RUN:   -O1 -o %t.bin 2>&1 | FileCheck -check-prefix=LINK_NODEDUP %s
-// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -mlinker-version=262 \
+// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -fuse-ld= -mlinker-version=262 \
+// RUN:   -O2 -o %t.bin 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
+// RUN: %clang -target x86_64-apple-darwin10 %t.o -### -fuse-ld=lld -mlinker-version=262 \
 // RUN:   -O2 -o %t.bin 2>&1 | FileCheck -check-prefix=LINK_DEDUP %s
 
 // LINK_NODEDUP: {{ld(.exe)?"}}
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ 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,9 @@
     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 and lld run the deduplicate pass by default.
+  if ((Version >= VersionTuple(262) || LinkerIsLLD) &&
+      shouldLinkerNotDedup(C.getJobs().empty(), Args))
     CmdArgs.push_back("-no_deduplicate");
 
   // Derived from the "link" spec.
@@ -368,6 +369,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");
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to