Skip to content

swift test --filter with --sanitize fails: "Sanitizer load violates platform policy" #9546

@naftaly

Description

@naftaly

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

When running swift test with both --filter and --sanitize flags, the test fails to execute because the sanitizer runtime library cannot be loaded into the xctest subprocess.

Environment:

  • Swift: 6.2.3 (swiftlang-6.2.3.3.21)
  • Xcode: 26.2
  • macOS: 26.1 (Build 25B78)
  • Architecture: arm64

Steps to Reproduce:

  1. Create or use any Swift package with tests
  2. Run: swift test --sanitize address --filter

Expected behavior

Tests matching the filter run with AddressSanitizer enabled.

Actual behavior

Build succeeds, but test execution fails with:

Library not loaded: '@rpath/libclang_rt.asan_osx_dynamic.dylib'
...
code signature in '/Applications/Xcode-26.2.0.app/.../libclang_rt.asan_osx_dynamic.dylib'
not valid for use in process: Sanitizer load violates platform policy

Workaround:

Running without --filter works correctly:
swift test --sanitize address # ✓ works
swift test --sanitize address --filter Foo # ✗ fails

Analysis:

When --filter is used, Swift PM spawns xctest as a subprocess to run filtered tests. The sanitizer runtime's code signature appears to be rejected by macOS platform policy when loaded into this subprocess, but works when tests run directly without the filter mechanism.

Steps to reproduce

No response

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.127.14.1 Apple Swift version 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
Target: arm64-apple-macosx26.0
Darwin Alex-M3-Air.local 25.1.0 Darwin Kernel Version 25.1.0: Mon Oct 20 19:26:04 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8122 arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions