diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index 769267008d8a94..a903add32e5adb 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1290,7 +1290,7 @@ bool macho::link(ArrayRef argsArr, bool canExitEarly, config->thinLTOCacheDir = args.getLastArgValue(OPT_cache_path_lto); config->thinLTOCachePolicy = getLTOCachePolicy(args); config->runtimePaths = args::getStrings(args, OPT_rpath); - config->allLoad = args.hasArg(OPT_all_load); + config->allLoad = args.hasFlag(OPT_all_load, OPT_noall_load, false); config->archMultiple = args.hasArg(OPT_arch_multiple); config->applicationExtension = args.hasFlag( OPT_application_extension, OPT_no_application_extension, false); diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td index 1183d0ebffa5d1..3d1d97641d7199 100644 --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -227,6 +227,9 @@ def F : JoinedOrSeparate<["-"], "F">, def all_load : Flag<["-"], "all_load">, HelpText<"Load all members of all static archive libraries">, Group; +def noall_load : Flag<["-"], "noall_load">, + HelpText<"Don't load all static members from archives, this is the default, this negates -all_load">, + Group; def ObjC : Flag<["-"], "ObjC">, HelpText<"Load all members of static archives that are an Objective-C class or category.">, Group; @@ -993,10 +996,6 @@ def no_dead_strip_inits_and_terms : Flag<["-"], "no_dead_strip_inits_and_terms"> HelpText<"Unnecessary option: initialization and termination are roots of the dead strip graph, so never dead stripped">, Flags<[HelpHidden]>, Group; -def noall_load : Flag<["-"], "noall_load">, - HelpText<"Unnecessary option: this is already the default">, - Flags<[HelpHidden]>, - Group; def grp_obsolete : OptionGroup<"obsolete">, HelpText<"OBSOLETE">; diff --git a/lld/test/MachO/archive.s b/lld/test/MachO/archive.s index 3a946c0ab93527..c324be0ac579f8 100644 --- a/lld/test/MachO/archive.s +++ b/lld/test/MachO/archive.s @@ -25,13 +25,19 @@ # VISIBLE-NOT: T _undefined # VISIBLE-NOT: T _unused -# RUN: %lld %t/test.a %t/main.o -o %t/all-load -all_load +# RUN: %lld %t/test.a %t/main.o -o %t/all-load -noall_load -all_load # RUN: llvm-nm %t/all-load | FileCheck %s --check-prefix ALL-LOAD # ALL-LOAD: T _bar # ALL-LOAD: T _boo # ALL-LOAD: T _main # ALL-LOAD: T _unused +# RUN: %lld %t/test.a %t/main.o -o %t/no-all-load -all_load -noall_load +# RUN: llvm-nm %t/no-all-load | FileCheck %s --check-prefix NO-ALL-LOAD +# RUN: %lld %t/test.a %t/main.o -o %t/no-all-load-only -noall_load +# RUN: llvm-nm %t/no-all-load-only | FileCheck %s --check-prefix NO-ALL-LOAD +# NO-ALL-LOAD-NOT: T _unused + ## Multiple archives defining the same symbols aren't an issue, due to lazy ## loading # RUN: cp %t/test.a %t/test2.a