mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 07:06:38 +00:00
[MachO LLD] Respect -all_load with --start-lib --end-lib style archives (#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. The `-all_load` flag is global, that is it can be placed anywhere in the linker invocation, and it affects the load behavior of all conventional archives listed. Unlike ELF's --whole-archive, the user need not necessarily have access to the entire linker invocation to reasonably make use of the flag. The user can supply `-all_load` to a build system without inspecting the rest of the linker invocation. To make the behavior of `--start-lib` style archives consistent with regular archives, this patch makes it so that -all_load also applies in this case.
This commit is contained in:
parent
16832eb585
commit
1697030d9d
@ -1162,6 +1162,8 @@ static void createFiles(const InputArgList &args) {
|
||||
// This loop should be reserved for options whose exact ordering matters.
|
||||
// Other options should be handled via filtered() and/or getLastArg().
|
||||
bool isLazy = false;
|
||||
// If we've processed an opening --start-lib, without a matching --end-lib
|
||||
bool inLib = false;
|
||||
for (const Arg *arg : args) {
|
||||
const Option &opt = arg->getOption();
|
||||
warnIfDeprecatedOption(opt);
|
||||
@ -1219,13 +1221,16 @@ static void createFiles(const InputArgList &args) {
|
||||
LoadType::CommandLine);
|
||||
break;
|
||||
case OPT_start_lib:
|
||||
if (isLazy)
|
||||
if (inLib)
|
||||
error("nested --start-lib");
|
||||
isLazy = true;
|
||||
inLib = true;
|
||||
if (!config->allLoad)
|
||||
isLazy = true;
|
||||
break;
|
||||
case OPT_end_lib:
|
||||
if (!isLazy)
|
||||
if (!inLib)
|
||||
error("stray --end-lib");
|
||||
inLib = false;
|
||||
isLazy = false;
|
||||
break;
|
||||
default:
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user