Skip to content

root: fix cling CMake include ordering for external LLVM#932

Open
wdconinc wants to merge 1 commit into
developfrom
root-cling-cmake-fix
Open

root: fix cling CMake include ordering for external LLVM#932
wdconinc wants to merge 1 commit into
developfrom
root-cling-cmake-fix

Conversation

@wdconinc
Copy link
Copy Markdown
Contributor

Problem

When building ROOT against an external (system-installed) LLVM (~builtin_llvm), the LLVM_INCLUDE_DIRS path (e.g. /usr/lib/llvm-20/include) contains a cxxabi.h from libc++abi.

The unconditional line in interpreter/cling/CMakeLists.txt:

include_directories(BEFORE SYSTEM ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS})

pushes that directory in front of all system includes, causing LLVM's cxxabi.h to shadow GCC 14's cxxabi_init_exception.h. This triggers a hard compiler error on __cxa_init_primary_exception: LLVM declares it returning __cxa_exception*, while GCC 14 declares it returning __cxa_refcounted_exception*.

Root cause

The BEFORE flag was introduced (commit 3c58e0d3, 2020) to ensure cling's own LLVM headers take priority. This is correct for builtin_llvm=ON — the in-tree LLVM_INCLUDE_DIRS contains no cxxabi.h. For external LLVM, BEFORE is not needed (the headers are already registered by interpreter/CMakeLists.txt without BEFORE) and actively harmful.

Fix

Guard the BEFORE flag with if(builtin_llvm). For external LLVM, use plain SYSTEM (still suppresses warnings) without BEFORE.

Fixes: eic/containers#288

With external LLVM (builtin_llvm=OFF), LLVM_INCLUDE_DIRS points to
/usr/lib/llvm-20/include which contains cxxabi.h from libc++abi.
The unconditional 'include_directories(BEFORE SYSTEM ...)' in
interpreter/cling/CMakeLists.txt causes that header to shadow GCC 14's
cxxabi.h, producing a hard conflict on __cxa_init_primary_exception
(LLVM returns __cxa_exception*; GCC returns __cxa_refcounted_exception*).

With builtin_llvm=ON the build-tree LLVM_INCLUDE_DIRS contain no
cxxabi.h, so BEFORE SYSTEM is harmless.  For external LLVM, BEFORE is
not needed because the outer interpreter/CMakeLists.txt already
registers the external LLVM include path without BEFORE; only SYSTEM
(for warning suppression) is needed.

Fixes: eic/containers#288

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 23, 2026 22:29
wdconinc added a commit to eic/containers that referenced this pull request May 23, 2026
Point to eic/eic-spack#932 which guards the BEFORE flag in
interpreter/cling/CMakeLists.txt include_directories to only apply
when builtin_llvm=ON.  With external LLVM, the unconditional BEFORE
caused LLVM's libc++abi cxxabi.h to shadow GCC 14's cxxabi.h,
producing a conflicting declaration of __cxa_init_primary_exception.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the EIC Spack overlay for ROOT to avoid a cling build failure when ROOT is built against an external (system) LLVM, by adjusting include directory ordering in cling’s CMake configuration.

Changes:

  • Add a ROOT Spack patch that conditionally uses include_directories(BEFORE ...) only when builtin_llvm is enabled.
  • Apply the patch only for ROOT @6.36: builds using external LLVM (~builtin_llvm).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
spack_repo/eic/packages/root/package.py Registers the new patch for ROOT builds with external LLVM on versions @6.36:.
spack_repo/eic/packages/root/cling-cmake-external-llvm-include-order.patch Implements the conditional BEFORE include ordering in interpreter/cling/CMakeLists.txt.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

wdconinc added a commit to eic/containers that referenced this pull request May 23, 2026
Point to eic/eic-spack#932 which guards the BEFORE flag in
interpreter/cling/CMakeLists.txt include_directories to only apply
when builtin_llvm=ON.  With external LLVM, the unconditional BEFORE
caused LLVM's libc++abi cxxabi.h to shadow GCC 14's cxxabi.h,
producing a conflicting declaration of __cxa_init_primary_exception.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants