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

Leandro Lupori via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 13 06:31:12 PST 2023


luporl wrote:

Since this patch I can't build binaries with flang-new on macOS anymore:
```
$ /Users/leandro.lupori/git/flang-luporl/buildr/bin/flang-new -v -fopenmp -o stest.exe stest.o -L/Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/lib
flang-new version 18.0.0git (git at github.com:luporl/llvm-project.git bfe1630bdda6714721e2e70a2327226ab7a94626)
Target: arm64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /Users/leandro.lupori/git/flang-luporl/buildr/bin
 "/usr/bin/ld" -demangle -lto_library /Users/leandro.lupori/git/flang-luporl/buildr/lib/libLTO.dylib -dynamic -arch arm64 -platform_version macos 14.0.0 14.0.0 -mllvm -enable-linkonceodr-outlining -o stest.exe -L/Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/lib stest.o -L/Users/leandro.lupori/git/flang-luporl/buildr/lib --whole-archive -lFortran_main --no-whole-archive -lFortranRuntime -lFortranDecimal -lomp -L/Users/leandro.lupori/git/flang-luporl/buildr/lib -lSystem
ld: unknown options: --whole-archive --no-whole-archive
flang-new: error: linker command failed with exit code 1 (use -v to see invocation)
```

The command line above works fine when I revert this patch (and #74139, to avoid dealing with conflicts).

I can also workaround it by adding `-fno-fortran-main` and `-lFortran_main` to the command line.

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


More information about the cfe-commits mailing list