@@ -1116,33 +1116,37 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC,
1116
1116
return true ;
1117
1117
}
1118
1118
1119
+ // TODO: add -fno-fortran-main option and check it in this function.
1119
1120
void tools::addFortranRuntimeLibs (const ToolChain &TC, const ArgList &Args,
1120
1121
llvm::opt::ArgStringList &CmdArgs) {
1121
1122
// These are handled earlier on Windows by telling the frontend driver to add
1122
1123
// the correct libraries to link against as dependents in the object file.
1123
1124
if (!TC.getTriple ().isKnownWindowsMSVCEnvironment ()) {
1124
- // The --whole-archive option needs to be part of the link line to
1125
- // make sure that the main() function from Fortran_main.a is pulled
1126
- // in by the linker. Determine if --whole-archive is active when
1127
- // flang will try to link Fortran_main.a. If it is, don't add the
1128
- // --whole-archive flag to the link line. If it's not, add a proper
1129
- // --whole-archive/--no-whole-archive bracket to the link line.
1130
- bool WholeArchiveActive = false ;
1131
- for (auto *Arg : Args.filtered (options::OPT_Wl_COMMA))
1132
- if (Arg)
1133
- for (StringRef ArgValue : Arg->getValues ()) {
1134
- if (ArgValue == " --whole-archive" )
1135
- WholeArchiveActive = true ;
1136
- if (ArgValue == " --no-whole-archive" )
1137
- WholeArchiveActive = false ;
1138
- }
1139
-
1140
- if (!WholeArchiveActive)
1141
- CmdArgs.push_back (" --whole-archive" );
1142
- CmdArgs.push_back (" -lFortran_main" );
1143
- if (!WholeArchiveActive)
1144
- CmdArgs.push_back (" --no-whole-archive" );
1125
+ // if -fno-fortran-main has been passed, skip linking Fortran_main.a
1126
+ bool DontLinkFortranMain = Args.getLastArg (options::OPT_no_fortran_main) != nullptr ;
1127
+ if (!DontLinkFortranMain) {
1128
+ // The --whole-archive option needs to be part of the link line to
1129
+ // make sure that the main() function from Fortran_main.a is pulled
1130
+ // in by the linker. Determine if --whole-archive is active when
1131
+ // flang will try to link Fortran_main.a. If it is, don't add the
1132
+ // --whole-archive flag to the link line. If it's not, add a proper
1133
+ // --whole-archive/--no-whole-archive bracket to the link line.
1134
+ bool WholeArchiveActive = false ;
1135
+ for (auto *Arg : Args.filtered (options::OPT_Wl_COMMA))
1136
+ if (Arg)
1137
+ for (StringRef ArgValue : Arg->getValues ()) {
1138
+ if (ArgValue == " --whole-archive" )
1139
+ WholeArchiveActive = true ;
1140
+ if (ArgValue == " --no-whole-archive" )
1141
+ WholeArchiveActive = false ;
1142
+ }
1145
1143
1144
+ if (!WholeArchiveActive)
1145
+ CmdArgs.push_back (" --whole-archive" );
1146
+ CmdArgs.push_back (" -lFortran_main" );
1147
+ if (!WholeArchiveActive)
1148
+ CmdArgs.push_back (" --no-whole-archive" );
1149
+ }
1146
1150
// Perform regular linkage of the remaining runtime libraries.
1147
1151
CmdArgs.push_back (" -lFortranRuntime" );
1148
1152
CmdArgs.push_back (" -lFortranDecimal" );
0 commit comments