[lld] r334641 - [Darwin] Do not error on '-lto_library' option

Brian Gesiak via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 13 11:59:14 PDT 2018


Author: modocache
Date: Wed Jun 13 11:59:14 2018
New Revision: 334641

URL: http://llvm.org/viewvc/llvm-project?rev=334641&view=rev
Log:
[Darwin] Do not error on '-lto_library' option

Summary:
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

Reviewers: ruiu, smeenai, pcc

Reviewed By: smeenai

Subscribers: JDevlieghere, pcc, mehdi_amini, inglorion, steven_wu, llvm-commits

Differential Revision: https://reviews.llvm.org/D47994

Added:
    lld/trunk/test/darwin/cmdline-lto_library.objtxt
Modified:
    lld/trunk/lib/Driver/DarwinLdOptions.td

Modified: lld/trunk/lib/Driver/DarwinLdOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdOptions.td?rev=334641&r1=334640&r2=334641&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdOptions.td (original)
+++ lld/trunk/lib/Driver/DarwinLdOptions.td Wed Jun 13 11:59:14 2018
@@ -231,6 +231,10 @@ def error_limit : Separate<["-", "--"],
      MetaVarName<"<number>">,
      HelpText<"Maximum number of errors to emit before stopping (0 = no limit)">;
 
+// Ignored options
+def lto_library : Separate<["-"], "lto_library">,
+    MetaVarName<"<path>">,
+    HelpText<"Ignored for compatibility with other linkers">;
 
 // Obsolete options
 def grp_obsolete : OptionGroup<"obsolete">, HelpText<"OBSOLETE OPTIONS">;

Added: lld/trunk/test/darwin/cmdline-lto_library.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/darwin/cmdline-lto_library.objtxt?rev=334641&view=auto
==============================================================================
--- lld/trunk/test/darwin/cmdline-lto_library.objtxt (added)
+++ lld/trunk/test/darwin/cmdline-lto_library.objtxt Wed Jun 13 11:59:14 2018
@@ -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 does not result in an error.
+#
+
+# CHECK-NOT: -lto_library
+
+--- !native
+defined-atoms:
+    - name:              _foo
+...




More information about the llvm-commits mailing list