llvm / llvm-project

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

CMake configuration failure while trying to build libc++: "/usr/lib/llvm-19/lib/libLibcTableGenUtil.a" but this file does not exist. #99819

Open Zingam opened 2 months ago

Zingam commented 2 months ago

@sylvestre reporting as suggested here: https://github.com/llvm/llvm-project/issues/92359 I am trying to build libc++ on WSL Ubuntu 24.04. LLVM19 was installed originally via llvm.sh. I updated today.

$ clang --version Ubuntu clang version 19.0.0 (++20240721081714+0caf0c93e759-1~exp1~20240721081828.299) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/lib/llvm-19/bin

I build via VSCode and I have the following CMakePresets.json file put in /runtimes

{
    "version": 9,
    "cmakeMinimumRequired": {
      "major": 3,
      "minor": 30,
      "patch": 0
    },
    "configurePresets": [
      {
        "name": "default",
        "displayName": "Default Config",
        "description": "Default build using Ninja generator",
        "hidden": true,
        "generator": "Ninja",
        "binaryDir": "${sourceParentDir}/build/${presetName}"
      },
      {
        "name": "default.debug.libcxx",
        "displayName": "Debug libc++",
        "description": "libc++ debug configuration",
        "inherits": [
          "default"
        ],
        "cacheVariables": {
          "LLVM_ENABLE_RUNTIMES": {
            "type": "STRING",
            "value": "libcxx;libcxxabi;libunwind"
          },
          "CMAKE_EXPORT_COMPILE_COMMANDS": {
            "type": "BOOL",
            "value": "ON"
          },
          "CMAKE_BUILD_TYPE": {
            "type": "STRING",
            "value": "Debug"
          },
          "LIBCXX_ENABLE_DEBUG_MODE": {
            "type": "BOOL",
            "value": "ON"
          },
          "LIBCXX_HARDENING_MODE": {
            "type": "STRING",
            "value": "debug"
          },
          "CMAKE_C_COMPILER": {
            "type": "STRING",
            "value": "clang"
          },
          "CMAKE_CXX_COMPILER": {
            "type": "STRING",
            "value": "clang++"
          }
        }
      }
    ],
    "buildPresets": [
      {
        "name": "default",
        "configurePreset": "default.debug.libcxx"
      }
    ]
  }

[cmake] -- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR) [cmake] CMake Error at /usr/lib/llvm-19/lib/cmake/llvm/LLVMExports.cmake:1914 (message): [cmake] The imported target "LibcTableGenUtil" references the file [cmake] [cmake] "/usr/lib/llvm-19/lib/libLibcTableGenUtil.a" [cmake] [cmake] but this file does not exist. Possible reasons include: [cmake] [cmake] The file was deleted, renamed, or moved to another location. [cmake] [cmake] An install or uninstall procedure did not complete successfully. [cmake] [cmake] * The installation package was faulty and contained [cmake] [cmake] "/usr/lib/llvm-19/lib/cmake/llvm/LLVMExports.cmake" [cmake] [cmake] but not all the files it references. [cmake] [cmake] Call Stack (most recent call first): [cmake] /usr/lib/llvm-19/lib/cmake/llvm/LLVMConfig.cmake:370 (include) [cmake] /usr/lib/cmake/clang-19/ClangConfig.cmake:11 (find_package) [cmake] /home/hristo/Projects/llvm-project/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt:11 (find_package) [cmake] [cmake] [cmake] -- Configuring incomplete, errors occurred!

Zingam commented 2 months ago

Same if I install LLVM20:

[cmake] The imported target "LibcTableGenUtil" references the file [cmake] [cmake] "/usr/lib/llvm-20/lib/libLibcTableGenUtil.a"

Zingam commented 2 months ago

Same if I install LLVM18:

[cmake] CMake Error at /usr/lib/llvm-18/lib/cmake/clang/ClangTargets.cmake:833 (message): [cmake] The imported target "clangBasic" references the file [cmake] [cmake] "/usr/lib/llvm-18/lib/libclangBasic.a"

dr-m commented 1 month ago

@Zingam, can you please explain how this was fixed or can be worked around? I am running into this same issue when trying to build a -fsanitize=memory instrumented libc++ on a Debian Sid system, using clang-19 from 1:19.1.0~++20240813124017+28f2d04b3ca3-1~exp1~20240813124123.26 and invoking this script attached to this ticket with CLANG=19.

It would be very convenient if a -fsanitize=memory instrumented libc++.so could be made available in the LLVM package repositories, because it would basically bring the same level of support for C and C++. (For C, there are built-in interceptors for the GNU libc.)

H-G-Hristov commented 1 month ago

@dr-m Have you tried installing libllvmlibc-20-dev:

image

dr-m commented 1 month ago

Thank you. I was missing the packages libllvmlibc-19-dev and libclang-19-dev.

I also adjusted my build script slightly (not sure if all that is needed):

--- build-msan18.sh
+++ build-msan19.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 set -eux
-: ${CLANG=18}
+: ${CLANG=19}
 : ${MSAN_LIBDIR=..}
 : ${PARALLEL=$(nproc)}

@@ -15,14 +15,17 @@
 fi

 sudo apt -o APT::Get::Assume-Yes=true install \
-    clang-$CLANG libc++-$CLANG-dev libc++abi-$CLANG-dev automake
+    clang-$CLANG libc++-$CLANG-dev libc++abi-$CLANG-dev \
+    libclang-$CLANG-dev libllvmlibc-$CLANG-dev automake
 apt -o APT::Get::Assume-Yes=true source \
     llvm-toolchain-$CLANG libgnutls28-dev libnettle8 libidn2 libgmp10

 mkdir -p ll-build
 cd ll-build
 cmake ../llvm-toolchain-$CLANG-$CLANG.*/runtimes -DCMAKE_BUILD_TYPE=Release \
