Flang (Target: x86_64-unknown-linux-gnu) linking error with REAL16 types, missing __truncsfhf2
Some programs with REAL(REAL16) types fail to link unless "-lclang_rt.builtins" is appended to the command line. Reproducer:
Program exhibit_hp
Use iso_fortran_env, only:real16
Real(real16) x
Integer a
a = -12344
x = a
Print *,x
End Program
The missing references seen are __extendhfsf2 __extendhftf2 __truncdfhf2 __truncsfhf2 __trunctfhf2 .
In AddLibgcc of clang/lib/Driver/ToolChains/CommonArgs.cpp, we see the line
if (D.IsFlangMode() && TC.getArch() == llvm::Triple::aarch64) {
which looks like it needs to be modified to include the x86_64 target.
@llvm/issue-subscribers-flang-driver
Author: Theodore-Thomas Tsikas (amd-thtsikas)
Program exhibit_hp
Use iso_fortran_env, only:real16
Real(real16) x
Integer a
a = -12344
x = a
Print *,x
End Program
The missing references seen are __extendhfsf2 __extendhftf2 __truncdfhf2 __truncsfhf2 __trunctfhf2 .
In AddLibgcc of clang/lib/Driver/ToolChains/CommonArgs.cpp, we see the line
if (D.IsFlangMode() && TC.getArch() == llvm::Triple::aarch64) {
which looks like it needs to be modified to include the x86_64 target.
It depends on the version of GCC toolchain that is used by Flang link step. I believe these APIs were defined in libgcc around version 12.0.
At the same time, I do not know what guarantees LLVM provides about ABI compatibility for the libgcc versions of these APIs and clang_rt.builtins versions (e.g. see https://github.com/llvm/llvm-project/issues/56854).
So it may be a good idea to link in clang_rt.builtins before libgcc.
FWIW, clang supports --rtlib=compiler-rt option that drops all gcc libraries at link time.