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

David Truby via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 27 07:44:15 PST 2023


DavidTruby wrote:

I think for Windows the easy thing to do here is just to add `/WHOLEARCHIVE:...` here anyway, using the same logic as in processVSRuntimeLibrary(); E.g
```
void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args, //need to add args here so we can search it
                                  llvm::opt::ArgStringList &CmdArgs) {
  if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
  // non-windows stuff
  } else {
      if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
      RTOptionID = llvm::StringSwitch<unsigned>(rtl->getValue())
                       .Case("static", options::OPT__SLASH_MT)
                       .Case("static_dbg", options::OPT__SLASH_MTd)
                       .Case("dll", options::OPT__SLASH_MD)
                       .Case("dll_dbg", options::OPT__SLASH_MDd)
                       .Default(options::OPT__SLASH_MT);
         switch (RTOptionID) {
         case options::OPT__SLASH_MT:
           CmdArgs.push_back("/WHOLEARCHIVE:Fortran_main.static.lib");
///etc
  }
  ```
I haven't actually tested this code but it maybe gives an idea of what needs doing?

The "correct" thing to do would probably be to add the /WHOLEARCHIVE directive as a linker directive in the object file (like we do for /DEFAULTLIB:Fortran_main) but that would require a bit more hooking up to pass that all the way through to creating an `llvm.linker_options` MLIR operation. I think the above should probably suffice at least for now.

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


More information about the cfe-commits mailing list