-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable ASan and TSan on FreeBSD (WIP) #47337
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (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. |
You can turn them on by adding It is great if you could turn on LSan too. cc #39699. r? @alexcrichton. |
Ah, right, so it's a LLVM 4's compiler-rt requires a couple patches to work on FreeBSD 12-CURRENT. They've been merged upstream (and released in LLVM 5), and rust-2017-07-20 already includes these changes. |
So LSan is incomplete (even though the library is built, it's not listed as supported on their website)
TSan doesn't link for some weird reason:
|
Thanks @myfreeweb! Is this good to go or are there still linking errors? |
no, TSan doesn't link yet, and I should add the pthread flag (just realized, probably the right place for it is |
Ok, feel free to ping the PR when it's good to go! |
Thanks for the pull request, @myfreeweb ! Since we haven't heard from you in a few weeks, I'm going to close this to keep the queue tidy. If you get over the last bit, please feel free to reopen this PR!
Who needs LLVM 4 or 5 when you can have LLVM 6 😜 |
…-obk Add sanitizer support on FreeBSD Restarting rust-lang#47337. Everything is better now, no more weird llvm problems, well not everything: Unfortunately, the sanitizers don't have proper support for versioned symbols (google/sanitizers#628), so `libc`'s usage of `stat@FBSD_1.0` and so on explodes, e.g. in calling `std::fs::metadata`. Building std (now easy thanks to cargo `-Zbuild-std`) and libc with `freebsd12/13` config via the `LIBC_CI=1` env variable is a good workaround… ``` LIBC_CI=1 RUSTFLAGS="-Z sanitizer=address" cargo +san-test -Zbuild-std run --target x86_64-unknown-freebsd --verbose ``` …*except* std won't build because there's no `st_lspare` in the ino64 version of the struct, so an std patch is required: ```diff --- i/src/libstd/os/freebsd/fs.rs +++ w/src/libstd/os/freebsd/fs.rs @@ -66,8 +66,6 @@ pub trait MetadataExt { fn st_flags(&self) -> u32; #[stable(feature = "metadata_ext2", since = "1.8.0")] fn st_gen(&self) -> u32; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_lspare(&self) -> u32; } #[stable(feature = "metadata_ext", since = "1.1.0")] @@ -136,7 +134,4 @@ impl MetadataExt for Metadata { fn st_flags(&self) -> u32 { self.as_inner().as_inner().st_flags as u32 } - fn st_lspare(&self) -> u32 { - self.as_inner().as_inner().st_lspare as u32 - } } ``` I guess std could like.. detect that `libc` isn't built for the old ABI, and replace the implementation of `st_lspare` with a panic?
Add sanitizer support on FreeBSD Restarting rust-lang#47337. Everything is better now, no more weird llvm problems, well not everything: Unfortunately, the sanitizers don't have proper support for versioned symbols (google/sanitizers#628), so `libc`'s usage of `stat@FBSD_1.0` and so on explodes, e.g. in calling `std::fs::metadata`. Building std (now easy thanks to cargo `-Zbuild-std`) and libc with `freebsd12/13` config via the `LIBC_CI=1` env variable is a good workaround… ``` LIBC_CI=1 RUSTFLAGS="-Z sanitizer=address" cargo +san-test -Zbuild-std run --target x86_64-unknown-freebsd --verbose ``` …*except* std won't build because there's no `st_lspare` in the ino64 version of the struct, so an std patch is required: ```diff --- i/src/libstd/os/freebsd/fs.rs +++ w/src/libstd/os/freebsd/fs.rs @@ -66,8 +66,6 @@ pub trait MetadataExt { fn st_flags(&self) -> u32; #[stable(feature = "metadata_ext2", since = "1.8.0")] fn st_gen(&self) -> u32; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_lspare(&self) -> u32; } #[stable(feature = "metadata_ext", since = "1.1.0")] @@ -136,7 +134,4 @@ impl MetadataExt for Metadata { fn st_flags(&self) -> u32 { self.as_inner().as_inner().st_flags as u32 } - fn st_lspare(&self) -> u32 { - self.as_inner().as_inner().st_lspare as u32 - } } ``` I guess std could like.. detect that `libc` isn't built for the old ABI, and replace the implementation of `st_lspare` with a panic?
I managed to get ASan running on my Rust program on FreeBSD, however, this patch is incomplete: seems like Rust's LLVM build is not building these
clang_rt.{}-x86_64
libraries. (find
doesn't even find them.) I haven't found where to turn them on, can anyone help?For now, I had to use the OS packaged LLVM's ASan library:
RUSTFLAGS="-L /usr/local/llvm40/lib/clang/4.0.1/lib/freebsd/ -l static=clang_rt.asan-x86_64 -l pthread -Z sanitizer=address" \ cargo build --example simple --target x86_64-unknown-freebsd ASAN_OPTIONS=detect_odr_violation=0 ASAN_SYMBOLIZER_PATH=/usr/local/llvm40/bin/llvm-symbolizer \ ../target/x86_64-unknown-freebsd/debug/examples/simple
And note the
pthread
, we have to link it when ASan is used. Not exactly sure where to add that. (Wouldn't have noticed this if my program used threads, by the way…)Also, looks like we have LSan too (at least the library is present in system LLVM packages)…