SNSystems / llvm-project-prepo

Fork of LLVM with modifications to support a program repository
26 stars 0 forks source link

Porting the libatomic on the repo target, #168

Closed MaggieYingYi closed 2 years ago

MaggieYingYi commented 2 years ago

This is spin-off from the https://github.com/SNSystems/llvm-project-prepo/issues/162.

Please see the detailed description in https://github.com/SNSystems/llvm-project-prepo/issues/162#issuecomment-1024181623.

MaggieYingYi commented 2 years ago

The problem description:

$ repo-clang --version
clang version 11.0.0 (https://github.com/SNSystems/llvm-project-prepo.git 4b09eb0faf6607f15be8c5d296e2d7834f3f73fc)
Target: x86_64-pc-linux-musl-repo
Thread model: posix
InstalledDir: /usr/bin

Run cmake for the upstream llvm-project, I get the following error.

CMake Error at cmake/modules/CheckAtomic.cmake:59 (message):
  Host compiler appears to require libatomic, but cannot find it.
Call Stack (most recent call first):
  cmake/config-ix.cmake:377 (include)
  CMakeLists.txt:727 (include)
:

Reproduce the problem:

  1. cp stdlib to my home folder:

    cd /home/maggie
    cp /usr/local/llvm/lib/stdlib.repo clang.db
  2. Set the REPOFILE to this clang.db

    export REPOFILE=/home/maggie/clang.db
  3. Run cmake for the upstream llvm-project, I get a missing libatomic issue shown below:

    cmake -G Ninja                                                       \
            -DCMAKE_C_COMPILER=repo-clang                                \
            -DCMAKE_CXX_COMPILER=repo-clang++                            \
            -DLLVM_ENABLE_ASSERTIONS=ON                                  \
            -DLLVM_INCLUDE_EXAMPLES=OFF                                  \
            -DLLVM_VERSION_SUFFIX=                                       \
            -DLLVM_BUILD_RUNTIME=ON                                      \
            -DCMAKE_BUILD_TYPE=Release                                   \
            -DLLVM_BUILD_TESTS=ON                                        \
            -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;libcxx;libcxxabi;" \
            ../llvm
    :   
    CMake Error at cmake/modules/CheckAtomic.cmake:59 (message):
    Host compiler appears to require libatomic, but cannot find it.
    Call Stack (most recent call first):
      cmake/config-ix.cmake:377 (include)
      CMakeLists.txt:727 (include)
    :

Possible solution:

MaggieYingYi commented 2 years ago

I found this is fixed by musl libc commit 88e4fd8 .

After installed the empty libraries (e.g. libpthread.a), the cmake passed the following tests.

-- Looking for dlopen in dl
-- Looking for dlopen in dl - found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE

The error is fixed.