[flang-commits] [clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)
Michael Klemm via flang-commits
flang-commits at lists.llvm.org
Mon Nov 27 12:17:37 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).
----------------
mjklemm wrote:
Guaranteed might be too much. :-) But at least it's common sense that --whole-archive will have a good chance of breaking any link line, unless the user closes it with --no-whole-archive right after the desired library.
https://github.com/llvm/llvm-project/pull/73124
More information about the flang-commits
mailing list