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

Michael Klemm via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 1 10:08:46 PST 2023


mjklemm wrote:

The above fails with ifort/ifx:

```
[2023-12-01 19:00:56 CET] iris ~/tm*/fo*/ftn_main_dupes [0:0] (main *=)> cat > ftn.f90
function pow(a, b)
  real :: a, b, pow
  pow = a ** b
end function
[2023-12-01 19:01:03 CET] iris ~/tm*/fo*/ftn_main_dupes [0:0] (main *=)> !if
[2023-12-01 19:01:04 CET] iris ~/tm*/fo*/ftn_main_dupes [0:0] (main *=)> ifx -o ftn.o -c ftn.f90 && icc -o prg.o -c prg.c && ifx -o bla prg.o ftn.o
icc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and will be removed from product release in the second half of 2023. The Intel(R) oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward. Please transition to use this compiler. Use '-diag-disable=10441' to disable this message.
ld: prg.o: in function `main':
prg.c:(.text+0x0): multiple definition of `main'; /net/software/x86_64/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/for_main.o:for_main.c:(.text+0x0): first defined here
ld: /net/software/x86_64/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/for_main.o: in function `main':
for_main.c:(.text+0x19): undefined reference to `MAIN__'
[2023-12-01 19:01:24 CET] [1] iris ~/tm*/fo*/ftn_main_dupes [0:0] (main *=)> cat prg.c
int main(void) {
  // call fortran code
  return 0;
}
[2023-12-01 19:01:27 CET] iris ~/tm*/fo*/ftn_main_dupes [0:0] (main *=)> cat ftn.f90
function pow(a, b)
  real :: a, b, pow
  pow = a ** b
end function
[2023-12-01 19:01:31 CET] iris ~/tm*/fo*/ftn_main_dupes [0:0] (main *=)> ifx -o ftn.o -c ftn.f90 && icc -o prg.o -c prg.c && ifx -o bla prg.o ftn.o
icc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and will be removed from product release in the second half of 2023. The Intel(R) oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward. Please transition to use this compiler. Use '-diag-disable=10441' to disable this message.
ld: prg.o: in function `main':
prg.c:(.text+0x0): multiple definition of `main'; /net/software/x86_64/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/for_main.o:for_main.c:(.text+0x0): first defined here
ld: /net/software/x86_64/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/for_main.o: in function `main':
for_main.c:(.text+0x19): undefined reference to `MAIN__'
[2023-12-01 19:01:34 CET] [1] iris ~/tm*/fo*/ftn_main_dupes [0:0] (main *=)> ifort -o ftn.o -c ftn.f90 && icc -o prg.o -c prg.c && ifort -o bla prg.o ftn.o
icc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and will be removed from product release in the second half of 2023. The Intel(R) oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward. Please transition to use this compiler. Use '-diag-disable=10441' to disable this message.
ld: prg.o: in function `main':
prg.c:(.text+0x0): multiple definition of `main'; /net/software/x86_64/oneapi/compiler/2023.1.0/linux/bin/intel64/../../compiler/lib/intel64_lin/for_main.o:for_main.c:(.text+0x0): first defined here
ld: /net/software/x86_64/oneapi/compiler/2023.1.0/linux/bin/intel64/../../compiler/lib/intel64_lin/for_main.o: in function `main':
for_main.c:(.text+0x19): undefined reference to `MAIN__'
```

To get gfortran's behavior one could also use `-Wl,--allow-multiple-definition` which would then allow the linker to pick the C `main` function and ignore the `main` function from Fortran_main.a



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


More information about the cfe-commits mailing list