[flang][driver] Allow main program to be in an archive
authorShao-Ce SUN <sunshaoce@iscas.ac.cn>
Tue, 25 Apr 2023 07:18:29 +0000 (15:18 +0800)
committerShao-Ce SUN <sunshaoce@iscas.ac.cn>
Fri, 28 Apr 2023 01:53:25 +0000 (09:53 +0800)
commit876df74dd47196a9ca3b4fff21ffb5441491a0a0
tree1ae7dbfe2219971ee9bb3ef8e129e4f6a3b38b6b
parent443d71527be0a052b2f533e4ad540733279ce46b
[flang][driver] Allow main program to be in an archive

Add --undefined=_QQmain to the link line, so that a Fortran main program
will be included in the link job even if it is in an archive (unless we
are building a shared object). For now, this is only applied to the Gnu
toolchain.

We also add a section on the linker invocation to docs/FlangDriver.md.

The new tests require llvm-ar to construct an archive we can include in
the link job. This is a new dependency for flang/test (which already
depends on similar tools such as llvm-objdump).

See discussions in
https://github.com/llvm/llvm-project/issues/54787
which this patch fixes.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D134821
clang/lib/Driver/ToolChains/Gnu.cpp
flang/docs/FlangDriver.md
flang/test/CMakeLists.txt
flang/test/Driver/link-c-main.c [new file with mode: 0644]
flang/test/Driver/link-f90-main.f90 [new file with mode: 0644]
flang/test/Driver/linker-flags.f90