Derived from llvm error when attempt to build libcxx instrumented with memory sanitizer
I am attempting to build LLVM with the libcxx and libcxxabi projects instrumented with MemorySanitizer (Msan) for debugging uninitialized memory usage in my C++ applications. However, I'm encountering errors during the build process.
Steps Taken
First, I executed the following CMake command successfully:
cmake -GNinja ../llvm \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DLLVM_USE_SANITIZER=MemoryWithOrigins
After running the command, I attempted to build LLVM using Ninja:
ninja -C ~/llvm-project/build -j2
Error Output Perhaps, I received the following MemorySanitizer error output:
#7 0x555f2def5c9c in llvm::RecordKeeper::addClass(std::unique_ptr<llvm::Record, std::default_delete<llvm::Record> >) /home/j/llvm-project/llvm/include/llvm/TableGen/Record.h:2027:24
#8 0x555f2def3f4 in llvm::TGParser::ParseClass() /home/j/llvm-project/llvm/lib/TableGen/TGParser.cpp:4008:13
#9 0x555f2def0bd7 in llvm::TGParser::ParseObject(llvm::MultiClass*) /home/j/llvm-project/llvm/lib/TableGen/TGParser.cpp:4377:12
#10 0x555f2df00c6a in ParseObjectList /home/j/llvm-project/llvm/lib/TableGen/TGParser.cpp:4389:9
#11 0x555f2df00c6a in llvm::TGParser::ParseFile() /home/j/llvm-project/llvm/lib/TableGen/TGParser.cpp:4398:7
#12 0x555f2ddb4772 in llvm::TableGenMain(char const*, std::function<bool (llvm::raw_ostream&, llvm::RecordKeeper const&)>) /home/j/llvm-project/llvm/lib/TableGen/Main.cpp:127:14
#13 0x555f2db78c32 in main /home/j/llvm-project/llvm/utils/TableGen/TableGen.cpp:81:10
#14 0x7ff357429d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
SUMMARY: MemorySanitizer: use-of-uninitialized-value /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_tree.h:1336:4 in _M_lower_bound_tr<llvm::StringRef, void>
Exiting
ninja: build stopped: subcommand failed.
Purpose of Building with MemorySanitizer
The only reason I am building LLVM with the line -DLLVM_USE_SANITIZER=MemoryWithOrigins is to fix the MemorySanitizer issue, as it throws an error for the use of uninitialized values. According to the MemorySanitizer GitHub page, building LLVM with this flag is necessary.
When I disable this flag, the build completes successfully, but I lose the ability to diagnose uninitialized memory issues.
Question
How can I successfully build LLVM with MemorySanitizer enabled without encountering these errors? Are there any specific flags or configurations I should try?
"I'm encountering errors during the build process": what errors? Please show them in your question as text verbatim.