llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.97k stars 11.54k forks source link

Configuring libc with libunwind fails #59762

Open oroppas opened 1 year ago

oroppas commented 1 year ago

Hi,

There is an issue with building libc with libunwind from scratch. Here's how I build:

cmake -G Ninja \
      -B build \
      -S llvm-project/llvm \
      -DBUILD_SHARED_LIBS=ON \
      -DCMAKE_BUILD_TYPE=RelWithDebInfo \
      -DCMAKE_C_COMPILER=clang \
      -DCMAKE_CXX_COMPILER=clang++ \
      -DLLVM_TARGETS_TO_BUILD="NVPTX;WebAssembly;X86" \
      -DLLVM_CCACHE_BUILD=ON \
      -DLLVM_ENABLE_LLD=ON \
      -DLLVM_ENABLE_LTO=Thin \
      -DLLVM_ENABLE_LIBCXX=ON \
      -DLLVM_ENABLE_PROJECTS="clang;lld;mlir;flang" \
      -DLLVM_ENABLE_RUNTIMES="libc;libunwind;libcxxabi;libcxx;compiler-rt;openmp" \
      -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-redhat-linux-gnu \
      -DLLVM_HOST_TRIPLE=x86_64-redhat-linux-gnu \
      -DCLANG_DEFAULT_CXX_STDLIB=libc++ \
      -DCLANG_DEFAULT_LINKER=lld \
      -DCLANG_DEFAULT_RTLIB=compiler-rt \
      -DCLANG_DEFAULT_UNWINDLIB=libunwind \
      || exit 1
cmake --build build || exit 1

Removing libc from LLVM_ENABLE_RUNTIMES, the build scceeds.

Here's the snippets of the log:

-- Set COMPILER_RESOURCE_DIR to /home/ryuta/packages/flang/build/lib/clang/16 using --print-resource-dir
-- Building libc for x86_64 on linux
CMake Error at /home/ryuta/packages/flang/llvm-project/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake:83 (message):
  Failed to compile: Change Dir:
  /home/ryuta/packages/flang/build/runtimes/runtimes-bins/libc/check_/CMakeFiles/CMakeTmp

  Run Build Command(s):/usr/bin/ninja-build cmTC_9838c && [1/2] Building CXX
  object CMakeFiles/cmTC_9838c.dir/check_cpu_features.cpp.o

  [2/2] Linking CXX executable cmTC_9838c

  FAILED: cmTC_9838c

  : && /home/ryuta/packages/flang/build/./bin/clang++
  --target=x86_64-redhat-linux-gnu -fPIC -fno-semantic-interposition
  -fvisibility-inlines-hidden -Werror=date-time
  -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter
  -Wwrite-strings -Wcast-qual -Wmissing-field-initializers
  -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type
  -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override
  -Wno-comment -Wstring-conversion -Wmisleading-indentation
  -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections
  -fdata-sections -fuse-ld=lld -Wl,--color-diagnostics
  CMakeFiles/cmTC_9838c.dir/check_cpu_features.cpp.o -o cmTC_9838c && :

  ld.lld: error: unable to find library -lunwind

  ld.lld: error: unable to find library -lunwind

  clang-16: error: linker command failed with exit code 1 (use -v to see
  invocation)

  ninja: build stopped: subcommand failed.

Call Stack (most recent call first):
  /home/ryuta/packages/flang/llvm-project/libc/CMakeLists.txt:123 (include)

-- Configuring incomplete, errors occurred!
See also "/home/ryuta/packages/flang/build/runtimes/runtimes-bins/CMakeFiles/CMakeOutput.log".
See also "/home/ryuta/packages/flang/build/runtimes/runtimes-bins/CMakeFiles/CMakeError.log".
llvmbot commented 1 year ago

@llvm/issue-subscribers-libc

sivachandra commented 1 year ago

Hi, can you try this now with HEAD?

oroppas commented 1 year ago

It passed the configuration but failed to link the test:

