[PATCH] D47994: [Darwin] Do not error on '-lto_library' option

Brian Gesiak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 10 11:34:02 PDT 2018


modocache created this revision.
modocache added reviewers: ruiu, smeenai.
Herald added subscribers: steven_wu, inglorion, mehdi_amini.

Any invocation of `clang -fuse-ld=lld` that results in a link command
on a macOS host currently fails, because the Darwin lld driver does not
recognize the `-lto_library` option that Clang passes it. Fix the error
by having the Darwin driver ignore the option.

The Clang driver's macOS toolchain is written such that it will always
pass the `-lto_library` option to the linker invocation on a macOS host.
And although the DarwinLdDriver is written to ignore any unknown arguments,
because `-lto_library` begins with `-l`, the DarwinLdDriver interprets it
as a library search command, for a library named "to_library". When the
DarwinLdDriver is unable to find a library specified via `-l`, it exits
with a hard error. This causes any invocation of `clang -fuse-ld=lld`
that results in a link command on a macOS host to fail with an error.

To fix the issue, I considered two alternatives:

1. Modify the Clang Darwin toolchain to only pass `-lto_library` if lld is *not* being used. lld doesn't support LTO on Darwin anyway, so it can't use the option. However, I opted against this because, if and when lld *does* support LTO on Darwin, I'll have to make another commit to Clang in order to get it to pass the option to lld again.
2. Modify the Darwin lld driver to ignore the `-lto_library` option. Just in case users may take this to mean LTO is supported, I also added a warning. If and when lld supports LTO on Darwin, the same commit that adds support for this option can remove the warning.

Option (2) seemed better to me, and is the rationale behind this commit.

Test Plan: check-lld


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D47994

Files:
  lib/Driver/DarwinLdDriver.cpp
  lib/Driver/DarwinLdOptions.td
  test/darwin/cmdline-lto_library.objtxt


Index: test/darwin/cmdline-lto_library.objtxt
===================================================================
--- /dev/null
+++ test/darwin/cmdline-lto_library.objtxt
@@ -0,0 +1,11 @@
+# RUN: ld64.lld -arch x86_64 -lto_library %t -print-atoms -r %s 2>&1 | FileCheck %s
+#
+# Test that the -lto_library option results in a warning, not an error.
+#
+
+# CHECK: warning: -lto_library being ignored
+
+--- !native
+defined-atoms:
+    - name:              _foo
+...
Index: lib/Driver/DarwinLdOptions.td
===================================================================
--- lib/Driver/DarwinLdOptions.td
+++ lib/Driver/DarwinLdOptions.td
@@ -94,6 +94,9 @@
      HelpText<"Disables the optimisation which merges Objective-C categories "
               "on a class in to the class itself.">,
      Group<grp_opts>;
+def lto_library : Separate<["-"], "lto_library">,
+    MetaVarName<"<path>">,
+    HelpText<"Not yet supported option for LTO">, Group<grp_opts>;
 
 // main executable options
 def grp_main : OptionGroup<"opts">, HelpText<"MAIN EXECUTABLE OPTIONS">;
Index: lib/Driver/DarwinLdDriver.cpp
===================================================================
--- lib/Driver/DarwinLdDriver.cpp
+++ lib/Driver/DarwinLdDriver.cpp
@@ -738,6 +738,12 @@
     return false;
   }
 
+  // Handle not-yet-supported LTO options
+  if (parsedArgs.getLastArg(OPT_lto_library)) {
+    diagnostics << "warning: -lto_library being ignored. LTO is not yet "
+                   "supported for Mach-O targets\n";
+  }
+
   // Handle -pie or -no_pie
   if (llvm::opt::Arg *pie = parsedArgs.getLastArg(OPT_pie, OPT_no_pie)) {
     switch (ctx.outputMachOType()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47994.150657.patch
Type: text/x-patch
Size: 1656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180610/f8a6e8fc/attachment.bin>


More information about the llvm-commits mailing list