Skip to content

[DeviceSanitizer] Fix circular library dependency causing undefined symbol - #22901

Merged
sarnex merged 1 commit into
intel:syclfrom
wenju-he:fix-unsolved-symbol-isModuleUsingMsan-slibs
Aug 10, 2026
Merged

[DeviceSanitizer] Fix circular library dependency causing undefined symbol#22901
sarnex merged 1 commit into
intel:syclfrom
wenju-he:fix-unsolved-symbol-isModuleUsingMsan-slibs

Conversation

@wenju-he

@wenju-he wenju-he commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Commit 0941896 ("[DeviceSanitizer] Make sanitizer metadata globals per-module unique (#22567)") made SanitizerPostOptimizer.cpp in LLVMSYCLLowerIR call sycl::isModuleUsingMsan(), which is defined in LLVMSYCLPostLink. LLVMSYCLPostLink already links against LLVMSYCLLowerIR, so this created a circular library dependency. It doesn't show up when linking against full static LLVM libs, but breaks with ld.lld: error: undefined symbol:llvm::sycl::isModuleUsingMsan(llvm::Module const&) when building LLVMSYCLLowerIR as a standalone shared library (-slibs build).

Fix by moving isModuleUsingAsan/Msan/Tsan down into SYCLLowerIR/SYCLUtils.{h,cpp}, which has no dependency on SYCLPostLink.

…ymbol

Commit 0941896 ("[DeviceSanitizer] Make sanitizer metadata globals
per-module unique (intel#22567)") made SanitizerPostOptimizer.cpp in
LLVMSYCLLowerIR call sycl::isModuleUsingMsan(), which is defined in
LLVMSYCLPostLink. LLVMSYCLPostLink already links against LLVMSYCLLowerIR,
so this created a circular library dependency. It doesn't show up when
linking against full static LLVM libs, but breaks with `ld.lld: error:
undefined symbol:llvm::sycl::isModuleUsingMsan(llvm::Module const&)`
when building LLVMSYCLLowerIR as a standalone shared library (-slibs build).

Fix by moving isModuleUsingAsan/Msan/Tsan down into
SYCLLowerIR/SYCLUtils.{h,cpp}, which has no dependency on SYCLPostLink.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
@wenju-he
wenju-he requested review from a team and cperkinsintel as code owners August 8, 2026 02:57
@wenju-he

wenju-he commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Please review, thanks. This blocks downstream pulldown.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes a circular library dependency between LLVMSYCLLowerIR and LLVMSYCLPostLink that could surface as an undefined symbol when building LLVMSYCLLowerIR as a standalone shared library (e.g., -slibs builds). It does so by relocating the sanitizer-usage detection helpers (isModuleUsingAsan/Msan/Tsan) into SYCLLowerIR utilities, removing SYCLLowerIR’s need to reference a symbol defined in SYCLPostLink.

Changes:

  • Moved isModuleUsingAsan/Msan/Tsan(const Module&) implementations from SYCLPostLink (ComputeModuleRuntimeInfo.cpp) into SYCLLowerIR (SYCLUtils.{h,cpp}).
  • Updated SYCLLowerIR and sycl-jit call sites to include SYCLUtils.h instead of relying on ComputeModuleRuntimeInfo.h for these helpers.
  • Removed the declarations of these helpers from the SYCLPostLink public header (ComputeModuleRuntimeInfo.h).

Reviewed changes

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

Show a summary per file
File Description
sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp Adds SYCLUtils.h include to access the relocated isModuleUsing* helpers.
llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp Removes local isModuleUsing* definitions now provided by SYCLLowerIR.
llvm/lib/SYCLLowerIR/SYCLUtils.cpp Adds the new shared implementations of isModuleUsingAsan/Msan/Tsan.
llvm/lib/SYCLLowerIR/SanitizerPostOptimizer.cpp Switches include dependency from SYCLPostLink header to SYCLUtils.h.
llvm/include/llvm/SYCLPostLink/ComputeModuleRuntimeInfo.h Removes isModuleUsing* declarations from the SYCLPostLink API surface.
llvm/include/llvm/SYCLLowerIR/SYCLUtils.h Adds declarations for isModuleUsingAsan/Msan/Tsan (with Module forward declaration).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@zhaomaosu zhaomaosu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@sarnex
sarnex merged commit 146796d into intel:sycl Aug 10, 2026
36 of 39 checks passed
bool isModuleUsingAsan(const Module &M);
bool isModuleUsingMsan(const Module &M);
bool isModuleUsingTsan(const Module &M);

@YuriPlyakhin YuriPlyakhin Aug 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit:

These three predicates are sanitizer-specific, but SYCLLowerIR/SYCLUtils.h is the generic SYCL grab-bag, and everything else in it lives under sycl::utils. SYCLLowerIR/SanitizerPostOptimizer.h is already the sanitizer-owned header in this component and declaring them there breaks the cycle. Could you please consider it?

A new SYCLLowerIR/SanitizerUtils.h might be an even cleaner solution. Additional argument for SYCLLowerIR/SanitizerUtils.h:
__AsanKernelMetadata / __MsanKernelMetadata / __TsanKernelMetadata now appear as raw literals in SYCLUtils.cpp, SanitizerPostOptimizer.cpp, SanitizerPostSplitProcessing.cpp, clang/lib/Driver/OffloadBundler.cpp, plus the producers in {Address,Memory,Thread}Sanitizer.cpp. New SanitizerUtils.h could be used to also expose constexpr StringRef ASAN_KERNEL_METADATA_PREFIX etc. to have single definition of prefixes in addition to keeping the predicates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nit:

These three predicates are sanitizer-specific, but SYCLLowerIR/SYCLUtils.h is the generic SYCL grab-bag, and everything else in it lives under sycl::utils. SYCLLowerIR/SanitizerPostOptimizer.h is already the sanitizer-owned header in this component and declaring them there breaks the cycle. Could you please consider it?

A new SYCLLowerIR/SanitizerUtils.h might be an even cleaner solution. Additional argument for SYCLLowerIR/SanitizerUtils.h: __AsanKernelMetadata / __MsanKernelMetadata / __TsanKernelMetadata now appear as raw literals in SYCLUtils.cpp, SanitizerPostOptimizer.cpp, SanitizerPostSplitProcessing.cpp, clang/lib/Driver/OffloadBundler.cpp, plus the producers in {Address,Memory,Thread}Sanitizer.cpp. New SanitizerUtils.h could be used to also expose constexpr StringRef ASAN_KERNEL_METADATA_PREFIX etc. to have single definition of prefixes in addition to keeping the predicates.

thanks @YuriPlyakhin for the review. These are good points. Follow-up the ideas at #22915

@wenju-he
wenju-he deleted the fix-unsolved-symbol-isModuleUsingMsan-slibs branch August 11, 2026 01:18
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.

5 participants