[lld] 67090e3 - [lld-macho] Implement -noall_load

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 19 13:31:13 PST 2022


Author: Keith Smiley
Date: 2022-01-19T13:12:18-08:00
New Revision: 67090e3446e8f92f9a26f90a38263e344da6d875

URL: https://github.com/llvm/llvm-project/commit/67090e3446e8f92f9a26f90a38263e344da6d875
DIFF: https://github.com/llvm/llvm-project/commit/67090e3446e8f92f9a26f90a38263e344da6d875.diff

LOG: [lld-macho] Implement -noall_load

This flag is the default, so in ld64 it is not implemented, but it can
be useful to negate previous -all_load arguments. Specifically if your
build system has some global linker flags, that you may want to negate
for specific links. We use something like this today to make sure some
C++ symbols are automatically discovered for all links, which passing
-all_load hides.

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

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/MachO/Options.td
    lld/test/MachO/archive.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 769267008d8a9..a903add32e5ad 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1290,7 +1290,7 @@ bool macho::link(ArrayRef<const char *> 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 1183d0ebffa5d..3d1d97641d719 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<grp_libs>;
+def noall_load : Flag<["-"], "noall_load">,
+    HelpText<"Don't load all static members from archives, this is the default, this negates -all_load">,
+    Group<grp_libs>;
 def ObjC : Flag<["-"], "ObjC">,
     HelpText<"Load all members of static archives that are an Objective-C class or category.">,
     Group<grp_libs>;
@@ -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<grp_deprecated>;
-def noall_load : Flag<["-"], "noall_load">,
-    HelpText<"Unnecessary option: this is already the default">,
-    Flags<[HelpHidden]>,
-    Group<grp_deprecated>;
 
 def grp_obsolete : OptionGroup<"obsolete">, HelpText<"OBSOLETE">;
 

diff  --git a/lld/test/MachO/archive.s b/lld/test/MachO/archive.s
index 3a946c0ab9352..c324be0ac579f 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


        


More information about the llvm-commits mailing list