Skip to content

[MachO LLD] Respect -all_load with --start-lib --end-lib style archives #93993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lld/MachO/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions lld/test/MachO/start-lib.s
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading