[flang][driver] Remove Fortain_main static library from linking stages (#75816)
commit9d6837d595719904720e5ff68ec1f1a2665bdc2f
authorMichael Klemm <michael.klemm@amd.com>
Mon, 25 Dec 2023 18:15:00 +0000 (25 19:15 +0100)
committerGitHub <noreply@github.com>
Mon, 25 Dec 2023 18:15:00 +0000 (25 19:15 +0100)
tree757f3b84cfb9ab7432d9f75c3938f116c4feb078
parent95bdbc8a28c5f5e91ea25bf246788b49aa6ec160
[flang][driver] Remove Fortain_main static library from linking stages (#75816)

At present, when building static or shared libraries, Flang adds
`-lFortran_main.a` (or `/WHOLEARCHIVE:Fortran.*.lib` pon Windows) to the
link line. This leads to the problem that `_QQmain` and
`_QQEnvironmentDefaults` (as of the time of this PR) are symbols marked
as used, while `main` is being defined. This should not happen and this
PR fixes this by detecting if `-shared` or `-static` is used on the
Flang command line and removing the static `Fortran_main` library.

---------

Co-authored-by: kkwli <kkwli@users.noreply.github.com>
clang/lib/Driver/ToolChains/CommonArgs.cpp
flang/docs/FlangDriver.md
flang/test/Driver/dynamic-linker.f90