Skip to content

Commit 95b4db0

Browse files
committed
[flang][driver] Don't use -whole-archive on Darwin
Direct follow-up of #7312 - the linker on Darwin does not support `-whole-archive`, so that needs to be removed from the linker invocation. For context: * #7312
1 parent 07e3c24 commit 95b4db0

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,24 +1132,29 @@ 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+
if (!WholeArchiveActive && !TC.getTriple().isMacOSX()) {
11451147
CmdArgs.push_back("--whole-archive");
1146-
CmdArgs.push_back("-lFortran_main");
1147-
if (!WholeArchiveActive)
1148+
CmdArgs.push_back("-lFortran_main");
11481149
CmdArgs.push_back("--no-whole-archive");
1150+
} else {
1151+
CmdArgs.push_back("-lFortran_main");
1152+
}
1153+
1154+
// Perform regular linkage of the remaining runtime libraries.
1155+
CmdArgs.push_back("-lFortranRuntime");
1156+
CmdArgs.push_back("-lFortranDecimal");
11491157
}
1150-
// Perform regular linkage of the remaining runtime libraries.
1151-
CmdArgs.push_back("-lFortranRuntime");
1152-
CmdArgs.push_back("-lFortranDecimal");
11531158
} else {
11541159
if (LinkFortranMain) {
11551160
unsigned RTOptionID = options::OPT__SLASH_MT;

0 commit comments

Comments
 (0)