How to shared link asan runtime with -Z sanitize=address?

It seems if link executable through cargo,
if -Z sanitize=address is speicified,
it static links librustc-nightly_rt.asan.a bundled with Rust installation.

It causes problems because my executable links to some shared library,
which links to sanitizer runtime shared library.

When running the executable, asan errors:
==115180==Your application is linked against incompatible ASan runtimes.

Is there a way to shared link to in gcc installation?
And do not link to librustc-nightly_rt.asan.a?

I think this is a Rustc bug, that it always static links librustc-nightly_rt.asan.a it bundles.
Static link asan Rust executable, is not compatible with C shared lib that dynamic links asan runtime.

I have submitted the issue: Incompatible ASan runtimes when Rust executable links with C shared library that dynamic links asan runtime · Issue #114127 · rust-lang/rust · GitHub

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.