Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upLeakSanitizer, ThreadSanitizer, AddressSanitizer and MemorySanitizer support #38699
Conversation
rust-highfive
assigned
nikomatsakis
Dec 30, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
|
This is WIP revival of #31605. Right now, this only contains the Leak Sanitizer I'm bringing this back to life because one concern brought up in the original PR Comments
Concerns
TODO
|
japaric
reviewed
Dec 30, 2016
| @@ -23,6 +23,9 @@ compiler_builtins = { path = "../libcompiler_builtins" } | |||
| std_unicode = { path = "../libstd_unicode" } | |||
| unwind = { path = "../libunwind" } | |||
|
|
|||
| [target.x86_64-unknown-linux-gnu.dependencies] | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
japaric
Dec 30, 2016
•
Author
Member
This is also a hack to place the rustc_lsan crate in the sysroot. (because std doesn't actually depend on rustc_lsan)
japaric
reviewed
Dec 30, 2016
| @@ -0,0 +1,6 @@ | |||
| #![cfg_attr(not(stage0), feature(sanitizer_runtime))] | |||
This comment has been minimized.
This comment has been minimized.
japaric
Dec 30, 2016
Author
Member
I suppose this crate should also contain the -lpthread -lrt -lm linker flags that runtimes supossedly depend on. But I'm not sure what runtime depends on what library.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@japaric I'm excited to hear that xargo can compile std with custom flags. However, I feel like there is an RFC wanting to be written here. But I'm not quite sure what it is. =) At minimum, surely a feature gate of some kind would be required. |
This comment has been minimized.
This comment has been minimized.
|
Neat! How come we need to specially recognize the asan crate? Does it need to go in a special place on the linker command line? I'm not really sure what the best way to expose this will be long-term. For now, though, having it be optional and behind a feature gate seems ok. |
This comment has been minimized.
This comment has been minimized.
(a) It needs to be linked using |
This comment has been minimized.
This comment has been minimized.
|
I think the ordering is guaranteed via |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton That is, indeed, the case. It doesn't work without |
This comment has been minimized.
This comment has been minimized.
|
Travis failure seems legit to me: "llvm-config not found". |
japaric
force-pushed the
japaric:lsan
branch
from
e322830
to
b0249d0
Jan 5, 2017
This comment has been minimized.
This comment has been minimized.
|
OK. Added ThreadSanitizer support and added an unstable Using LeakSanitizer is as simple as (*) Actually, first you have patch --- a/src/libstd/Cargo.toml
+++ b/src/libstd/Cargo.toml
@@ -7,7 +7,6 @@ build = "build.rs"
[lib]
name = "std"
path = "lib.rs"
-crate-type = ["dylib", "rlib"]
[dependencies]
alloc = { path = "../liballoc" }Some comments: LeakSanitizer only requires linking a runtime so, IMO, it makes sense to ThreadSanitizer requires recompiling the rust-lang/compiler-rt needs to be patched to make tsan work with PIE |
japaric
changed the title
leak sanitizer support
LeakSanitizer and ThreadSanitizer support
Jan 5, 2017
japaric
reviewed
Jan 5, 2017
| @@ -432,3 +432,4 @@ impl Drop for OperandBundleDef { | |||
| mod llvmdeps { | |||
| include! { env!("CFG_LLVM_LINKAGE_FILE") } | |||
| } | |||
| #[link(name = "ffi")] extern {} | |||
This comment has been minimized.
This comment has been minimized.
japaric
Jan 5, 2017
Author
Member
TODO remove. (Sometimes I forget to not commit this -- workaround for #34486)
This comment has been minimized.
This comment has been minimized.
|
Pushed AddressSanitizer support and added an example to the PR description. Interestingly, an empty
|
japaric
changed the title
LeakSanitizer and ThreadSanitizer support
LeakSanitizer, ThreadSanitizer and AddressSanitizer support
Jan 5, 2017
This comment has been minimized.
This comment has been minimized.
|
travis says:
not sure what's up w/ that |
This comment has been minimized.
This comment has been minimized.
|
Quoting myself
Travis is testing on Ubuntu. We should build MemorySanitizer is now working (example in the PR description) but requires the latest compiler-rt release. We could backport some stuff to make our fork work (but we would have to first figure out what needs to be backported) or we could simply upgrade our fork to something more recent (easier). |
japaric
changed the title
LeakSanitizer, ThreadSanitizer and AddressSanitizer support
LeakSanitizer, ThreadSanitizer, AddressSanitizer and MemorySanitizer support
Jan 5, 2017
This comment has been minimized.
This comment has been minimized.
|
So, @alexcrichton -- I feel more-or-less about experimenting in this direction without an RFC, but it seems like we should have some docs. Maybe a tracking issue? I feel like I would not want this interface to stabilize without an RFC. Not sure what team has jurisdiction here, probably @rust-lang/compiler or @rust-lang/tools. |
This comment has been minimized.
This comment has been minimized.
|
Yeah I'm fine experimenting here as well. I want to make sure that everything is thoroughly feature gated, but beyond that it seems worthwhile to enable supporting this at all |
This comment has been minimized.
This comment has been minimized.
|
I wonder though if we can experiment here with less of this support in-tree. @japaric do you have an idea of how we might minimize basically the size of this PR? Ideally we wouldn't maintain all of this in tree because development would be slowed down, and hopefully one day these crates can all be on crates.io anyway. I'm slightly hesitant here as this would be one of the first "linux only" features we support in-tree, so if we can keep it external that would be nice. |
vadimcn
reviewed
Jan 5, 2017
| // We must link the sanitizer runtime using -Wl,--whole-archive but since | ||
| // it's packed in a .rlib, it contains stuff that are not objects that will | ||
| // make the linker error. So we must remove those bits from the .rlib before | ||
| // linking it. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
japaric
Jan 5, 2017
Author
Member
Because of the dependency graph (the sanitizer runtime gets injected as a direct dependency of the "top" crate) the runtime rlib ends up being one of the first linker arguments. Because linkers are lazy, if we don't use whole-archive, the linker will end up dropping most / all of the symbols in it (because the preceding linker argument didn't directly need the symbols). whole-archive prevents that; it forces the linker to keep all the symbols around as it keeps looking at the next linker arguments.
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Initial testing with rustc_lsan shows that the sanitizer runtimes can live out of tree. I'll update the PR with that in mind. |
This comment has been minimized.
This comment has been minimized.
|
Great work, @japaric! Some thoughts on integration into the compiler:
|
This comment has been minimized.
This comment has been minimized.
|
@japaric It is great to see more work on sanitizer support! Regarding the question how much of this should be in-tree or not, I think the |
This comment has been minimized.
This comment has been minimized.
|
|
japaric
added some commits
Dec 30, 2016
japaric
force-pushed the
japaric:lsan
branch
from
b4ff677
to
e180dd5
Feb 9, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors r=alexcrichton |
This comment has been minimized.
This comment has been minimized.
|
|
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this pull request
Feb 9, 2017
bors
added a commit
that referenced
this pull request
Feb 9, 2017
bors
merged commit e180dd5
into
rust-lang:master
Feb 9, 2017
1 check passed
This comment has been minimized.
This comment has been minimized.
|
Should this be marked with relnotes tag? |
japaric
deleted the
japaric:lsan
branch
Feb 9, 2017
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Done. #39699 |
This comment has been minimized.
This comment has been minimized.
|
Thanks, @japaric , what a great feature! |
This comment has been minimized.
This comment has been minimized.
|
@japaric @alexcrichton This PR integrates with rustbuild in a really weird way. It adds some always-enabled 'optional' std features, lsan/msan/asan, and then omits actually producing any code for them if the LLVM_CONFIG environment variable is absent; the LLVM_CONFIG variable is only added if --enable-sanitizers is passed. Shouldn't there be more sanity in this? Actually enabling the feature only if the config flag is on? |
This comment has been minimized.
This comment has been minimized.
|
@whitequark sounds reasonable to me, yeah. We may also be able to remove the features now as they were from a previous iteration as well. @japaric what do you think? |
o01eg
referenced this pull request
Feb 14, 2017
Merged
Add support for sanitizers. Remove rustbuild option. #229
This comment has been minimized.
This comment has been minimized.
|
Yeah, seems fine to remove the Cargo features. I'll prepare a PR. |
japaric commentedDec 30, 2016
•
edited
Examples
LeakSanitizer
ThreadSanitizer
AddressSanitizer
MemorySanitizer