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

Fix clippy warnings #80

Merged
merged 1 commit into from May 10, 2021
Merged

Fix clippy warnings #80

merged 1 commit into from May 10, 2021

Conversation

shaqq
Copy link
Contributor

@shaqq shaqq commented May 7, 2021

@danobi I took a quick stab at getting rid of all warnings.

There were a bunch of errors in examples/runqslower, but it didn't quite make sense to add Clippy ignore's in there, since people are likely going to copy/paste from that code. Let me know if I got that wrong.

Otherwise, this is pretty much my first Rust code ever, so let me know what I should fix!

@shaqq shaqq marked this pull request as ready for review May 7, 2021 19:59
Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, 1 styling nit

libbpf-cargo/src/btf/btf.rs Outdated Show resolved Hide resolved
let obj_opts = libbpf_sys::bpf_object_open_opts {
sz: std::mem::size_of::<libbpf_sys::bpf_object_open_opts>() as libbpf_sys::size_t,
object_name: cname.as_ptr(),
..Default::default()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this ensure that all the bytes are zeroed out, even padding?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so.

Example: https://godbolt.org/z/r75T13Pcd

Rust generates code to call ::default() which is implemented by https://docs.rs/libbpf-sys/0.3.0-1/src/libbpf_sys/bindings.rs.html#2987-2991 and the implementation zeros out the struct using https://doc.rust-lang.org/stable/std/mem/fn.zeroed.html . From reading the docs there and looking at rust-lang/rust#70230 , I don't believe bindgen is generating the right code here. It should probably generate a memset.

Also note that this PR doesn't change the old behavior. Functionally it should be the same as before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's definitely padding: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b7342c8fe84d6bb1e01333e4e07f7a79 (48 vs 38). I think this should be a bindgen bug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danobi I think I'm following along, though I'm still p new to systems programming.

It sounds like the padding is bad because we want libbpf-rs to be as conservative as possible when it comes to memory, yeah? Also, It seems like rust-lang/rust#70230 is going to take some time to resolve, and when it does it'll be in the nightly release at first.

I can revert these changes around calling default() and add a comment so that clippy ignores em. That work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed up the revert - let me know if that's not the right path, and I can undo em

Copy link
Member

@danobi danobi May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your original changes were good. I think it's a bug with bindgen (a tool used to generate rust bindings to c/c++ libraries). I'm working on fixing the bindgen bug in rust-lang/rust-bindgen#2051

Even then, the non-zero padding is currently a theoretical issue. We haven't seen issues with it yet -- not to say it won't happen in the future (b/c bindgen is invoking undefined behavior)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted the revert!

@danobi
Copy link
Member

danobi commented May 10, 2021

Can you rebase and also remove the whitespace changes again?

@@ -165,10 +165,10 @@ impl<'a> ObjectSkeletonConfigBuilder<'a> {
// Holds `CString`s alive so pointers to them stay valid
let mut string_pool = Vec::new();

// NB: use default() to zero out struct
Copy link
Contributor Author

@shaqq shaqq May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danobi I also got rid of this, since it appears to be a comment about zeroing out the bytes, but it sounds like we'll fix it with the bind-gen bugfix

@danobi danobi merged commit ba44fd5 into libbpf:master May 10, 2021
@danobi
Copy link
Member

danobi commented May 10, 2021

Thanks!

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.

None yet

3 participants