Skip to content
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

serde: Only executables and rlibs can be compiled with -Z sanitizer #2

Closed
bbigras opened this issue Feb 20, 2017 · 2 comments
Closed

Comments

@bbigras
Copy link

bbigras commented Feb 20, 2017

I'm not able to use the sanitizer with one of my program since it uses serde and serde_derive won't build using -Z sanitizer. I'm able to reproduce with:

#[macro_use]
extern crate serde_derive;

extern crate serde_json;

#[derive(Serialize, Deserialize, Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let point = Point { x: 1, y: 2 };

    // Convert the Point to a JSON string.
    let serialized = serde_json::to_string(&point).unwrap();

    // Prints serialized = {"x":1,"y":2}
    println!("serialized = {}", serialized);

    // Convert the JSON string back to a Point.
    let deserialized: Point = serde_json::from_str(&serialized).unwrap();

    // Prints deserialized = Point { x: 1, y: 2 }
    println!("deserialized = {:?}", deserialized);
}

rustc 1.17.0-nightly (0e7727795 2017-02-19)

$ RUSTFLAGS="-Z sanitizer=thread" cargo run
   Compiling dtoa v0.4.1
   Compiling itoa v0.3.1
   Compiling quote v0.3.13
   Compiling unicode-xid v0.0.4
   Compiling serde v0.9.7
   Compiling num-traits v0.1.36
   Compiling synom v0.11.0
   Compiling syn v0.11.6
   Compiling serde_json v0.9.7
   Compiling serde_codegen_internals v0.13.0
   Compiling serde_derive v0.9.7
error: Only executables and rlibs can be compiled with `-Z sanitizer`

error: aborting due to previous error

error: Could not compile `serde_derive`.
@japaric
Copy link
Owner

japaric commented Feb 20, 2017

RUSTFLAGS="-Z sanitizer=thread" cargo run

Use --target x86_64-unknown-linux-gnu.

$ RUSTFLAGS="-Z sanitizer=thread" cargo run --target x86_64-unknown-linux-gnu

This is in the README:

Be sure to always pass --target x86_64-unknown-linux-gnu to Cargo or else you'll end up sanitizing the build scripts that Cargo runs or run into compilation error if your crate depends on a dylib.

@bbigras
Copy link
Author

bbigras commented Feb 20, 2017

It's fine with --target x86_64-unknown-linux-gnu. Sorry about that. I should have known.

@bbigras bbigras closed this as completed Feb 20, 2017
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

No branches or pull requests

2 participants