[314/326] Linking CXX executable libc/test/src/__support/libc_str_to_float_comparison_test
FAILED: libc/test/src/__support/libc_str_to_float_comparison_test
: && /home/ryutas/packages/llvm/build/./bin/clang++ --target=x86_64-pc-linux-gnu -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG -fuse-ld=lld -Wl,--color-diagnostics libc/test/src/__support/CMakeFiles/libc_str_to_float_comparison_test.dir/str_to_float_comparison_test.cpp.o -o libc/test/src/__support/libc_str_to_float_comparison_test   && cd /home/ryutas/packages/llvm/build/runtimes/runtimes-bins/libc/test/src/__support && /home/ryutas/packages/llvm/build/runtimes/runtimes-bins/libc/test/src/__support/libc_str_to_float_comparison_test /home/ryutas/packages/llvm/llvm-project/libc/test/src/__support/str_to_float_comparison_data.txt
/home/ryutas/packages/llvm/build/runtimes/runtimes-bins/libc/test/src/__support/libc_str_to_float_comparison_test: error while loading shared libraries: libunwind.so.1: cannot open shared object file: No such file or directory
[318/326] Building CXX object libc/test/UnitTest/CMakeFiles/LibcUnitTest.dir/LibcTest.cpp.o
ninja: build stopped: subcommand failed.
FAILED: runtimes/runtimes-stamps/runtimes-build /home/ryutas/packages/llvm/build/runtimes/runtimes-stamps/runtimes-build
cd /home/ryutas/packages/llvm/build/runtimes/runtimes-bins && /usr/bin/cmake --build .
ninja: build stopped: subcommand failed.
sivachandra commented 1 year ago

Can you disable tests with -DLLVM_INCLUDE_TESTS=OFF?

oroppas commented 1 year ago

Yup. It worked!

oroppas commented 1 year ago

Hmm, with clean build, I've got the different configure error:

[6169/6207] Performing configure step for 'runtimes'
Not searching for unused variables given on the command line.
-- The C compiler identification is Clang 17.0.0
-- The CXX compiler identification is Clang 17.0.0
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /home/ryuta/packages/flang/build/./bin/clang
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find Terminfo (missing: Terminfo_LIBRARIES Terminfo_LINKABLE) 
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.12")
-- Found LibXml2: /usr/lib64/libxml2.so (found version "2.10.3") 
-- Could NOT find Terminfo (missing: Terminfo_LIBRARIES Terminfo_LINKABLE) 
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.12")
-- Performing Test LLVM_RUNTIMES_LINKING_WORKS
-- Performing Test LLVM_RUNTIMES_LINKING_WORKS - Failed
-- Performing Test CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG
-- Performing Test CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG - Failed
-- Performing Test CXX_SUPPORTS_NOSTDLIBXX_FLAG
-- Performing Test CXX_SUPPORTS_NOSTDLIBXX_FLAG - Failed
-- Performing Test CXX_SUPPORTS_NOSTDINCXX_FLAG
-- Performing Test CXX_SUPPORTS_NOSTDINCXX_FLAG - Failed
CMake Warning (dev) at /usr/share/cmake/Modules/GNUInstallDirs.cmake:243 (message):
  Unable to determine default CMAKE_INSTALL_LIBDIR directory because no
  target architecture is known.  Please enable at least one language before
  including GNUInstallDirs.
Call Stack (most recent call first):
  /home/ryuta/packages/flang/llvm-project/llvm/cmake/modules/AddLLVM.cmake:1 (include)
  CMakeLists.txt:156 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Linker detection: LLD
-- Performing Test CXX_SUPPORTS_CUSTOM_LINKER
-- Performing Test CXX_SUPPORTS_CUSTOM_LINKER - Failed
CMake Error at /home/ryuta/packages/flang/llvm-project/llvm/cmake/modules/HandleLLVMOptions.cmake:326 (message):
  Host compiler does not support '-fuse-ld=lld'
Call Stack (most recent call first):
  CMakeLists.txt:157 (include)

-- Configuring incomplete, errors occurred!

