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

2023-12-21 Thread Tom Eccles via cfe-commits

https://github.com/tblah closed https://github.com/llvm/llvm-project/pull/74120
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-12-01 Thread Michael Klemm via cfe-commits

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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-12-01 Thread Michael Klemm via cfe-commits

mjklemm wrote:

> For what it's worth, `armflang` follows gfortran's behavior.

So does the "old legacy flang", which I guess is the basis for armflang.  
AOCC's flang shows the same behavior.


> As there isn't consensus amongst fortran compilers, I'm unsure which behavior 
> we should follow. What do other's think?

I guess, we could agree that the current behavior of flang-new ignoring the 
Fortran program unit is present, is not correct either. :-)

Could please see if `-Wl,--allow-multiple-definition` would help to resolve the 
issue in the application?

https://github.com/llvm/llvm-project/pull/74120
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-12-01 Thread Michael Klemm via cfe-commits

mjklemm wrote:

BTW, flang legacy has this: `  -fno-fortran-main   Don't link in Fortran 
main` 

Adding that command line option might be the right choice.  If everyone agrees, 
I can see if I can get this added.

https://github.com/llvm/llvm-project/pull/74120
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-12-01 Thread Tom Eccles via cfe-commits

tblah wrote:

> Could you please see if `-Wl,--allow-multiple-definition` would help to 
> resolve the issue in the application?

Surprisingly not. 
```
ld.lld: error: undefined symbol: _QQEnvironmentDefaults
>>> referenced by Fortran_main.c
>>>   Fortran_main.c.o:(.text.main+0x8) in archive 
>>> [...]/libFortran_main.a
>>> referenced by Fortran_main.c
>>>   Fortran_main.c.o:(.text.main+0xC) in archive 
>>> [...]/lib/libFortran_main.a

ld.lld: error: undefined symbol: _QQmain
>>> referenced by Fortran_main.c
>>>   Fortran_main.c.o:(.text.main+0x18) in archive 
>>> [...]/lib/libFortran_main.a
flang-new: error: linker command failed with exit code 1 (use -v to see 
invocation)
```

https://github.com/llvm/llvm-project/pull/74120
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits