<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63311>63311</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
unittests build does not respect CMAKE_EXE_LINKER_FLAGS, PipSqueak fails to link for MemorySanitizer
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
FlashSheridan
</td>
</tr>
</table>
<pre>
## Summary
Trying to build our LLVM fork for MemorySanitizer with a local libc++ per [MemorySanitizerBootstrappingClang](https://github.com/google/sanitizers/wiki/MemorySanitizerBootstrappingClang) fails with “ld.lld: error: unable to find library -lc++” trying to link unittests/Support/DynamicLibrary/CMakeFiles/SecondLib.dir/PipSqueak.cpp.o. If I add `add_link_options(-L<my custom libc++ path>)` to llvm/unittests/CMakeLists.txt, the file links. Except for the unittests, this directory is correctly propagated to the clang++ command from the -DCMAKE_EXE_LINKER_FLAGS argument, as in [MemorySanitizerBootstrappingClang#building-clang](https://github.com/google/sanitizers/wiki/MemorySanitizerBootstrappingClang#building-clang).
## Details
(See also “Configuration Workarounds” below.)
If I add the following arguments to our build system (a front-end to CMake and Ninja) `\\--debug-trycompile \\-DCMAKE_BUILD_TYPE=Release \\-DLLVM_ENABLE_PROJECTS="clang;lld" \\-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/x86_64-unknown-linux-gnu -L$LIBCXX_DIR/lib/x86_64-unknown-linux-gnu -fsanitize=memory"`, the clang++ command for the failing link step contains my custom include directories, but is missing the lib directory, so it is understandably “unable to find library -lc++””:
(Expanded with (\s"?-+) ⇒ \n\1 for clarity)
```
: && /usr/bin/clang++
-fPIC
-nostdinc++
-isystem /home/zekebot/Documents/Code/External_Code/Llvm-15.0.4_for_libcxx/build_libcxx//include
-isystem /home/zekebot/Documents/Code/External_Code/Llvm-15.0.4_for_libcxx/build_libcxx//include/c++/v1
-stdlib=libc++
-fvisibility-inlines-hidden
-Wall
-Wextra
-Wno-unused-parameter
-Wwrite-strings
-Wcast-qual
-Wmissing-field-initializers
-pedantic
-Wno-long-long
-Wno-noexcept-type
-Wnon-virtual-dtor
-Wdelete-non-virtual-dtor
-Wsuggest-override
-Wno-comment
-fsanitize=memory
-fsanitize-memory-track-origins
-fdiagnostics-color
-O3
-DNDEBUG
-stdlib=libc++
-fuse-ld=lld
-Wl,--color-diagnostics
-fsanitize=memory
-fsanitize-recover=memory
-shared
-o unittests/Support/DynamicLibrary/PipSqueak.so unittests/Support/DynamicLibrary/CMakeFiles/PipSqueak.dir/PipSqueak.cpp.o && :
```
## Configuration
Ubuntu 22.04.1 LTS (Jammy Jellyfish) x86_64
Ubuntu clang version 15.0.6
Target: x86_64-pc-linux-gnu
### Configuration Workarounds
- $LIBCXX_DIR/lib in MemorySanitizerBootstrappingClang doc needs platform name appended (https://github.com/google/sanitizers/issues/1661)
- https://github.com/llvm/llvm-project/issues/57104#issuecomment-1278598494
## See Also
- [MemorySanitizerBootstrappingClang Wiki building instructions out of date #1230](https://github.com/google/sanitizers/issues/1230)
- [MemorySanitizerLibcxxHowTo wiki page has deprecated build instructions. #1574](https://github.com/google/sanitizers/issues/1574)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV1Fz4jgS_jXiRSXKloHAAw-AYS-zTGZqyFxy90LJVmO0yJJXkpOwv_5KsjGEZHazc1V3VSliSa1Wq_vrr1vMWlEogCkaztEw7bHa7bWZriSz-80ejOBM9TLNj1NEE0QTvKnLkpkjilIUzZrfe3MUqsBO46wWkmNdG7xe__Mz3mlz8D_4M5TaHDdMCSf-AIOfhdtjhqXOmcRSZDmic0TnuAK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