Bug 2394767 - when compiling simde tests on s390x, clang produces code using __truncsfhf2 and __extendhfsf2 which are not defined in glibc
Summary: when compiling simde tests on s390x, clang produces code using __truncsfhf2 a...
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: llvm
Version: rawhide
Hardware: s390x
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Tom Stellard
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2025-09-12 08:41 UTC by Dominik 'Rathann' Mierzejewski
Modified: 2025-09-12 15:29 UTC (History)
15 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github simd-everywhere simde pull 1297 0 None open Add i686 and clang packit config 2025-09-12 08:41:43 UTC

Description Dominik 'Rathann' Mierzejewski 2025-09-12 08:41:44 UTC
Description of problem:
On s390x, clang version 21.1.0-1.fc44 is producing code that uses __extendhfsf2 but the glibc or other runtime library doesn't implement it. 

Version-Release number of selected component (if applicable):
simde-0.8.4~rc1 (aa5af70a6964db2f630dbb1ce1fe75c1a308e167)
clang-21.1.0-1.fc44
glibc-2.42.9000-5.fc44

How reproducible:
Always.

Steps to Reproduce:
1. See https://github.com/simd-everywhere/simde/tree/master/.packit

Actual results:
...
+ /bin/time -f '=> [%E]' ninja -C build/clang-O2 -v -j 2
ninja: Entering directory `build/clang-O2'
...
[2325/4020] clang  -o test/x86/avx512/reduce-emul-c test/x86/avx512/reduce-emul-c.p/reduce.c.o -Wl,--as-needed -Wl,--no-undefined -O2 -Wl,--start-group -lm -Wl,--end-group
FAILED: [code=1] test/x86/avx512/reduce-emul-c 
clang  -o test/x86/avx512/reduce-emul-c test/x86/avx512/reduce-emul-c.p/reduce.c.o -Wl,--as-needed -Wl,--no-undefined -O2 -Wl,--start-group -lm -Wl,--end-group
/usr/bin/ld: test/x86/avx512/reduce-emul-c.p/reduce.c.o: in function `simde_mm512_reduce_max_ph':
/builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:55:(.text+0x14c): undefined reference to `__truncsfhf2'
/usr/bin/ld: /builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:55:(.text+0x23c): undefined reference to `__extendhfsf2'
/usr/bin/ld: /builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:55:(.text+0x246): undefined reference to `__extendhfsf2'
/usr/bin/ld: test/x86/avx512/reduce-emul-c.p/reduce.c.o: in function `simde_mm512_reduce_min_ph':
/builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:79:(.text+0x36c): undefined reference to `__truncsfhf2'
/usr/bin/ld: /builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:79:(.text+0x45c): undefined reference to `__extendhfsf2'
/usr/bin/ld: /builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:79:(.text+0x466): undefined reference to `__extendhfsf2'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[2326/4020] clang  -o test/x86/avx512/reduce-native-c test/x86/avx512/reduce-native-c.p/reduce.c.o -Wl,--as-needed -Wl,--no-undefined -O2 -Wl,--start-group -lm -Wl,--end-group
FAILED: [code=1] test/x86/avx512/reduce-native-c 
clang  -o test/x86/avx512/reduce-native-c test/x86/avx512/reduce-native-c.p/reduce.c.o -Wl,--as-needed -Wl,--no-undefined -O2 -Wl,--start-group -lm -Wl,--end-group
/usr/bin/ld: test/x86/avx512/reduce-native-c.p/reduce.c.o: in function `simde_mm512_reduce_max_ph':
/builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:55:(.text+0x14c): undefined reference to `__truncsfhf2'
/usr/bin/ld: /builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:55:(.text+0x23c): undefined reference to `__extendhfsf2'
/usr/bin/ld: /builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:55:(.text+0x246): undefined reference to `__extendhfsf2'
/usr/bin/ld: test/x86/avx512/reduce-native-c.p/reduce.c.o: in function `simde_mm512_reduce_min_ph':
/builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:79:(.text+0x36c): undefined reference to `__truncsfhf2'
/usr/bin/ld: /builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:79:(.text+0x45c): undefined reference to `__extendhfsf2'
/usr/bin/ld: /builddir/build/BUILD/simde-v0.8.4.rc1-build/simde-v0.8.4.rc1/build/clang-O2/../../simde/x86/avx512/reduce.h:79:(.text+0x466): undefined reference to `__extendhfsf2'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Command exited with non-zero status 1
...

Expected results:
Successful linking with clang.

Additional info:
COPR build: https://copr.fedorainfracloud.org/coprs/packit/simd-everywhere-simde-1297/build/09545693/

Comment 1 Nikita Popov 2025-09-12 09:04:05 UTC
These symbols would be provided by libgcc rather than glibc. You can likely work around this using --rtlib=compiler-rt to use compiler-rt instead of libgcc.

Comment 2 Jakub Jelinek 2025-09-12 09:18:05 UTC
gcc certainly doesn't provide such symbols on targets like s390*-linux* which don't support _Float16.
AFAIK only aarch64, csky, gcn, x86 (and in that case for ia32 only with -msse2), nvptx and riscv do support those.

Comment 3 Nikita Popov 2025-09-12 09:30:47 UTC
Yes, the problem is that Clang supports _Float16 on s390x, but GCC doesn't, so this currently only works with Clang's runtime library. Sorry if that was unclear. (Note that _Float16 ABI was specified in the 1.7 ABI revision.)

It's probably possible to get working behavior when building with clang and linking against libgcc by modifying the macros in https://github.com/simd-everywhere/simde/blob/69f0da1ba6ea4ef6d7a4da878bdeedd6ff902277/simde/simde-f16.h to force the fallback implementation.

Comment 4 Jakub Jelinek 2025-09-12 09:36:13 UTC
After all, how could it?  Before a type like that is supported, the psABI of the architecture (if any) needs to specify what size/alignment it has, in which registers/stack slots it is passed as argument and in which registers/stack slots it is returned.
From what I can see, _Float16 has been added to the s390 ABI only in June of this year, https://github.com/IBM/s390x-abi/commit/79880d87ee03cfcbf23ed2509f40a9f19b440434 and so such support can't be in GCC 15 which has been released almost 2 months before that.
I don't see that support even on GCC trunk, but guess that might change in the upcoming months.

Comment 5 Michael R. Crusoe 2025-09-12 10:26:50 UTC
(In reply to Nikita Popov from comment #1)
> You can likely
> work around this using --rtlib=compiler-rt to use compiler-rt instead of
> libgcc.

Adding `--rtlib=compiler-rt` to the clang invocation failed on all architectures

> /usr/bin/ld: cannot find /usr/bin/../lib/clang/21/lib/aarch64-redhat-linux-gnu/libclang_rt.builtins.a: No such file or directory

> /usr/bin/ld: cannot find /usr/bin/../lib/clang/21/lib/i686-redhat-linux-gnu/libclang_rt.builtins.a: No such file or directory

> /usr/bin/ld: cannot find /usr/bin/../lib/clang/21/lib/ppc64le-redhat-linux-gnu/libclang_rt.builtins.a: No such file or directory

> /usr/bin/ld: cannot find /usr/bin/../lib/clang/21/lib/s390x-redhat-linux-gnu/libclang_rt.builtins.a: No such file or directory

> /usr/bin/ld: cannot find /usr/bin/../lib/clang/21/lib/x86_64-redhat-linux-gnu/libclang_rt.builtins.a: No such file or directory

https://copr.fedorainfracloud.org/coprs/packit/simd-everywhere-simde-ci-packit-clang-rt-compiler/build/9550628/

Comment 6 Nikita Popov 2025-09-12 10:28:54 UTC
This probably also needs a BuildRequires: compiler-rt, as compiler-rt is only a weak dependency of clang, so it will not be installed by default in rpm builds.

Comment 7 Michael R. Crusoe 2025-09-12 11:55:48 UTC
(In reply to Nikita Popov from comment #6)
> This probably also needs a BuildRequires: compiler-rt, as compiler-rt is
> only a weak dependency of clang, so it will not be installed by default in
> rpm builds.

Thank you, Nikita Popov, that fixed this issue. But it would be far preferred if clang didn't claim to support _Float16 when it isn't going to link to a runtime library that supports it for the given platform. And from what I can see, the presence of `--rtlib=compiler-rt` is not detectable from source code: https://godbolt.org/z/TPx8EabfY

Comment 8 Tulio Magno Quites Machado Filho 2025-09-12 13:33:19 UTC
> But it would be far preferred if clang didn't claim to support _Float16 when it isn't going to link to a runtime library that supports it for the given platform.

Michael, this is not considered to be a good practice because:

1. It makes it harder for developers interacting with this feature, e.g. libgcc developers could use clang to evaluate if their implementation is working as expected.
2. It's very difficult for a compiler to cover all possible combinations an user can make. That's why projects usually adopt a configure script in order to guide users on their requirements for compiler, libraries and OS.

I see that simde uses meson, but it seems the code seems to be missing a check for _Float16 compiler support + compiler-rt on s390x on Linux.

Comment 9 Michael R. Crusoe 2025-09-12 15:29:15 UTC
(In reply to Tulio Magno Quites Machado Filho from comment #8)
> > But it would be far preferred if clang didn't claim to support _Float16 when it isn't going to link to a runtime library that supports it for the given platform.
> 
> Michael, this is not considered to be a good practice because:
> 
> 1. It makes it harder for developers interacting with this feature, e.g.
> libgcc developers could use clang to evaluate if their implementation is
> working as expected.

I hear you, but that is an advanced and rare use case; I would imagine that a runtime flag to clang could be added, and then by default `_Float16` would not be surfaced if a compatible linker is not chosen.

> 2. It's very difficult for a compiler to cover all possible combinations an
> user can make. That's why projects usually adopt a configure script in order
> to guide users on their requirements for compiler, libraries and OS.
> 
> I see that simde uses meson, but it seems the code seems to be missing a
> check for _Float16 compiler support + compiler-rt on s390x on Linux.

SIMDe only uses meson for building and running its tests; as a header-only library, we have no control how developers use SIMDe and therefore we strive to cope with toolchain and architecture variation as much as we can without configure scripts.


Note You need to log in before you can comment on or make changes to this bug.