Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latest libc++ doesn't compile with gcc 14.1 #91831

Open
Chilledheart opened this issue May 11, 2024 · 6 comments · May be fixed by #92663
Open

latest libc++ doesn't compile with gcc 14.1 #91831

Chilledheart opened this issue May 11, 2024 · 6 comments · May be fixed by #92663
Assignees
Labels
build-problem libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@Chilledheart
Copy link

Chilledheart commented May 11, 2024

libc++ doesn't compile with GCC 14.1 because it comes with new GCC __remove_pointer built-in which is incompatible with libc++.

GCC 14.1 is out https://lwn.net/Articles/972683/.

[39/48] Building CXX object third_part...xx.dir/trunk/src/filesystem/path.cpp.o
FAILED: third_party/libc++/CMakeFiles/cxx.dir/trunk/src/filesystem/path.cpp.o 
/usr/bin/c++ -DCR_LIBCXX_REVISION=e3b94d0e5b86883fd77696bf10dc33ba250ba99b -DHAVE_LIBCXX -DLIBCXX_BUILDING_LIBCXXABI -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED=1 -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D_LIBCPP_OVERRIDABLE_FUNC_VIS="__attribute__((__visibility__(\"default\")))" -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -I/home/hky/yass-develop/build-archlinux -I/home/hky/yass-develop/third_party/libc++/../libc++ -I/home/hky/yass-develop/third_party/libc++/../libc++/trunk/src -I/home/hky/yass-develop/third_party/libc++/../libc++/trunk/include -I/home/hky/yass-develop/third_party/libc++/trunk/include -fdata-sections -ffunction-sections -gdwarf-4 -g2 -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -funwind-tables -pipe -pthread -fdiagnostics-color=always -nostdinc++ -isystem /home/hky/yass-develop/third_party/libc++ -isystem /home/hky/yass-develop/third_party/libc++/trunk/include -isystem /home/hky/yass-develop/third_party/libc++/../libc++abi/trunk/include -fno-builtin-abs -Wno-alloc-size-larger-than -Wno-stringop-overread -Wno-array-bounds -include /home/hky/yass-develop/third_party/libc++/__config_site -include /home/hky/yass-develop/third_party/libc++/__assertion_handler -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -DCR_LIBCXX_REVISION=e3b94d0e5b86883fd77696bf10dc33ba250ba99b -O3 -DNDEBUG -DNDEBUG -flto=auto -std=c++20 -fPIC -fstrict-aliasing -Wno-missing-declarations -Wno-attributes -fPIC -fvisibility-inlines-hidden -fvisibility=hidden -frtti -fno-exceptions -MD -MT third_party/libc++/CMakeFiles/cxx.dir/trunk/src/filesystem/path.cpp.o -MF third_party/libc++/CMakeFiles/cxx.dir/trunk/src/filesystem/path.cpp.o.d -o third_party/libc++/CMakeFiles/cxx.dir/trunk/src/filesystem/path.cpp.o -c /home/hky/yass-develop/third_party/libc++/trunk/src/filesystem/path.cpp
In file included from /home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/filesystem_error.h:15,
                 from /home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/directory_entry.h:20,
                 from /home/hky/yass-develop/third_party/libc++/trunk/include/filesystem:538,
                 from /home/hky/yass-develop/third_party/libc++/trunk/src/filesystem/path.cpp:10:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h: In instantiation of \u2018std::__Cr::__fs::filesystem::path::_EnableIfPathable<_Source> std::__Cr::__fs::filesystem::path::append(const _Source&) [with _Source = char [3]]\u2019:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h:533:52: error: use of built-in trait \u2018__remove_pointer(typename std::__Cr::decay<_Tp>::type)\u2019 in function signature; use library traits instead
  533 |   _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> append(const _Source& __src) {
      |                                                    ^~~~~~
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h: In instantiation of \u2018std::__Cr::__fs::filesystem::path::_EnableIfPathable<_Source> std::__Cr::__fs::filesystem::path::append(const _Source&) [with _Source = char [1]]\u2019:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h:533:52: error: use of built-in trait \u2018__remove_pointer(typename std::__Cr::decay<_Tp>::type)\u2019 in function signature; use library traits instead
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h: In instantiation of \u2018std::__Cr::__fs::filesystem::path::_EnableIfPathable<_Source> std::__Cr::__fs::filesystem::path::append(const _Source&) [with _Source = std::__Cr::basic_string_view<char>]\u2019:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h:533:52: error: use of built-in trait \u2018__remove_pointer(typename std::__Cr::decay<_Tp>::type)\u2019 in function signature; use library traits instead
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h: In instantiation of \u2018std::__Cr::__fs::filesystem::path::_EnableIfPathable<_Source> std::__Cr::__fs::filesystem::path::operator/=(const _Source&) [with _Source = char [3]]\u2019:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h:528:52: error: use of built-in trait \u2018__remove_pointer(typename std::__Cr::decay<_Tp>::type)\u2019 in function signature; use library traits instead
  528 |   _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> operator/=(const _Source& __src) {
      |                                                    ^~~~~~~~
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h: In instantiation of \u2018std::__Cr::__fs::filesystem::path::_EnableIfPathable<_Source> std::__Cr::__fs::filesystem::path::operator/=(const _Source&) [with _Source = char [1]]\u2019:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h:528:52: error: use of built-in trait \u2018__remove_pointer(typename std::__Cr::decay<_Tp>::type)\u2019 in function signature; use library traits instead
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h: In instantiation of \u2018std::__Cr::__fs::filesystem::path::_EnableIfPathable<_Source> std::__Cr::__fs::filesystem::path::operator/=(const _Source&) [with _Source = std::__Cr::basic_string_view<char>]\u2019:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h:528:52: error: use of built-in trait \u2018__remove_pointer(typename std::__Cr::decay<_Tp>::type)\u2019 in function signature; use library traits instead
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h: In instantiation of \u2018std::__Cr::__fs::filesystem::path::_EnableIfPathable<_Source> std::__Cr::__fs::filesystem::path::append(const _Source&) [with _Source = std::__Cr::basic_string<char>]\u2019:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h:533:52: error: use of built-in trait \u2018__remove_pointer(typename std::__Cr::decay<_Tp>::type)\u2019 in function signature; use library traits instead
  533 |   _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> append(const _Source& __src) {
      |                                                    ^~~~~~
[40/48] Building CXX object third_party/libc++/CMakeFiles/cxx.dir/trunk/src/locale.cpp.o
ninja: build stopped: subcommand failed.
[hky@arch build-archlinux]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.1.1 20240507 (GCC) 

It compiles with below patch:

diff --git a/include/__type_traits/remove_pointer.h b/include/__type_traits/remove_pointer.h
index 54390a193..c01eb3c37 100644
--- a/include/__type_traits/remove_pointer.h
+++ b/include/__type_traits/remove_pointer.h
@@ -17,7 +17,7 @@

 _LIBCPP_BEGIN_NAMESPACE_STD

-#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__remove_pointer)
+#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__remove_pointer) && !defined(_LIBCPP_GCC_VER)
 template <class _Tp>
 struct remove_pointer {
   using type _LIBCPP_NODEBUG = __remove_pointer(_Tp);
@github-actions github-actions bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label May 11, 2024
@Chilledheart
Copy link
Author

Chilledheart commented May 11, 2024

For comparison, below is libstdc++'s implementation (from https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/type_traits#L2105):

  /// remove_pointer
#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_pointer)
  template<typename _Tp>
    struct remove_pointer
    { using type = __remove_pointer(_Tp); };
#else
  template<typename _Tp, typename>
    struct __remove_pointer_helper
    { using type = _Tp; };

  template<typename _Tp, typename _Up>
    struct __remove_pointer_helper<_Tp, _Up*>
    { using type = _Up; };

  template<typename _Tp>
    struct remove_pointer
    : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>>
    { };
#endif

@Chilledheart
Copy link
Author

Chilledheart commented May 11, 2024

It also compiles with below patch:

diff --git a/libcxx/include/__type_traits/remove_pointer.h b/libcxx/include/__type_traits/remove_pointer.h
index 54390a1939f7..690a58068dd8 100644
--- a/libcxx/include/__type_traits/remove_pointer.h
+++ b/libcxx/include/__type_traits/remove_pointer.h
@@ -24,7 +24,7 @@ struct remove_pointer {
 };

 template <class _Tp>
-using __remove_pointer_t = __remove_pointer(_Tp);
+using __remove_pointer_t = typename remove_pointer<_Tp>::type;
 #else
 // clang-format off
 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer                      {typedef _LIBCPP_NODEBUG _Tp type;};

@Chilledheart
Copy link
Author

Chilledheart commented May 11, 2024

It might be an issue but gcc adds tons of builtin in near furthure release (trunk):

image

@Chilledheart
Copy link
Author

For reference, archlinux and fedora 40 are using gcc 14/14.1.

(Fedora)

hky@fedora:~/yass-develop/build-gcc14$ ninja cxx
[25/68] Building CXX object third_part...dir/trunk/src/ios.instantiations.cpp.o
FAILED: third_party/libc++/CMakeFiles/cxx.dir/trunk/src/ios.instantiations.cpp.o 
/usr/bin/c++ -DCR_LIBCXX_REVISION=e3b94d0e5b86883fd77696bf10dc33ba250ba99b -DHAVE_LIBCXX -DLIBCXX_BUILDING_LIBCXXABI -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED=1 -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D_LIBCPP_OVERRIDABLE_FUNC_VIS="__attribute__((__visibility__(\"default\")))" -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -I/home/hky/yass-develop/build-gcc14 -I/home/hky/yass-develop/third_party/libc++/../libc++ -I/home/hky/yass-develop/third_party/libc++/../libc++/trunk/src -I/home/hky/yass-develop/third_party/libc++/../libc++/trunk/include -I/home/hky/yass-develop/third_party/libc++/trunk/include -fdata-sections -ffunction-sections -gdwarf-4 -g2 -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -funwind-tables -pipe -pthread -fdiagnostics-color=always -nostdinc++ -isystem /home/hky/yass-develop/third_party/libc++ -isystem /home/hky/yass-develop/third_party/libc++/trunk/include -isystem /home/hky/yass-develop/third_party/libc++/../libc++abi/trunk/include -fno-builtin-abs -Wno-alloc-size-larger-than -Wno-stringop-overread -Wno-array-bounds -include /home/hky/yass-develop/third_party/libc++/__config_site -include /home/hky/yass-develop/third_party/libc++/__assertion_handler -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -DCR_LIBCXX_REVISION=e3b94d0e5b86883fd77696bf10dc33ba250ba99b -O3 -DNDEBUG -DNDEBUG -flto=auto -std=c++20 -fPIC -fstrict-aliasing -Wno-missing-declarations -Wno-attributes -fPIC -fvisibility-inlines-hidden -fvisibility=hidden -frtti -fno-exceptions -MD -MT third_party/libc++/CMakeFiles/cxx.dir/trunk/src/ios.instantiations.cpp.o -MF third_party/libc++/CMakeFiles/cxx.dir/trunk/src/ios.instantiations.cpp.o.d -o third_party/libc++/CMakeFiles/cxx.dir/trunk/src/ios.instantiations.cpp.o -c /home/hky/yass-develop/third_party/libc++/trunk/src/ios.instantiations.cpp
In file included from /home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/filesystem_error.h:15,
                 from /home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/directory_entry.h:20,
                 from /home/hky/yass-develop/third_party/libc++/trunk/include/filesystem:538,
                 from /home/hky/yass-develop/third_party/libc++/trunk/include/fstream:199,
                 from /home/hky/yass-develop/third_party/libc++/trunk/src/ios.instantiations.cpp:10:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h: In instantiation of \u2018std::__Cr::__fs::filesystem::path::_EnableIfPathable<_Source> std::__Cr::__fs::filesystem::path::append(const _Source&) [with _Source = std::__Cr::basic_string<char>]\u2019:
/home/hky/yass-develop/third_party/libc++/trunk/include/__filesystem/path.h:533:52: error: use of built-in trait \u2018__remove_pointer(typename std::__Cr::decay<_Tp>::type)\u2019 in function signature; use library traits instead
  533 |   _LIBCPP_HIDE_FROM_ABI _EnableIfPathable<_Source> append(const _Source& __src) {
      |                                                    ^~~~~~
[38/68] Building CXX object third_part...keFiles/cxx.dir/trunk/src/locale.cpp.o
ninja: build stopped: subcommand failed.
hky@fedora:~/yass-develop/build-gcc14$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-14.0.1-20240411/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240411 (Red Hat 14.0.1-0) (GCC)

(Archlinux)

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.1.1 20240507 (GCC) 

@Chilledheart
Copy link
Author

Fedora 40 got an update for GCC 14.1:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-14.1.1-20240508/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.1.1 20240507 (Red Hat 14.1.1-1) (GCC) 

Chilledheart added a commit to Chilledheart/llvm-project that referenced this issue May 15, 2024
In new GCC release (such as 14.1), a new warning is added that
all traits are not to be used directly but library traits.

Keep the same structure with gcc's library traits to prevent future
issues.

see https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/type_traits#L2105
and https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/type_traits#L2146.

Fixes llvm#91831.
@Chilledheart
Copy link
Author

Chilledheart commented May 17, 2024

For the records, I upload the gcc 14 patch to https://github.com/Chilledheart/libcxx/tree/fix_with_gcc14 for any one interested.

@ldionne ldionne linked a pull request May 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-problem libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
3 participants