diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -168,6 +168,7 @@ bool demangle = false; bool deadStrip = false; bool errorForArchMismatch = false; + bool ignoreAutoLink = false; PlatformInfo platformInfo; llvm::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 @@ -463,6 +463,9 @@ // flags. This directly parses the flags instead of using the standard argument // parser to improve performance. void macho::parseLCLinkerOption(InputFile *f, unsigned argc, StringRef data) { + if (config->ignoreAutoLink) + return; + SmallVector argv; size_t offset = 0; for (unsigned i = 0; i < argc && offset < data.size(); ++i) { @@ -1539,6 +1542,7 @@ config->forceExactCpuSubtypeMatch = getenv("LD_DYLIB_CPU_SUBTYPES_MUST_MATCH"); config->objcStubsMode = getObjCStubsMode(args); + config->ignoreAutoLink = args.hasArg(OPT_ignore_auto_link); for (const Arg *arg : args.filtered(OPT_alias)) { config->aliasedSymbols.push_back( diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -991,6 +991,9 @@ MetaVarName<"">, HelpText<"Specifies a LC_DYLD_ENVIRONMENT variable value pair.">, Group; +def ignore_auto_link : Flag<["-"], "ignore_auto_link">, + HelpText<"Ignore LC_LINKER_OPTIONs">, + Group; def grp_deprecated : OptionGroup<"deprecated">, HelpText<"DEPRECATED">; @@ -1270,10 +1273,6 @@ HelpText<"This option is undocumented in ld64">, Flags<[HelpHidden]>, Group; -def ignore_auto_link : Flag<["-"], "ignore_auto_link">, - HelpText<"This option is undocumented in ld64">, - Flags<[HelpHidden]>, - Group; def ignore_optimization_hints : Flag<["-"], "ignore_optimization_hints">, HelpText<"Ignore Linker Optimization Hints">, Group; 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 @@ -12,6 +12,9 @@ ; FRAME-NEXT: cmdsize ; FRAME-NEXT: name /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation +; RUN: not %lld %t/framework.o -o %t/frame_no_autolink -ignore_auto_link 2>&1 | FileCheck --check-prefix=NO_AUTOLINK %s +; NO_AUTOLINK: error: undefined symbol: __CFBigNumGetInt128 + ; RUN: llvm-as %t/l.ll -o %t/l.o ;; The dynamic call to _CFBigNumGetInt128 uses dyld_stub_binder, ;; which needs -lSystem from LC_LINKER_OPTION to get resolved.