add -fsanitize=... flag if sanitizer is enabled in rust#1672
Open
kamulos wants to merge 1 commit intorust-lang:mainfrom
Open
add -fsanitize=... flag if sanitizer is enabled in rust#1672kamulos wants to merge 1 commit intorust-lang:mainfrom
-fsanitize=... flag if sanitizer is enabled in rust#1672kamulos wants to merge 1 commit intorust-lang:mainfrom
Conversation
NobodyXu
requested changes
Feb 5, 2026
| } | ||
|
|
||
| if let Some(sanitizer) = self.getenv("CARGO_CFG_SANITIZE") { | ||
| let mut sanitizer_flag = OsString::from("-fsanitize="); |
Contributor
There was a problem hiding this comment.
It seems that rust and clang support hwaddress sanitizer, but gcc doesn't.
So we probably want to map it to normal address right?
cc @madsmtm
Contributor
There was a problem hiding this comment.
I agree that we should parse the value here, and only emit the flag on tested configurations
(Which also means I think we should have some sort of test for this in CI).
madsmtm
reviewed
Feb 11, 2026
| self.add_inherited_rustflags(&mut cmd, &target)?; | ||
| } | ||
|
|
||
| if let Some(sanitizer) = self.getenv("CARGO_CFG_SANITIZE") { |
Contributor
There was a problem hiding this comment.
The ordering here is a bit significant. I think it should be before add_inherited_rustflags?
(Probably also before envflags("CFLAGS") above, but add_inherited_rustflags isn't, so let's not do that just yet).
Contributor
There was a problem hiding this comment.
Or maybe place it'd make sense to place in add_default_flags?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
resolves #1666
I tried this mainly using ASAN. It works for me on gnu linux using
clangandgcc. It triggers when thex86_64-unknown-linux-gnuasantarget is used, and also whenRUSTFLAGS="-Z sanitizer=address"is set.I don't know this crate well, so I am unsure about a few things:
CARGO_CFG_SANITIZEis only set on targets, that support a specific sanitizer. Does this mean, there are no additional checks of the target necessary?