-      -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
+      -DLLVM_ENABLE_RUNTIMES="libc;libcxx;libcxxabi;libunwind" \
+      -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_DOCS=OFF \
+      -DLLVM_ENABLE_SPHINX=OFF \
       -DCMAKE_C_COMPILER=clang-$CLANG \
       -DCMAKE_CXX_COMPILER=clang++-$CLANG \
       -DLLVM_USE_SANITIZER=MemoryWithOrigins

This exercise was rewarded: I got the fix D158943 that I was looking for. (Note: the automake in the above diff is not related to clang, but some other libraries that I need to compile with -fsanitize=memory.)

Still, it would be really great if a -fsanitize=memory instrumented libc++ package could be provided. After all, -fsanitize=memory is rather useless for pretty much any C++ code without that.

Zingam commented 1 month ago

Thank you. I was missing the packages libllvmlibc-19-dev and libclang-19-dev.

Great! Now the real question would be: Why the llvm.sh script fails to install these?

dr-m commented 1 month ago

I’m sorry, I just now realize that there could be an officially maintained llvm.sh script that I might use to avoid issues when compiling libc++ for various LLVM versions. Where is that script available? I could not find it on my system or in the package search at https://packages.debian.org.

I am using my own script, which my comments identify. The title of this ticket does exactly match my usage scenario: trying to build a -fsanitizer=memory instrumented version of libc++. There was no build-time dependency on libclang-18-dev or libllvmlibc-18-dev for the libc++ of LLVM 18.

Zingam commented 4 weeks ago

@dr-m Please check: https://apt.llvm.org/

dr-m commented 2 weeks ago

@Zingam Thank you. I see that https://apt.llvm.org/llvm.sh would install some packages, some of which would be redundant for what I am trying to achieve. I only want to build libc++ with -fsanitize=memory, possibly as part of a minimal Docker image. I don’t think that tools like clang-tidy, clang-format, or lldb would be needed to achieve that.

Zingam commented 1 week ago

[cmake] CMake Error at /usr/lib/llvm-20/lib/cmake/clang/ClangTargets.cmake:847 (message): [cmake] The imported target "clangBasic" references the file [cmake] [cmake] "/usr/lib/llvm-20/lib/libclangBasic.a" [cmake] [cmake] but this file does not exist. Possible reasons include: [cmake] [cmake] The file was deleted, renamed, or moved to another location. [cmake] [cmake] An install or uninstall procedure did not complete successfully. [cmake] [cmake] * The installation package was faulty and contained [cmake] [cmake] "/usr/lib/llvm-20/lib/cmake/clang/ClangTargets.cmake" [cmake] [cmake] but not all the files it references.

libclang-20-dev Clang library - Development package

Zingam commented 1 week ago

[cmake] CMake Error at /usr/lib/llvm-20/lib/cmake/clang/ClangTargets.cmake:847 (message): [cmake] The imported target "clang-cpp" references the file [cmake] [cmake] "/usr/lib/llvm-20/lib/libclang-cpp.so.20.0" [cmake] [cmake] but this file does not exist. Possible reasons include: [cmake] [cmake] The file was deleted, renamed, or moved to another location. [cmake] [cmake] An install or uninstall procedure did not complete successfully. [cmake] [cmake] * The installation package was faulty and contained [cmake] [cmake] "/usr/lib/llvm-20/lib/cmake/clang/ClangTargets.cmake"

libclang-cpp20-dev C++ interface to the Clang library

Zingam commented 1 week ago

[cmake] CMake Error at /usr/lib/llvm-20/lib/cmake/clang/ClangTargets.cmake:847 (message): [cmake] The imported target "clang-cpp" references the file [cmake] [cmake] "/usr/lib/llvm-20/lib/libclang-cpp.so.20.0" [cmake] [cmake] but this file does not exist.

Does the package contain the wrong path:

image

sylvestre commented 1 week ago

@Zingam please open new issues as they are different problems. Also, please don't share screenshot, they are terrible for accessibility and search thanks

Zingam commented 1 week ago

Superseded by the linked issue.

Zingam commented 1 week ago

@sylvestre Thanks. I already created a new issue and closed this one: https://github.com/llvm/llvm-project/issues/109153

Zingam commented 4 days ago

I noticed this issue in the libc++ CI now: https://github.com/llvm/llvm-project/actions/runs/11008128330/job/30565201169?pr=109291

Maybe it wasn't fixed.

sylvestre commented 4 days ago

ok, working on it i started a build to see if my fix worked

zibi2 commented 3 days ago

I got same error in CI this morning at build 109693.

sylvestre commented 3 days ago

@zibi2 which versions ? (ubuntu and llvm)

zibi2 commented 3 days ago

@zibi2 which versions ? (ubuntu and llvm)

Not sure about version of Ubuntu since I don't have access to CI systems. All I can do is look at logs in the link I provided. I see the version of llvm must be 19 based on this from the log:

2024-09-25T15:08:12.9312931Z Ubuntu clang version 19.1.0 (++20240920111944+64075837b553-1~exp1~20240920111958.43)
2024-09-25T15:08:12.9314477Z Target: x86_64-pc-linux-gnu
2024-09-25T15:08:12.9314921Z Thread model: posix
2024-09-25T15:08:12.9315400Z InstalledDir: /usr/lib/llvm-19/bin
ldionne commented 3 days ago

Note: I've disabled the clang-tidy checks from the libc++ CI to get our CI back online, so this issue shouldn't be visible when running the libc++ CI anymore. But the issue is real, thanks for investigating it.