Checking build/runtimes/runtimes-bins/CMakeFiles/CMakeConfigureLog.yaml

    kind: "try_compile-v1"
    backtrace:
      - "/usr/share/cmake/Modules/Internal/CheckSourceCompiles.cmake:101 (try_compile)"
      - "/usr/share/cmake/Modules/CheckCXXSourceCompiles.cmake:76 (cmake_check_source_compiles)"
      - "/home/ryuta/packages/flang/llvm-project/llvm/cmake/modules/HandleLLVMOptions.cmake:324 (check_cxx_source_compiles)"
      - "CMakeLists.txt:157 (include)"
    checks:
      - "Performing Test CXX_SUPPORTS_CUSTOM_LINKER"
    directories:
      source: "/home/ryuta/packages/flang/build/runtimes/runtimes-bins/CMakeFiles/CMakeScratch/TryCompile-FpjrYD"
      binary: "/home/ryuta/packages/flang/build/runtimes/runtimes-bins/CMakeFiles/CMakeScratch/TryCompile-FpjrYD"
    cmakeVariables:
      CMAKE_CXX_COMPILER_TARGET: "x86_64-redhat-linux-gnu"
      CMAKE_CXX_FLAGS: ""
      CMAKE_CXX_FLAGS_DEBUG: "-g"
      CMAKE_C_COMPILER_TARGET: "x86_64-redhat-linux-gnu"
      CMAKE_EXE_LINKER_FLAGS: " -fuse-ld=lld"
      CMAKE_MODULE_PATH: "/home/ryuta/packages/flang/llvm-project/runtimes/cmake;/home/ryuta/packages/flang/llvm-project/runtimes/cmake/modules;/home/ryuta/packages/flang/llvm-project/runtimes/../cmake;/home/ryuta/packages/flang/llvm-project/runtimes/../cmake/Modules;/home/ryuta/packages/flang/llvm-project/runtimes/../llvm/cmake;/home/ryuta/packages/flang/llvm-project/runtimes/../llvm/cmake/modules;/home/ryuta/packages/flang/build/lib/cmake/llvm;/home/ryuta/packages/flang/build/lib/cmake/llvm"
    buildResult:
      variable: "CXX_SUPPORTS_CUSTOM_LINKER"
      cached: true
      stdout: |
        Change Dir: /home/ryuta/packages/flang/build/runtimes/runtimes-bins/CMakeFiles/CMakeScratch/TryCompile-FpjrYD

        Run Build Command(s):/usr/bin/ninja-build -v cmTC_5a78d && [1/2] /home/ryuta/packages/flang/build/./bin/clang++ --target=x86_64-redhat-linux-gnu -DCXX_SUPPORTS_CUSTOM_LINKER   -MD -MT CMakeFiles/cmTC_5a78d.dir/src.cxx.o -MF CMakeFiles/cmTC_5a78d.dir/src.cxx.o.d -o CMakeFiles/cmTC_5a78d.dir/src.cxx.o -c /home/ryuta/packages/flang/build/runtimes/runtimes-bins/CMakeFiles/CMakeScratch/TryCompile-FpjrYD/src.cxx
        [2/2] : && /home/ryuta/packages/flang/build/./bin/clang++ --target=x86_64-redhat-linux-gnu  -fuse-ld=lld CMakeFiles/cmTC_5a78d.dir/src.cxx.o -o cmTC_5a78d   && :
        FAILED: cmTC_5a78d 
        : && /home/ryuta/packages/flang/build/./bin/clang++ --target=x86_64-redhat-linux-gnu  -fuse-ld=lld CMakeFiles/cmTC_5a78d.dir/src.cxx.o -o cmTC_5a78d   && :
        ld.lld: error: unable to find library -lunwind
        ld.lld: error: unable to find library -lunwind
        clang++: error: linker command failed with exit code 1 (use -v to see invocation)
        ninja: build stopped: subcommand failed.

      exitCode: 1
...

It's having trouble finding libunwind.so but find build -name "libunwind.*" finds nothing. There's something wrong with cmake configure sequence?