diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -174,6 +174,10 @@ // exist. This allows users to ignore the specific invalid options in the case // they can't easily fix them. llvm::StringSet<> ignoreAutoLinkOptions; + // This is the more relaxed option to ignore all framework not found errors. + // In some cases, it's not practical to find and list all the framework names + // with --ignore-auto-link-options. + bool ignoreAutoLinkErrors = false; PlatformInfo platformInfo; std::optional secondaryPlatformInfo; NamespaceKind namespaceKind = NamespaceKind::twolevel; diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -456,6 +456,8 @@ } return; } + if (loadType == LoadType::LCLinkerOption && config->ignoreAutoLinkErrors) + return; error("framework not found for -framework " + name); } @@ -1569,6 +1571,8 @@ for (const Arg *arg : args.filtered(OPT_ignore_auto_link_option)) config->ignoreAutoLinkOptions.insert(arg->getValue()); + config->ignoreAutoLinkErrors = args.hasArg(OPT_ignore_auto_link_errors); + for (const Arg *arg : args.filtered(OPT_alias)) { config->aliasedSymbols.push_back( std::make_pair(arg->getValue(0), arg->getValue(1))); diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -96,11 +96,14 @@ HelpText<"Print a symbol order specified by --call-graph-profile-sort into the specified file">, Group; def ignore_auto_link_option : Separate<["--"], "ignore-auto-link-option">, - Group; + Group; def ignore_auto_link_option_eq : Joined<["--"], "ignore-auto-link-option=">, Alias(ignore_auto_link_option)>, HelpText<"Ignore a single auto-linked library or framework. Useful to ignore invalid options that ld64 ignores">, Group; +def ignore_auto_link_errors : Flag<["-"], "ignore_auto_link_errors">, + HelpText<"Ignore framework or library not found errors if they are loaded via LC_LINKER_OPTIONS">, + Group; // This is a complete Options.td compiled from Apple's ld(1) manpage // dated 2018-03-07 and cross checked with ld64 source code in repo diff --git a/lld/test/MachO/lc-linker-option.ll b/lld/test/MachO/lc-linker-option.ll --- a/lld/test/MachO/lc-linker-option.ll +++ b/lld/test/MachO/lc-linker-option.ll @@ -134,6 +134,16 @@ ; RUN: %lld %t/main -F %t -framework Foo -framework Foo -o /dev/null ; RUN: %lld -F %t -framework Foo -framework Foo %t/main -o /dev/null +;; Checks that "framework not found" errors from LC_LINKER_OPTIONS are not emitted when +;; -ignore_auto_link_errors is set. +; RUN: %lld -ignore_auto_link_errors -ObjC %t/load-framework-foo.o %t/main.o -o %t/main-no-foo.out +; RUN: llvm-objdump --macho --syms %t/main-no-foo.out | FileCheck %s --check-prefix=SYMS_NO_FOO + +;; Verify that nothing from the framework is included. +; SYMS_NO_FOO: SYMBOL TABLE: +; SYMS_NO_FOO-NEXT: g F __TEXT,__text _main +; SYMS_NO_FOO-NOT: g O __DATA,__objc_data _OBJC_CLASS_$_TestClass + ;--- framework.ll target triple = "x86_64-apple-macosx10.15.0" target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"