dslm4515 / CMLFS

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

LLVM12 - llvmtools build breaks as libcxx #9

Closed dslm4515 closed 3 years ago

dslm4515 commented 3 years ago

Building llvmtools with llvm-12.0.0 on a glibc host .... Build fails.

[ 70%] Building CXX object src/CMakeFiles/cxx_shared.dir/charconv.cpp.o                  [139/1822]
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:                  
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:    /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:321:9: error: no member named 'signbit' in the global namespace; did you mean '__signbit'?
using ::signbit;
      ~~^~~~~~~
        __signbit
/llvmtools/include/math.h:93:5: note: '__signbit' declared here
int __signbit(double);
    ^
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:322:9: error: no member named 'fpclassify' in the global namespace; did you mean '__fpclassify'?
using ::fpclassify;
      ~~^~~~~~~~~~
        __fpclassify
/llvmtools/include/math.h:51:5: note: '__fpclassify' declared here
int __fpclassify(double);
    ^
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:323:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
      ~~^~~~~~~~
        finite
/llvmtools/include/math.h:401:13: note: 'finite' declared here
int         finite(double);
            ^
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:324:9: error: no membe[106/1822]sinf' in the global namespace
using ::isinf;
      ~~^
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:325:9: error: no member named 'isnan' in the global namespace
using ::isnan;
      ~~^
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:326:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
      ~~^
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:327:9: error: no member named 'isgreater' in the global namespace; did you mean '__isgreater'?
using ::isgreater;
      ~~^~~~~~~~~
        __isgreater
/llvmtools/include/math.h:118:1: note: '__isgreater' declared here
__ISREL_DEF(greater, >, double_t)
^
/llvmtools/include/math.h:105:21: note: expanded from macro '__ISREL_DEF'
static __inline int __is##rel(type __x, type __y) \
                    ^
<scratch space>:59:1: note: expanded from here
__isgreater
^
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:328:9: error: no member named 'isgreaterequal' in the global namespace; did you mean '__isgreaterequal'?
using ::isgreaterequal;
      ~~^~~~~~~~~~~~~~
        __isgreaterequal 
/llvmtools/include/math.h:121:1: note: '__isgreaterequal' declared here
__ISREL_DEF(greaterequal, >=, double_t)                                                   [72/1822]
^
/llvmtools/include/math.h:105:21: note: expanded from macro '__ISREL_DEF'
static __inline int __is##rel(type __x, type __y) \
                    ^
<scratch space>:62:1: note: expanded from here
__isgreaterequal
^
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:329:9: error: no member named 'isless' in the global namespace; did you mean '__isless'?
using ::isless;
      ~~^~~~~~
        __isless
/llvmtools/include/math.h:109:1: note: '__isless' declared here
__ISREL_DEF(less, <, double_t)
^
/llvmtools/include/math.h:105:21: note: expanded from macro '__ISREL_DEF'
static __inline int __is##rel(type __x, type __y) \
                    ^
<scratch space>:50:1: note: expanded from here
__isless
^
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:330:9: error: no member named 'islessequal' in the global namespace; did you mean '__islessequal'?
using ::islessequal;
      ~~^~~~~~~~~~~
        __islessequal
/llvmtools/include/math.h:112:1: note: '__islessequal' declared here
__ISREL_DEF(lessequal, <=, double_t)
^
/llvmtools/include/math.h:105:21: note: expanded from macro '__ISREL_DEF'                 [38/1822]
static __inline int __is##rel(type __x, type __y) \
                    ^
<scratch space>:53:1: note: expanded from here
__islessequal
^
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:331:9: error: no member named 'islessgreater' in the global namespace; did you mean '__islessgreater'?
using ::islessgreater;
      ~~^~~~~~~~~~~~~
        __islessgreater
/llvmtools/include/math.h:115:1: note: '__islessgreater' declared here
__ISREL_DEF(lessgreater, !=, double_t)
^
/llvmtools/include/math.h:105:21: note: expanded from macro '__ISREL_DEF'
static __inline int __is##rel(type __x, type __y) \
                    ^
<scratch space>:56:1: note: expanded from here
__islessgreater
^
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:332:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:333:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:339:9: error: no member named 'abs' in the global namespace; did you mean 'fabs'? 
using ::abs;                                                                               [4/1822]
      ~~^~~
        fabs
/llvmtools/include/math.h:203:13: note: 'fabs' declared here
double      fabs(double);
            ^
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/src/charconv.cpp:9:
In file included from /mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/charconv:79:
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:644:26: error: no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                         ^
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:644:60: error: no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                                                           ^
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:645:18: error: no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                 ^
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:645:50: error: no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                                                 ^
/mnt/cmlfs/sources/llvm/projects/libcxx/build/include/c++/v1/cmath:650:17: error: no template named 'numeric_limits'
  static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [src/CMakeFiles/cxx_shared.dir/build.make:128: src/CMakeFiles/cxx_shared.dir/charconv.cpp.o] Error 1
