Skip to content

Draft: Fix building with address sanitizer#91

Draft
jschwe wants to merge 1 commit intodtolnay:masterfrom
jschwe:asan_support
Draft

Draft: Fix building with address sanitizer#91
jschwe wants to merge 1 commit intodtolnay:masterfrom
jschwe:asan_support

Conversation

@jschwe
Copy link
Copy Markdown

@jschwe jschwe commented Apr 9, 2026

Status: Tested on MacOS. Pending tests on windows and Linux.

Without this patch, using inventory will result in the following linker error on macOS when address sanitizer is enabled:

note: ld: initializer pointer has no target in <...>.rcgu.o

ASAN instrumentation will apparently modify the statics, which breaks linking.

Considerations:

  • feature(sanitize) is still unstable, so we need to guard it behind a cfg
  • Users will need to add #![feature(sanitize)] to their crate, if they wish to use ASAN.
  • feature(cfg_sanitize) is also unstable, so that would also need to be guarded by something in order to not break regular compilation on stable Rust. Hence we just require the user to set --cfg=asan via RUSTFLAGS when using ASAN, since they would need to set RUSTFLAGS anyway to enable ASAN.

Fixes: #90

Without this patch, using inventory will result in the following linker error
on macOS when address sanitizer is enabled:
```
note: ld: initializer pointer has no target in <...>.rcgu.o
```

ASAN instrumentation will apparently modify the statics, which breaks linking.

Considerations:

- `feature(sanitize)` is still unstable, so we need to guard it behind a cfg
- Users will need to add `#![feature(sanitize)]` to their crate, if they wish
  to use ASAN.
- `feature(cfg_sanitize)` is also unstable, so that would also need to be guarded by
   something in order to not break regular compilation on stable Rust. Hence we
   just require the user to set `--cfg=asan` via RUSTFLAGS when using ASAN, since
   they would need to set RUSTFLAGS anyway to enable ASAN.
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.

linker failure when using ASAN in a project with inventory on macOS

1 participant