[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

Krzysztof Parzyszek via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 27 12:00:45 PST 2023


================
@@ -977,14 +977,51 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain &TC,
+void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
                                   llvm::opt::ArgStringList &CmdArgs) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+    // --whole-archive needs to be part of the link line to make sure
+    // that the main() function from Fortran_main.a is pulled in by
+    // the linker.
+    //
+    // We are using this --whole-archive/--no-whole-archive bracket w/o
+    // any further checks, because -Wl,--whole-archive at the flang
+    // driver's link line will not sucessfully complete, unless the user
+    // correctly specified -Wl,--whole-archive/-Wl,--no-whole-archive
+    // (e.g., -Wl,--whole-archive -ldummy -Wl,--no-whole-archive).
----------------
kparzysz wrote:

What I meant is that it's not clear that we can actually skip this check and get away with it forever.  Is that guaranteed?

https://github.com/llvm/llvm-project/pull/73124


More information about the cfe-commits mailing list