[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 07:54:41 PST 2023


mjklemm 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?

Yeah, that's pretty much what I was doing before the code was refactored with this commit:

```
commit 0bc7cd4d51226344a54da5929d87184730e73e83
Author: David Truby <david.truby at arm.com>
Date:   Thu Nov 23 14:19:57 2023 +0000

    [flang] Add runtimes using --dependent-lib on MSVC targets (#72519)
```

So, I'd have to replicate part of the code that was removed from `lib/Driver/ToolChains/CommonArgs.cpp` to get `/WHOLEARCHIVE` back into the link line?



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


More information about the flang-commits mailing list