make[2]: Leaving directory '/mnt/cmlfs/sources/llvm/projects/libcxx/build'
make[1]: *** [CMakeFiles/Makefile2:533: src/CMakeFiles/cxx_shared.dir/all] Error 2
make[1]: Leaving directory '/mnt/cmlfs/sources/llvm/projects/libcxx/build'
make: *** [Makefile:130: all] Error 2
make: Leaving directory '/mnt/cmlfs/sources/llvm/projects/libcxx/build'
owl4ce commented 3 years ago

Conflict with libcxx's math header

dslm4515 commented 3 years ago

I figured as such, but I haven't figured out what to change.

owl4ce commented 3 years ago

Removing this should fix most issue

        -DCMAKE_CXX_FLAGS="-I/llvmtools/include"
        -DCMAKE_C_FLAGS="-I/llvmtools/include"

but there are still one (currently: at 72%) problems still appears because of not including linux API headers

/mnt/cmlfs/sources/llvm/projects/libcxx/src/atomic.cpp:19:10: fatal error: 'linux/futex.h' file not found
#include <linux/futex.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/CMakeFiles/cxx_static.dir/build.make:104: src/CMakeFiles/cxx_static.dir/atomic.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
[ 72%] Building CXX object src/CMakeFiles/cxx_shared.dir/bind.cpp.o
/mnt/cmlfs/sources/llvm/projects/libcxx/src/atomic.cpp:19:10: fatal error: 'linux/futex.h' file not found
#include <linux/futex.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/CMakeFiles/cxx_shared.dir/build.make:104: src/CMakeFiles/cxx_shared.dir/atomic.cpp.o] Error 1

So what

dslm4515 commented 3 years ago

hmmmmm:

The build actually fails because of "#include <linux/futex.h>". 
Musl does not have this header file and the build fails with a 
missing header file error.

https://reviews.llvm.org/D76632

owl4ce commented 3 years ago

hmmmmm:

The build actually fails because of "#include <linux/futex.h>". 
Musl does not have this header file and the build fails with a 
missing header file error.

https://reviews.llvm.org/D76632

Its not from libc, but from linux headers that it exists. The problems is how to include those headers along with built-in libcxx's headers if I'm not wrong

dslm4515 commented 3 years ago

on LLVM11, it went further after patching src/atomic.cpp

[ 83%] Building CXX object src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o
/mnt/cmlfs/sources/llvm/projects/libcxx/src/filesystem/operations.cpp:29:10: fatal error: 'linux/version.h' file not found
#include <linux/version.h>
         ^~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/CMakeFiles/cxx_shared.dir/build.make:531: src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o] Error 1
make[2]: Leaving directory '/mnt/cmlfs/sources/llvm/projects/libcxx/build'
make[1]: *** [CMakeFiles/Makefile2:408: src/CMakeFiles/cxx_shared.dir/all] Error 2
make[1]: Leaving directory '/mnt/cmlfs/sources/llvm/projects/libcxx/build'
make: *** [Makefile:130: all] Error 2
make: Leaving directory '/mnt/cmlfs/sources/llvm/projects/libcxx/build'
dslm4515 commented 3 years ago

I also patched src/filesystem/operations.cpp and libcxx completes! I will upload a patch soon

owl4ce commented 3 years ago

Got it

owl4ce commented 3 years ago

Using -isystem instead of -I for CXX flags and build successful

cmake -B build  \
      -DCMAKE_INSTALL_PREFIX=/llvmtools \
      -DLLVM_PATH="${LLVMSRC}" \
      -DLIBCXX_ENABLE_SHARED=ON \
      -DLIBCXX_ENABLE_STATIC=ON  \
      -DLIBCXX_HAS_MUSL_LIBC=ON \
      -DLIBCXX_USE_COMPILER_RT=ON \
      -DLIBCXX_CXX_ABI=libcxxabi \
      -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/llvmtools/include" \
      -DLIBCXXABI_USE_LLVM_UNWINDER=ON \
      -DLIBCXX_CXX_ABI_LIBRARY_PATH=/llvmtools/lib \
      -DLIBCXX_INSTALL_HEADERS=ON \
      -DCMAKE_CXX_FLAGS="-isystem /llvmtools/include" \

Removed line

      -DCMAKE_C_FLAGS="-I/llvmtools/include" 

There's no .c source code

dslm4515 commented 3 years ago

OH! that better than patching the source. :+1:

dslm4515 commented 3 years ago

Made the change with b88d11f

Thanks!