Description
In https://github.com/google/sanitizers/wiki/MemorySanitizerBootstrappingClang#building-clang, the two occurrences of $LIBCXX_DIR/lib
in the last line of the following command need to have LLVM_DEFAULT_TARGET_TRIPLE appended, at least for some configurations:
cmake -GNinja ../llvm \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DLLVM_USE_SANITIZER=MemoryWithOrigins \
-DLLVM_ENABLE_LIBCXX=ON \
-DCMAKE_CXX_FLAGS=" -nostdinc++ -isystem $LIBCXX_DIR/include -isystem $LIBCXX_DIR/include/c++/v1" \
-DCMAKE_EXE_LINKER_FLAGS=" -stdlib=libc++ -Wl,--rpath=$LIBCXX_DIR/lib -L$LIBCXX_DIR/lib -fsanitize=memory"
In my configuration, the CMake check fails with “cannot find -lc++”. The result of the instructions in the preceding section (“Building libcxx and libcxxabi“) has libc++.a
and friends in $LIBCXX_DIR/lib/x86_64-unknown-linux-gnu/
, not $LIBCXX_DIR/lib
.
This seems to be fairly common, e.g. the following code in
https://github.com/llvm/llvm-project/blob/main/libcxx/CMakeLists.txt#L411
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
See Also
- MemorySanitizerBootstrappingClang Wiki building instructions out of date #1230
- MemorySanitizerLibcxxHowTo wiki page has deprecated build instructions. #1574
Configuration
Ubuntu 22.04.1 LTS (Jammy Jellyfish) x86_64
Ubuntu clang version 15.0.6
Target: x86_64-pc-linux-gnu