[PATCH] D117629: [lld-macho] Implement -noall_load

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 18 17:19:45 PST 2022


keith created this revision.
Herald added a subscriber: dang.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
keith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117629

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


Index: lld/test/MachO/archive.s
===================================================================
--- lld/test/MachO/archive.s
+++ lld/test/MachO/archive.s
@@ -25,13 +25,17 @@
 # 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
+# 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
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -223,6 +223,9 @@
 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>;
@@ -989,10 +992,6 @@
     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">;
 
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1295,7 +1295,7 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117629.401056.patch
Type: text/x-patch
Size: 2530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220119/92069d79/attachment.bin>


More information about the llvm-commits mailing list