Skip to content

Commit

Permalink
Update llvm version (#416)
Browse files Browse the repository at this point in the history
This updates jazzer.js to use the latest version of our LLVM fork which
fixes build issues for LLVM 16
  • Loading branch information
br-lewis committed May 9, 2023
1 parent f5e07bf commit 13e1d24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/run-all-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get install software-properties-common
sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main'
sudo apt-get install clang-tidy-15
sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main'
sudo apt-get install clang-tidy-16
sudo rm -f /usr/bin/clang-tidy
sudo ln -s /usr/bin/clang-tidy-15 /usr/bin/clang-tidy
sudo ln -s /usr/bin/clang-tidy-16 /usr/bin/clang-tidy
- name: build fuzzer
# Build the native addon so that CMake generates compile_commands.json that is needed by clang-tidy
run: npm run build --workspace=@jazzer.js/fuzzer
Expand Down
35 changes: 33 additions & 2 deletions packages/fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,42 @@ set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})

# We're not sure why but sometimes systems don't end up setting LLVM_TARGET_TRIPLE used in llvm's cmake to eventually
# set COMPILER_RT_DEFAULT_TARGET which is necessary for compiler-rt to build
# So this will either take it from an envvar or try to set it to a sane value until we can figure out why it's broken
if(NOT DEFINED ENV{COMPILER_RT_DEFAULT_TARGET_TRIPLE})
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} "-print-target-triple" OUTPUT_VARIABLE COMPILER_RT_DEFAULT_TARGET_TRIPLE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} "-dumpmachine" OUTPUT_VARIABLE COMPILER_RT_DEFAULT_TARGET_TRIPLE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# pulled from https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/GetHostTriple.cmake
if( CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "ARM64.*" )
set( COMPILER_RT_DEFAULT_TARGET_TRIPLE "aarch64-pc-windows-msvc" )
elseif( CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "ARM.*" )
set( COMPILER_RT_DEFAULT_TARGET_TRIPLE "armv7-pc-windows-msvc" )
elseif( CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "x64" )
set( COMPILER_RT_DEFAULT_TARGET_TRIPLE "x86_64-pc-windows-msvc" )
elseif( CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "X86" )
set( COMPILER_RT_DEFAULT_TARGET_TRIPLE "i686-pc-windows-msvc" )
elseif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set( COMPILER_RT_DEFAULT_TARGET_TRIPLE "x86_64-pc-windows-msvc" )
else()
set( COMPILER_RT_DEFAULT_TARGET_TRIPLE "i686-pc-windows-msvc" )
endif()
endif()
# strip whitespace because newlines from the shell calls will break the cmake call
string(STRIP ${COMPILER_RT_DEFAULT_TARGET_TRIPLE} COMPILER_RT_DEFAULT_TARGET_TRIPLE)
message(STATUS "COMPILER_RT_DEFAULT_TARGET_TRIPLE not set, using ${COMPILER_RT_DEFAULT_TARGET_TRIPLE}")
endif()

# Download and build compiler-rt, which contains libfuzzer.
include(ExternalProject)
ExternalProject_Add(
compiler-rt
URL https://github.com/CodeIntelligenceTesting/llvm-project-jazzer/archive/refs/tags/2022-11-25.tar.gz
URL https://github.com/CodeIntelligenceTesting/llvm-project-jazzer/archive/refs/tags/2023-04-25.tar.gz
URL_HASH
SHA256=e691dc9b45c35713fa67c613d352b646f30cab5d35d15abfcf77cc004a3befdb
SHA256=200b32c897b1171824462706f577d7f1d6175da602eccfe570d2dceeac11d490
SOURCE_SUBDIR compiler-rt
CMAKE_ARGS # compiler-rt usually initializes the sanitizer runtime by means of
# a pointer in the .preinit_array section; since .preinit_array
Expand All @@ -90,6 +119,8 @@ ExternalProject_Add(
-DCOMPILER_RT_USE_LIBCXX=OFF
# Use the same build type as the parent project.
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=${COMPILER_RT_DEFAULT_TARGET_TRIPLE}
-DLLVM_CMAKE_DIR=<SOURCE_DIR>/llvm/cmake/modules
# We only need libfuzzer from the compiler-rt project.
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target
${LIBFUZZER_TARGET}
Expand Down

0 comments on commit 13e1d24

Please sign in to comment.