[lld] [MachO LLD] Respect -all_load with --start-lib --end-lib style archives (PR #93993)
Nuri Amari via llvm-commits
llvm-commits at lists.llvm.org
Fri May 31 10:36:12 PDT 2024
https://github.com/NuriAmari created https://github.com/llvm/llvm-project/pull/93993
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.
>From 6b8c03a465a5a9787d6c15835e65677981c6042d Mon Sep 17 00:00:00 2001
From: Nuri Amari <nuriamari at fb.com>
Date: Fri, 31 May 2024 10:25:00 -0700
Subject: [PATCH] [MachO LLD] Respect -all_load with --start-lib --end-lib
style archives
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.
---
lld/MachO/Driver.cpp | 5 +++--
lld/test/MachO/start-lib.s | 5 +++++
2 files changed, 8 insertions(+), 2 deletions(-)
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:
More information about the llvm-commits
mailing list