Skip to content

Commit 1b6c828

Browse files
authored
[flang][driver] Don't use -whole-archive on Darwin (#75393)
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
1 parent d8941df commit 1b6c828

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,24 +1132,30 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
11321132
// --whole-archive flag to the link line. If it's not, add a proper
11331133
// --whole-archive/--no-whole-archive bracket to the link line.
11341134
bool WholeArchiveActive = false;
1135-
for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
1136-
if (Arg)
1135+
for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA)) {
1136+
if (Arg) {
11371137
for (StringRef ArgValue : Arg->getValues()) {
11381138
if (ArgValue == "--whole-archive")
11391139
WholeArchiveActive = true;
11401140
if (ArgValue == "--no-whole-archive")
11411141
WholeArchiveActive = false;
11421142
}
1143+
}
1144+
}
11431145

1144-
if (!WholeArchiveActive)
1146+
// TODO: Find an equivalent of `--whole-archive` for Darwin.
1147+
if (!WholeArchiveActive && !TC.getTriple().isMacOSX()) {
11451148
CmdArgs.push_back("--whole-archive");
1146-
CmdArgs.push_back("-lFortran_main");
1147-
if (!WholeArchiveActive)
1149+
CmdArgs.push_back("-lFortran_main");
11481150
CmdArgs.push_back("--no-whole-archive");
1151+
} else {
1152+
CmdArgs.push_back("-lFortran_main");
1153+
}
1154+
1155+
// Perform regular linkage of the remaining runtime libraries.
1156+
CmdArgs.push_back("-lFortranRuntime");
1157+
CmdArgs.push_back("-lFortranDecimal");
11491158
}
1150-
// Perform regular linkage of the remaining runtime libraries.
1151-
CmdArgs.push_back("-lFortranRuntime");
1152-
CmdArgs.push_back("-lFortranDecimal");
11531159
} else {
11541160
if (LinkFortranMain) {
11551161
unsigned RTOptionID = options::OPT__SLASH_MT;

flang/test/Driver/no-duplicate-main.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! UNSUPPORTED: system-windows
1+
! UNSUPPORTED: system-windows, system-darwin
22

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

0 commit comments

Comments
 (0)