When building llvm12 through llvm15 with clang 15 as host compiler (see bug 265425), and when compiler-rt is enabled, there will be errors due to float16 support, similar to: In file included from /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/extendhfsf2.c:11: In file included from /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/fp_extend_impl.inc:38: /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/fp_extend.h:44:9: error: _Float16 is not supported on this target typedef _Float16 src_t; ^ This is because compiler-rt's CMake infrastructure detects float16 support at configure time, while targeting 'pure' x86_64, but then builds parts of its tree also targeting i386. To work around this, modify compiler-rt's top-level CMakeLists.txt to move setting the -DCOMPILER_RT_HAS_FLOAT16 compilation flag to the arch-specific for loop, so it only gets enabled for x86_64, and not for i386. For llvm15, also add another modification that removes the bfloat16 source files from the i386_SOURCES list, so these are not built for i386.
Created attachment 238572 [details] devel/llvm1[2-5]: fix build with clang 15
I'll commit soon (probably Friday) this along with a change to llvm15 that requires a PORTREVISION bump to slightly reduce the number of rebuilds that get done.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=830bbdd84a53aa33b48c01ee16048d1400094e26 commit 830bbdd84a53aa33b48c01ee16048d1400094e26 Author: Brooks Davis <brooks@FreeBSD.org> AuthorDate: 2022-12-09 18:49:40 +0000 Commit: Brooks Davis <brooks@FreeBSD.org> CommitDate: 2022-12-09 18:49:40 +0000 devel/llvm1[2345]: fix build with clang 15 When building llvm12 through llvm15 with clang 15 as host compiler, and when compiler-rt is enabled, there will be errors due to float16 support, similar to: In file included from /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/extendhfsf2.c:11: In file included from /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/fp_extend_impl.inc:38: /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/fp_extend.h:44:9: error: _Float16 is not supported on this target typedef _Float16 src_t; ^ This is because compiler-rt's CMake infrastructure detects float16 support at configure time, while targeting 'pure' x86_64, but then builds parts of its tree also targeting i386. To work around this, modify compiler-rt's top-level CMakeLists.txt to move setting the -DCOMPILER_RT_HAS_FLOAT16 compilation flag to the arch-specific for loop, so it only gets enabled for x86_64, and not for i386. For llvm15, also add another modification that removes the bfloat16 source files from the i386_SOURCES list, so these are not built for i386. PR: 268196 Submitted by: dim ...h-compiler-rt_lib_builtins_CMakeLists.txt (new) | 22 ++++++++++ ...h-compiler-rt_lib_builtins_CMakeLists.txt (new) | 22 ++++++++++ ...h-compiler-rt_lib_builtins_CMakeLists.txt (new) | 22 ++++++++++ ...h-compiler-rt_lib_builtins_CMakeLists.txt (new) | 50 ++++++++++++++++++++++ 4 files changed, 116 insertions(+)
(In reply to commit-hook from comment #3) Are these changes that also need to be done upstream?
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=e9c750b7ee8c734028113d316bf46a070ac3dd67 commit e9c750b7ee8c734028113d316bf46a070ac3dd67 Author: Brooks Davis <brooks@FreeBSD.org> AuthorDate: 2022-12-09 22:44:29 +0000 Commit: Brooks Davis <brooks@FreeBSD.org> CommitDate: 2022-12-09 22:47:50 +0000 devel/llvm-devel: update to a fresh snapshot Fix builds with clang15 using with the patch applied to devel/llvm15 in 830bbdd84a53aa33b48c01ee16048d1400094e26. PR: 268196 devel/llvm-devel/Makefile | 2 +- devel/llvm-devel/Makefile.snapshot | 4 +- devel/llvm-devel/distinfo | 6 +-- ...h-compiler-rt_lib_builtins_CMakeLists.txt (new) | 50 ++++++++++++++++++++++ devel/llvm-devel/pkg-plist | 11 +++-- 5 files changed, 64 insertions(+), 9 deletions(-)
(In reply to Ed Maste from comment #4) Yes, but I'm unsure if the diff as-is is acceptable for upstream. It might be good enough for a stopgap. [ The problem with the compiler-rt cmake configuration is that the detection of features is done just once. But it is built twice, first with the default architecture, then with -m32, implying different 32-bit CPUs on different platforms. On FreeBSD, we target i686 by default so float16/bfloat16 *aren't* available, while on Linux, the default is pentium4. ]
A commit in branch 2022Q4 references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=f4497535fe59b5e0fee717a4c91032fc8bb223cc commit f4497535fe59b5e0fee717a4c91032fc8bb223cc Author: Brooks Davis <brooks@FreeBSD.org> AuthorDate: 2022-12-12 17:37:59 +0000 Commit: Brooks Davis <brooks@FreeBSD.org> CommitDate: 2022-12-12 17:37:59 +0000 devel/llvm1[2345]: fix build with clang 15 When building llvm12 through llvm15 with clang 15 as host compiler, and when compiler-rt is enabled, there will be errors due to float16 support, similar to: In file included from /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/extendhfsf2.c:11: In file included from /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/fp_extend_impl.inc:38: /wrkdirs/usr/ports/devel/llvm15/work/llvm-project-15.0.6.src/compiler-rt/lib/builtins/fp_extend.h:44:9: error: _Float16 is not supported on this target typedef _Float16 src_t; ^ This is because compiler-rt's CMake infrastructure detects float16 support at configure time, while targeting 'pure' x86_64, but then builds parts of its tree also targeting i386. To work around this, modify compiler-rt's top-level CMakeLists.txt to move setting the -DCOMPILER_RT_HAS_FLOAT16 compilation flag to the arch-specific for loop, so it only gets enabled for x86_64, and not for i386. For llvm15, also add another modification that removes the bfloat16 source files from the i386_SOURCES list, so these are not built for i386. PR: 268196 Submitted by: dim (cherry picked from commit 830bbdd84a53aa33b48c01ee16048d1400094e26) ...h-compiler-rt_lib_builtins_CMakeLists.txt (new) | 22 ++++++++++ ...h-compiler-rt_lib_builtins_CMakeLists.txt (new) | 22 ++++++++++ ...h-compiler-rt_lib_builtins_CMakeLists.txt (new) | 22 ++++++++++ ...h-compiler-rt_lib_builtins_CMakeLists.txt (new) | 50 ++++++++++++++++++++++ 4 files changed, 116 insertions(+)