[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 11:51:58 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:

This may be true now, but we don't know if it will always be true.

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


More information about the cfe-commits mailing list