Skip to content

Commit

Permalink
[flang][driver] Don't use -whole-archive on Darwin (#75393)
Browse files Browse the repository at this point in the history
Direct follow-up of #73124 - the linker on Darwin does not support
`-whole-archive`, so that needs to be removed from the linker
invocation.

For context:
  * #73124
  • Loading branch information
banach-space committed Dec 14, 2023
1 parent d8941df commit 1b6c828
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,24 +1132,30 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
// --whole-archive flag to the link line. If it's not, add a proper
// --whole-archive/--no-whole-archive bracket to the link line.
bool WholeArchiveActive = false;
for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
if (Arg)
for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA)) {
if (Arg) {
for (StringRef ArgValue : Arg->getValues()) {
if (ArgValue == "--whole-archive")
WholeArchiveActive = true;
if (ArgValue == "--no-whole-archive")
WholeArchiveActive = false;
}
}
}

if (!WholeArchiveActive)
// TODO: Find an equivalent of `--whole-archive` for Darwin.
if (!WholeArchiveActive && !TC.getTriple().isMacOSX()) {
CmdArgs.push_back("--whole-archive");
CmdArgs.push_back("-lFortran_main");
if (!WholeArchiveActive)
CmdArgs.push_back("-lFortran_main");
CmdArgs.push_back("--no-whole-archive");
} else {
CmdArgs.push_back("-lFortran_main");
}

// Perform regular linkage of the remaining runtime libraries.
CmdArgs.push_back("-lFortranRuntime");
CmdArgs.push_back("-lFortranDecimal");
}
// Perform regular linkage of the remaining runtime libraries.
CmdArgs.push_back("-lFortranRuntime");
CmdArgs.push_back("-lFortranDecimal");
} else {
if (LinkFortranMain) {
unsigned RTOptionID = options::OPT__SLASH_MT;
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Driver/no-duplicate-main.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! UNSUPPORTED: system-windows
! UNSUPPORTED: system-windows, system-darwin

! RUN: %flang -x ir -o %t.c-object -c %S/Inputs/no_duplicate_main.ll
! RUN: %flang -o %t -c %s
Expand Down

0 comments on commit 1b6c828

Please sign in to comment.