dslm4515 / CMLFS

Clang-Built Musl Linux From Scratch
MIT License
99 stars 18 forks source link

Cannot build libc++ with Localization #69

Closed dslm4515 closed 1 year ago

dslm4515 commented 1 year ago

When building LLVM of cgnutools, libc++ will not compile if localization is enabled:

-DLIBCXX_ENABLE_LOCALIZATION=ON

If turned on, build fails:

In file included from /mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__locale:44:
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:28:68: error: 'abi_tag' attribute applied to extern "C" declaration 'long long int strtoll_l(const char*, char**, int, locale_t)'
   28 | strtoll_l(const char *__nptr, char **__endptr, int __base, locale_t) {
      |                                                                    ^
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:33:69: error: 'abi_tag' attribute applied to extern "C" declaration 'long long unsigned int strtoull_l(const char*, char**, int, locale_t)'
   33 | strtoull_l(const char *__nptr, char **__endptr, int __base, locale_t) {
      |                                                                     ^
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:38:74: error: 'abi_tag' attribute applied to extern "C" declaration 'long long int wcstoll_l(const wchar_t*, wchar_t**, int, locale_t)'
   38 | wcstoll_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
      |                                                                          ^
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:43:75: error: 'abi_tag' attribute applied to extern "C" declaration 'long long int wcstoull_l(const wchar_t*, wchar_t**, int, locale_t)'
   43 | wcstoull_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
      |                                                                           ^
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:48:62: error: 'abi_tag' attribute applied to extern "C" declaration 'long double wcstold_l(const wchar_t*, wchar_t**, locale_t)'
   48 | wcstold_l(const wchar_t *__nptr, wchar_t **__endptr, locale_t) {
      |                                                              ^
ninja: build stopped: subcommand failed.

Even with patch from Alpine Linux, issue persists.

dslm4515 commented 1 year ago

If libc++ does not have localization, then ncurses built in llvmtools, fails to build:

In file included from ../c++/cursesmain.cc:50:
/mnt/cmlfs/cgnutools/bin/../include/c++/v1/locale.h:39:5: error: "<locale.h> is not supported since libc++ has been configured without support for localization."
#   error "<locale.h> is not supported since libc++ has been configured without support for localization."
    ^
1 error generated.
make[1]: *** [Makefile:454: ../obj_s/cursesmain.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/mnt/cmlfs/sources/ncurses-6.3/c++'
make: *** [Makefile:140: all] Error 2
dslm4515 commented 1 year ago

ncurses now compiles if --without-cxx is added to configure. Let's see if this feature will be required elsewhere.

takusuman commented 1 year ago

May we should make LLVM developers aware of this? I think this may be a LLVM bug, not our fault.

dslm4515 commented 1 year ago

Out of curiosity, I tried to compile libc++ under a glibc host: same error as when compiling libc++ with Alpine Linux's patch and under a musl host:

/mnt/cmlfs/sources/llvm-project-15.0.5.src/build/include/c++/v1/__locale:545:3: error: #error unknown rune table for this platform -- do you mean to de
fine _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?                                                                                                              
  545 | # error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?                                     
      |   ^~~~~

So Alpine's patch for libc++ works, just another issue with libc++-15.0.5

dslm4515 commented 1 year ago

Arch Linux has libc++ at version 14.0.6 ... there might be a reason why Arch has not upgraded to 15.x.x yet.

OpenMandriva has libc++ at 15.0.6 .... but i dont see any patches. The build recipe is an eyesore to read.

dslm4515 commented 1 year ago

@takusuman Looks like someone may have reported it: https://github.com/llvm/llvm-project/issues/59540

No solution posted

dslm4515 commented 1 year ago

If these options are disabled:

-DLIBCXX_ENABLE_FILESYSTEM=OFF
-DLIBCXX_ENABLE_LOCALIZATION=OFF

Then libc++ builds fine... without any patches. There are no errors for error unknown rune table for this platform

This applies to 14.0.6, 15.0.5, and 15.0.6

dslm4515 commented 1 year ago

If I enable localization of libc++, this error comes up:

In file included from /mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__locale:44:
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:28:68: error: 'abi_tag' attribute applied to extern "C" declaration 'long long int strtoll_l(const char*, char**, int, locale_t)'
   28 | strtoll_l(const char *__nptr, char **__endptr, int __base, locale_t) {
      |                                                                    ^
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:33:69: error: 'abi_tag' attribute applied to extern "C" declaration 'long long unsigned int strtoull_l(const char*, char**, int, locale_t)'
   33 | strtoull_l(const char *__nptr, char **__endptr, int __base, locale_t) {
      |                                                                     ^
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:38:74: error: 'abi_tag' attribute applied to extern "C" declaration 'long long int wcstoll_l(const wchar_t*, wchar_t**, int, locale_t)'
   38 | wcstoll_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
      |                                                                          ^
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:43:75: error: 'abi_tag' attribute applied to extern "C" declaration 'long long int wcstoull_l(const wchar_t*, wchar_t**, int, locale_t)'
   43 | wcstoull_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
      |                                                                           ^
/mnt/cmlfs/sources/llvm-rl/build/include/c++/v1/__support/musl/xlocale.h:48:62: error: 'abi_tag' attribute applied to extern "C" declaration 'long double wcstold_l(const wchar_t*, wchar_t**, locale_t)'
   48 | wcstold_l(const wchar_t *__nptr, wchar_t **__endptr, locale_t) {
      |                                                              ^
ninja: build stopped: subcommand failed.

If i manually edit ` build/include/c++/v1/__support/musl/xlocale.h' [in the build directory] and comment the following:

#ifndef _LIBCPP_SUPPORT_MUSL_XLOCALE_H
#define _LIBCPP_SUPPORT_MUSL_XLOCALE_H

#include <cstdlib>
#include <cwchar>

#ifdef __cplusplus
extern "C" {
#endif

//inline _LIBCPP_HIDE_FROM_ABI long long
//strtoll_l(const char *__nptr, char **__endptr, int __base, locale_t) {
//  return ::strtoll(__nptr, __endptr, __base);
//}

//inline _LIBCPP_HIDE_FROM_ABI unsigned long long
//strtoull_l(const char *__nptr, char **__endptr, int __base, locale_t) {
//  return ::strtoull(__nptr, __endptr, __base);
//}

//inline _LIBCPP_HIDE_FROM_ABI long long
//wcstoll_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
//  return ::wcstoll(__nptr, __endptr, __base);
//}

//inline _LIBCPP_HIDE_FROM_ABI long long
//wcstoull_l(const wchar_t *__nptr, wchar_t **__endptr, int __base, locale_t) {
//  return ::wcstoull(__nptr, __endptr, __base);
//}

//inline _LIBCPP_HIDE_FROM_ABI long double
//wcstold_l(const wchar_t *__nptr, wchar_t **__endptr, locale_t) {
//  return ::wcstold(__nptr, __endptr);
//}

#ifdef __cplusplus

then libc++ builds with out error!

The question is ... how to prevent/apply this BEFORE compiling?

dslm4515 commented 1 year ago

This looks like "name mangling" is in use (reference)

Perhaps cgnutools' GCC does not support 'name mangling' ?

dslm4515 commented 1 year ago

Issue fixed with commit c0022b0ed5c32a922e20145326c699652cae97f2

Let's see if this will cause any issues

dslm4515 commented 1 year ago

For the error of 'rune table':

/mnt/cmlfs/sources/llvm-project-15.0.5.src/build/include/c++/v1/__locale:545:3: error: #error unknown rune table for this platform -- do you mean to de
fine _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?                                                                                                              
  545 | # error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?                                     
      |   ^~~~~

Perhaps, there should be a patch to use libcxx's default rune table with the Musl C library: https://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20151123/143770.html

dslm4515 commented 1 year ago

Looks like when building libcxx, the cxx headers were not configured correctly at ${BUILD}/include/x86_64-pc-linux-musl/c++/v1/__config_site :

 #define _LIBCPP_ABI_VERSION 1
#define _LIBCPP_ABI_NAMESPACE __1
/* #undef _LIBCPP_ABI_FORCE_ITANIUM */
/* #undef _LIBCPP_ABI_FORCE_MICROSOFT */
/* #undef _LIBCPP_HAS_NO_THREADS */
/* #undef _LIBCPP_HAS_NO_MONOTONIC_CLOCK */
/* #undef _LIBCPP_HAS_MUSL_LIBC */

#undef _LIBCPP_HAS_MUSL_LIBC should be changed to this:

#define _LIBCPP_HAS_MUSL_LIBC
dslm4515 commented 1 year ago

No, looks like i forgot to set -DLIBCXX_HAS_MUSL_LIBC=ON ... setting option eliminates rune table error

dslm4515 commented 1 year ago

So far as of commit 5a13253ae45bafea296314b06d2ca3d88bf441a6 , no more localization issues so far. Patch from commit c0022b0 works for building LLVM for both cgnutools & llvmtools