Skip to content

Fix sanitizer link propagation for NPDetPlugins in clang CI builds#53

Closed
Copilot wants to merge 2 commits into
copilot/implement-use-asan-use-tsan-supportfrom
copilot/fix-asan-link-failure
Closed

Fix sanitizer link propagation for NPDetPlugins in clang CI builds#53
Copilot wants to merge 2 commits into
copilot/implement-use-asan-use-tsan-supportfrom
copilot/fix-asan-link-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 17, 2026

linux-eic-shell clang sanitizer builds were failing to link libNPDetPlugins.so with unresolved ASan symbols (__asan_report_store4/8). The failure was isolated to the plugin target created by dd4hep_add_plugin(...), where sanitizer link flags were not reliably applied.

  • Targeted plugin-level sanitizer linking

    • Updated src/plugins/CMakeLists.txt to add explicit target link options on NPDetPlugins when sanitizers are enabled.
    • Applies only for GNU/Clang toolchains and only under the corresponding CMake options:
      • USE_ASAN-fsanitize=address
      • USE_UBSAN-fsanitize=undefined
  • Scope

    • Change is intentionally minimal and localized to NPDetPlugins, avoiding broader CMake behavior changes while preserving sanitizer coverage.
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
  if(USE_ASAN)
    target_link_options(NPDetPlugins PRIVATE -fsanitize=address)
  endif()
  if(USE_UBSAN)
    target_link_options(NPDetPlugins PRIVATE -fsanitize=undefined)
  endif()
endif()
Original prompt

Fix pull request #50 in repository eic/npsim by addressing the failing GitHub Actions build job in workflow .github/workflows/linux-eic-shell.yml for commit e4be85c2a80e7f6f6c244e448bab5ae48a00045e.

Observed failure:

  • In the clang++ sanitizer build, linking lib/libNPDetPlugins.so fails with undefined ASan symbols:
    • __asan_report_store4
    • __asan_report_store8
  • Failing target comes from src/plugins/CMakeLists.txt, which defines dd4hep_add_plugin(NPDetPlugins ...).

Relevant files already inspected:

  • .github/workflows/linux-eic-shell.yml
  • src/plugins/CMakeLists.txt

Likely root cause:

  • Sanitizer compile flags are enabled globally, but the plugin target created by dd4hep_add_plugin(...) is not receiving the necessary sanitizer link options/runtime propagation under clang, causing ASan link failure for the shared plugin target.

Requested change:

  • Modify the PR branch to fix the build.
  • Prefer a minimal, targeted fix.
  • Recommended direction: ensure NPDetPlugins receives explicit sanitizer link options (and compile options if needed) when USE_ASAN and/or USE_UBSAN are enabled, so the clang sanitizer build links successfully.
  • Validate that the fix is appropriate for both clang and gcc builds and does not unnecessarily disable sanitizer coverage.

Please create a commit on the PR branch with the fix and open/update the pull request accordingly.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The failure is in the clang++ ASAN/UBSAN build of the build job in .github/workflows/linux-eic-shell.yml, where sanitizers are enabled for both compilers:

  • -DUSE_ASAN=ON
  • -DUSE_UBSAN=ON

The actual error occurs while linking NPDetPlugins from src/plugins/CMakeLists.txt:

  • failing target: lib/libNPDetPlugins.so
  • linker error:
    • undefined reference to '__asan_report_store4'
    • undefined reference to '__asan_report_store8'

Root cause

This is a sanitizer link mismatch: Clang is pulling in the static ASan runtime (libclang_rt.asan_static-x86_64.a), but the final plugin link is missing the full ASan runtime needed to resolve those symbols.

Because the failure is isolated to the plugin target, the most likely issue is that the sanitizer compile options are being applied, but the corresponding link options/libraries are not propagating to dd4hep_add_plugin(...).

Solution

Make sure the plugin target links with sanitizer flags explicitly when sanitizers are enabled.

Recommended patch

Update src/plugins/CMakeLists.txt to add sanitizer link options directly to NPDetPlugins:

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

dd4hep_add_plugin(NPDetPlugins
  SOURCES
    src/EICInteractionVertexBoost.cxx
    src/EICInteractionVertexSmear.cxx
    src/OpticalPhotonEfficiencyStackingAction.cxx
  INCLUDES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  USES DD4hep::DDCore DD4hep::DDG4
)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
  if(USE_ASAN)
    target_compile_options(NPDetPlugins PRIVATE -fsanitize=address)
    target_link_options(NPDetPlugins PRIVATE -fsanitize=address)
  endif()

  if(USE_UBSAN)
    target_compile_options(NPDetPlugins PRIVATE -fsanitize=undefined)
    target_link_options(NPDetPlugins PRIVATE -fsanitize=undefined)
  endif()
endif()

install(TARGETS NPDetPlugins
  EXPORT NPDetTargets
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  RUNTIME DESTINATION bin
  INCLUDES DESTINATION include
)

Why this should fix it

dd4hep_add_plugin(...) creates a shared library target, and shared-library/plugin targets often do not inherit sanitizer link flags reliably from global settings or parent targets. Adding target_link_options(... -fsanitize=address) ensures Clang links the correct ASan runtime for libNPDetPlugins.so.

If you want the smallest possible change

If ASAN/UBSAN are already applied globally at compile time elsewhere, this may be enough:

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
  if(USE_ASAN)
    target_link_options(NPDetPlugins PRIVATE -fsanitize=address)
  endif()
  if(USE_UBSAN)
    target_link_options(NPDetPlugins PRIVATE -fsanitize=undefined)
  endif()
endif()

Less ideal workaround

If the project does not need sani...

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Fix ASan link failure for NPDetPlugins in GitHub Actions Fix sanitizer link propagation for NPDetPlugins in clang CI builds May 17, 2026
Copilot AI requested a review from wdconinc May 17, 2026 17:53
@wdconinc wdconinc closed this May 17, 2026
@wdconinc wdconinc deleted the copilot/fix-asan-link-failure branch May 17, 2026 18:21
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