Building images with LLVM 16
Navidem opened this issue · comments
I started looking into having base-clang and dispatcher use LLVM 16.
base-clang is not building successfully after following changes:
- Pin calng to
12149f209bf6a9ac6db64742ad9417922cebc232
- use
OUR_LLVM_REVISION=llvmorg-16-init-12251-g87d0ff91
- using
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi"
The error I get is when Targeting X86
:
[810/812] Performing configure step for 'runtimes'
CMake Error at /usr/local/share/cmake-3.24/Modules/CMakeDetermineCCompiler.cmake:49 (message):
Could not find compiler set in environment variable CC:
/work/llvm-stage1/bin/clang.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_ASM_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
When I make it to use the chromium's clang (the one in /work/llvm-stage1/bin/clang
), it fails with this:
SUMMARY: MemorySanitizer: use-of-uninitialized-value /src/llvm-project/llvm/include/llvm/ADT/StringRef.h:298:29 in find
Exiting
[445/816] Building IntrinsicsSPIRV.h...
FAILED: include/llvm/IR/IntrinsicsSPIRV.h /work/msan/include/llvm/IR/IntrinsicsSPIRV.h
cd /work/msan && /work/msan/bin/llvm-tblgen -gen-intrinsic-enums -intrinsic-prefix=spv -I /src/llvm-project/llvm/include/llvm/IR -I/work/msan/include -I/src/llvm-project/llvm/include /src/llvm-project/llvm/include/llvm/IR/Intrinsics.td --write-if-changed -o include/llvm/IR/IntrinsicsSPIRV.h -d include/llvm/IR/IntrinsicsSPIRV.h.d
Uninitialized bytes in __interceptor_memchr at offset 6 inside [0x702000000660, 7)
==26568==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x56113bfbc8b0 in find /src/llvm-project/llvm/include/llvm/ADT/StringRef.h:298:29
#1 0x56113bfbc8b0 in llvm::StringRef::split(llvm::SmallVectorImpl<llvm::StringRef>&, char, int, bool) const /src/llvm-project/llvm/lib/Support/StringRef.cpp:360:20
#2 0x56113bfc6560 in llvm::Triple::Triple(llvm::Twine const&) /src/llvm-project/llvm/lib/Support/Triple.cpp:889:19
#3 0x56113bfff3ea in llvm::sys::getProcessTriple[abi:cxx11]() /src/llvm-project/llvm/lib/Support/Host.cpp:1841:10
#4 0x56113bf7a483 in ParseCommandLineOptions /src/llvm-project/llvm/lib/Support/CommandLine.cpp:1507:35
#5 0x56113bf7a483 in llvm::cl::ParseCommandLineOptions(int, char const* const*, llvm::StringRef, llvm::raw_ostream*, char const*, bool) /src/llvm-project/llvm/lib/Support/CommandLine.cpp:1470:24
#6 0x56113bf24bf9 in main /src/llvm-project/llvm/utils/TableGen/TableGen.cpp:289:3
#7 0x7fbcbb9e9082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)
#8 0x56113b8b3b8d in _start (/work/msan/bin/llvm-tblgen+0x34b8d)
SUMMARY: MemorySanitizer: use-of-uninitialized-value /src/llvm-project/llvm/include/llvm/ADT/StringRef.h:298:29 in find
Exiting
ninja: build stopped: subcommand failed.
The command '/bin/sh -c /root/checkout_build_install_llvm.sh' returned a non-zero code: 1
Update: the correct way is setting the compilers as follows, but the MSan
failure still persists.
export CC=clang
export CXX=clang++
I started looking into having base-clang and dispatcher use LLVM 16.
base-clang is not building successfully after following changes:
- Pin calng to
12149f209bf6a9ac6db64742ad9417922cebc232
- use
OUR_LLVM_REVISION=llvmorg-16-init-12251-g87d0ff91
The error I get is when
Targeting X86
:[810/812] Performing configure step for 'runtimes' CMake Error at /usr/local/share/cmake-3.24/Modules/CMakeDetermineCCompiler.cmake:49 (message): Could not find compiler set in environment variable CC: /work/llvm-stage1/bin/clang. Call Stack (most recent call first): CMakeLists.txt:3 (project) CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage CMake Error: CMAKE_ASM_COMPILER not set, after EnableLanguage -- Configuring incomplete, errors occurred!
btw i'm not sure we want to upgrade fuzzbench before oss-fuzz
btw i'm not sure we want to upgrade fuzzbench before oss-fuzz
Sure, made this issue to keep track of this even for a local image upgrade.
UPDATE: I am able to build base-clang with llvm16.
The missing part was that the cmake_libcxx
function in the checkout_build_install_llvm.sh
should use $LLVM_SRC/runtimes
for source.
Nice!
+1 Awesome to see!
Posting here to share the result: With the above changes, base-images are built successfully but projects fail to build.
We still needed to update infra/base-images/base-builder/compile_libfuzzer
as the following:
-cp /usr/local/lib/clang/*/lib/linux/libclang_rt.fuzzer-$ARCHITECTURE.a \
+cp /usr/local/lib/clang/*/lib/$ARCHITECTURE-unknown-linux-gnu/libclang_rt.fuzzer.a \
Projects still fail, read next comment to fix.
This was very strange, the project build (both OSS-Fuzz and FuzzBench) were failing.
For OSS-Fuzz I get the many undefined references:
clang++ -O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fprofile-instr-generate -fcoverage-mapping -pthread -Wl,--no-as-needed -Wl,-ldl -Wl,-lm -Wno-unused-command-line-argument -stdlib=libc++ -o
/out/bzip2_compress_target /out/bzip2_compress_target.o -fsanitize=fuzzer libbz2.a
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25
/usr/local/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer.a(FuzzerIO.cpp.o): in function `fuzzer::FileToVector(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, bool)': FuzzerIO.cpp:(.text._ZN6fuzzer12FileToVectorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmb+0x2a): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::__cxx11::basic_string<char, std::ch
ar_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)' /usr/bin/ld: FuzzerIO.cpp:(.text._ZN6fuzzer12FileToVectorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmb+0x5d): undefined reference to `std::istream::seekg(long, std::_Ios_Seekdir)'
/usr/bin/ld: FuzzerIO.cpp:(.text._ZN6fuzzer12FileToVectorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmb+0x65): undefined reference to `std::istream::tellg()' /usr/bin/ld: FuzzerIO.cpp:(.text._ZN6fuzzer12FileToVectorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmb+0x8e): undefined reference to `std::istream::seekg(long, std::_Ios_Seekdir)'
/usr/bin/ld: FuzzerIO.cpp:(.text._ZN6fuzzer12FileToVectorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmb+0xe1): undefined reference to `std::istream::read(char*, long)'
After spending multiple hours, I found out the solution. When building clang, we HAVE TO use -DLLVM_ENABLE_RUNTIMES=compiler-rt
. The llvm docs indicates that compiler-rt
should be in -DLLVM_ENABLE_PROJECTS
. But it is not working at least for us (for reasons unknown to me). In this discussion MaskRay says
For compiler-rt, perhaps we can say -DLLVM_ENABLE_RUNTIMES=compiler-rt is strongly recommended, though -DLLVM_ENABLE_PROJECTS=compiler-rt works.
That is not working, so in our checkout_build_install_llvm.sh
using
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;compiler-rt"
fixes the project build failures.