dslm4515 / CMLFS

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

Libc++.so.1 (llvmtools) requires libatomic.so.1 #12

Closed dslm4515 closed 3 years ago

dslm4515 commented 3 years ago

llvmtools' libc++.so.1 from libcxx should NOT rely on libatomic.so.1, which is provided by GCC.

$ ldd /llvmtools/lib/libc++.so.1
        ldd (0x7fb67cb49000)
        libc.so => ldd (0x7fb67cb49000)
Error loading shared library libatomic.so.1: No such file or directory (needed by /llvmtools/lib/libc++.so.1)
        libunwind.so.1 => /llvmtools/lib/../lib/libunwind.so.1 (0x7fb67ca6b000)
        libc++abi.so.1 => /llvmtools/lib/../lib/libc++abi.so.1 (0x7fb67ca0f000)

This will require to build LLVM for llvmtools with a LD_LIBARARY_PATH hack

owl4ce commented 3 years ago

hmmmmmm http://llvmweekly.org/issue/336

image

dslm4515 commented 3 years ago

Re-built llvmtools and made sure libcxx did not require libatomic.

now llvm/clang for llvmtools fails to build:

FAILED: include/llvm/IR/Attributes.inc 
cd /mnt/cmlfs/sources/llvm/build && /mnt/cmlfs/sources/llvm/build/bin/llvm-tblgen -gen-attrs -I /mnt/cmlfs/sources/llvm/include/llvm/IR -I /mnt/cmlfs/sources/llvm/build/include -I /mnt/cmlfs/sources/llvm/include /mnt/cmlfs/sources/llvm/include/llvm/IR/Attributes.td --write-if-changed -o include/llvm/IR/Attributes.inc -d include/llvm/IR/Attributes.inc.d
/bin/sh: /mnt/cmlfs/sources/llvm/build/bin/llvm-tblgen: No such file or directory
[220/3316] Building CXX object lib/BinaryFormat/CMakeFiles/LLVMBinaryFormat.dir/MsgPackDocument.cpp.o
ninja: build stopped: subcommand failed.
dslm4515 commented 3 years ago

hmmmmmm http://llvmweekly.org/issue/336

image

Looks like for libcxx, I’ll have to set a flag to disable libatomic

owl4ce commented 3 years ago

hmmmmmm http://llvmweekly.org/issue/336 image

Looks like for libcxx, I’ll have to set a flag to disable libatomic

How?

dslm4515 commented 3 years ago

Looks like I’ll have to patch libcxx/cmake/Modules/CheckLibcxxAtomic.cmake

dslm4515 commented 3 years ago

Although it’s strange that after rebuilding llvmtools... llvmtools’ Libc++.so.1 no longer requires libatomic.

not sure if it matters that PATH=/cgnutools/bin:/llvmtools/bin:/bin:/usr/bin

owl4ce commented 3 years ago

Commenting this will disable libatomic detection for Linux when configure libcxx (cmake).

check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)

projects/libcxx/cmake/config-ix.cmake

102 else()
103   check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
104   check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
105   check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
106   set(LIBCXX_HAS_SYSTEM_LIB NO)
107 #  check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
108 endif()
owl4ce commented 3 years ago

I wonder how atomic detected when building libcxx

dslm4515 commented 3 years ago

I probably will include a check for libunwind, libcxx, and libcxxabi to make sure there are no GCC dependencies. It’s annoying to finally build LLVM for llvmtools only to realize llvmtools has GCC dependencies.

owl4ce commented 3 years ago

LLVM 12.0.0

Successful by using above trick! While building libcxx in llvmtools (deletes matched PATTERN):

sed -i '/check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)/d' \
${LLVMSRC}/projects/libcxx/cmake/config-ix.cmake

Progress of building Clang/LLVM in llvmtools (I'm prefer GNU's Make btw):

[ 99%] Built target clangStaticAnalyzerFrontend
make[2]: Entering directory '/mnt/cmlfs/sources/llvm/build'
make[2]: Leaving directory '/mnt/cmlfs/sources/llvm/build'
make[2]: Entering directory '/mnt/cmlfs/sources/llvm/build'
[ 99%] Building C object tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o
[ 99%] Building CXX object tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/core_main.cpp.o
[100%] Linking CXX executable ../../../../bin/c-arcmt-test
make[2]: Leaving directory '/mnt/cmlfs/sources/llvm/build'
[100%] Built target c-arcmt-test
make[2]: Entering directory '/mnt/cmlfs/sources/llvm/build'
make[2]: Leaving directory '/mnt/cmlfs/sources/llvm/build'
make[2]: Entering directory '/mnt/cmlfs/sources/llvm/build'
[100%] Linking CXX static library ../../../../lib/libclangFrontendTool.a
make[2]: Leaving directory '/mnt/cmlfs/sources/llvm/build'
[100%] Built target clangFrontendTool
make[2]: Entering directory '/mnt/cmlfs/sources/llvm/build'
make[2]: Leaving directory '/mnt/cmlfs/sources/llvm/build'
make[2]: Entering directory '/mnt/cmlfs/sources/llvm/build'
[100%] Linking CXX static library ../../../../../lib/libclangDependencyScanning.a
make[2]: Leaving directory '/mnt/cmlfs/sources/llvm/build'
[100%] Built target clangDependencyScanning
[100%] Linking CXX executable ../../../../bin/c-index-test
make[2]: Leaving directory '/mnt/cmlfs/sources/llvm/build'
[100%] Built target c-index-test
make[1]: Leaving directory '/mnt/cmlfs/sources/llvm/build'
make: Leaving directory '/mnt/cmlfs/sources/llvm/build

@dslm4515

dslm4515 commented 3 years ago

Commenting this will disable libatomic detection for Linux when configure libcxx (cmake).

check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)

projects/libcxx/cmake/config-ix.cmake

102 else()
103   check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
104   check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
105   check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
106   set(LIBCXX_HAS_SYSTEM_LIB NO)
107 #  check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
108 endif()

Closing issue as @owl4ce fixed issue