[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

llvm-svn: 334641
This commit is contained in:
Brian Gesiak 2018-06-13 18:59:14 +00:00
parent 7bec57300c
commit 4fcebf6cf6
2 changed files with 15 additions and 0 deletions

View File

@ -231,6 +231,10 @@ def error_limit : Separate<["-", "--"], "error-limit">,
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">;

View File

@ -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
...