Skip to content

fix(deps): only require LLVM when building the LLVM pass - #49

Open
w00tzenheimer wants to merge 1 commit into
trailofbits:masterfrom
w00tzenheimer:fix-deps-llvm-unconditional
Open

fix(deps): only require LLVM when building the LLVM pass#49
w00tzenheimer wants to merge 1 commit into
trailofbits:masterfrom
w00tzenheimer:fix-deps-llvm-unconditional

Conversation

@w00tzenheimer

Copy link
Copy Markdown

Problem

dependencies/CMakeLists.txt includes llvm.cmake unconditionally. With the
default USE_EXTERNAL_LLVM=ON that reaches
find_package(LLVM REQUIRED CONFIG) at dependencies/llvm.cmake:8, so every
dependency build fails unless a system LLVM is installed. Setting
USE_EXTERNAL_LLVM=OFF avoids that only by building LLVM from source.

Neither is needed for cobra-core, which references zero LLVM symbols:

$ nm -u build/lib/core/libcobra-core.a | grep -c -i llvm
0

LLVM is used only by lib/llvm, which the main project already gates on
COBRA_BUILD_LLVM_PASS (CMakeLists.txt:64). The superbuild was missing the
same gate.

Fix

Gate include(llvm.cmake) on COBRA_BUILD_LLVM_PASS, matching the main
project. Default is unchanged (OFF), so builds that do want the pass plugin
behave exactly as before by passing -DCOBRA_BUILD_LLVM_PASS=ON.

Verification

Counterfactual, with LLVM hidden from CMake. Before the change:

CMake Error at llvm.cmake:8 (find_package):
  Could NOT find LLVM (missing: LLVM_DIR)
Call Stack (most recent call first):
  CMakeLists.txt:31 (include)

After the change the same command configures and builds cleanly:

cmake -S dependencies -B build-deps -DCMAKE_BUILD_TYPE=Release
cmake --build build-deps
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_PREFIX_PATH=$(pwd)/build-deps/install
cmake --build build
./build/tools/cobra-cli/cobra-cli --mba "(x|y)-(x&y)" --bitwidth 32
x ^ y

The dependency prefix contains no LLVM afterwards, and cobra-cli links only
CoreFoundation, libc++ and libSystem.

Verified on macOS arm64, macOS x86_64 and Linux (manylinux_2_28). Windows
additionally needs the companion MSVC fix, since cobra-core does not compile
under MSVC today.

Motivation

This makes it possible to build cobra-core inside cibuildwheel images for
Python bindings, where installing a full LLVM is not practical.

The dependencies superbuild included llvm.cmake unconditionally, so every
dependency build either required a system LLVM install (USE_EXTERNAL_LLVM=ON
-> find_package(LLVM REQUIRED CONFIG)) or built LLVM from source.

Neither is needed for cobra-core: libcobra-core.a references zero LLVM
symbols. LLVM is used only by lib/llvm, which the main project already gates
on COBRA_BUILD_LLVM_PASS (CMakeLists.txt:64). Gate the superbuild the same
way.

This makes it possible to build cobra-core in environments without LLVM,
such as cibuildwheel/CI images.
@CLAassistant

CLAassistant commented Aug 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@kyle-elliott-tob

Copy link
Copy Markdown
Collaborator

Will merge after the CLA has been signed, thanks :)

@w00tzenheimer

Copy link
Copy Markdown
Author

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants