[lld] [MachO LLD] Respect -all_load with --start-lib --end-lib style archives (PR #93993)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 10:40:48 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-macho

@llvm/pr-subscribers-lld

Author: Nuri Amari (NuriAmari)

<details>
<summary>Changes</summary>

The -all_load flag is intended to force the linker to load all lazy members, but doesn't do so if the archive is specified with --start-lib, --end-lib flags. This patch makes it so that -all_load also applies in this case.

---
Full diff: https://github.com/llvm/llvm-project/pull/93993.diff


2 Files Affected:

- (modified) lld/MachO/Driver.cpp (+3-2) 
- (modified) lld/test/MachO/start-lib.s (+5) 


``````````diff
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 4ee6a907b2f46..9a05e5532603a 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1169,7 +1169,8 @@ static void createFiles(const InputArgList &args) {
 
     switch (opt.getID()) {
     case OPT_INPUT:
-      addFile(rerootPath(arg->getValue()), LoadType::CommandLine, isLazy);
+      addFile(rerootPath(arg->getValue()), LoadType::CommandLine,
+              isLazy && !config->allLoad);
       break;
     case OPT_needed_library:
       if (auto *dylibFile = dyn_cast_or_null<DylibFile>(
@@ -1189,7 +1190,7 @@ static void createFiles(const InputArgList &args) {
         dylibFile->forceWeakImport = true;
       break;
     case OPT_filelist:
-      addFileList(arg->getValue(), isLazy);
+      addFileList(arg->getValue(), isLazy && !config->allLoad);
       break;
     case OPT_force_load:
       addFile(rerootPath(arg->getValue()), LoadType::CommandLineForce);
diff --git a/lld/test/MachO/start-lib.s b/lld/test/MachO/start-lib.s
index 2da940c929490..09df292e13fa8 100644
--- a/lld/test/MachO/start-lib.s
+++ b/lld/test/MachO/start-lib.s
@@ -86,6 +86,11 @@
 # RUN: not %lld --end-lib 2>&1 | FileCheck %s --check-prefix=STRAY
 # STRAY: error: stray --end-lib
 
+# RUN: %lld -dylib --start-lib %t/1.bc %t/2.o --end-lib -all_load -o %t/out
+# RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=ALL-LOAD %s
+# ALL-LOAD-DAG: _foo
+# ALL-LOAD-DAG: _bar
+
 #--- main.s
 .globl _main
 _main:

``````````

</details>


https://github.com/llvm/llvm-project/pull/93993


More information about the llvm-commits mailing list