Skip to content

Fix unaligned_references warnings instead of supressing them #123

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

Closed
roypat opened this issue Nov 14, 2022 · 0 comments · Fixed by #127
Closed

Fix unaligned_references warnings instead of supressing them #123

roypat opened this issue Nov 14, 2022 · 0 comments · Fixed by #127
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@roypat
Copy link
Member

roypat commented Nov 14, 2022

Currently, compiling linux-loader prints the warnings

warning: the following packages contain code that will be rejected by a future version of Rust: linux-loader v0.7.0 (.../linux-loader)
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1`

Running the suggested command yields a lot of unaligned_references warnings. The warnings mention that these will become hard errors in a future release. Most of them are in loader_gen generated tests, where they can be fixed by re-generating the files using rust bindgen >= 0.60.0 (which is the version in which this this landed: rust-lang/rust-bindgen#2203).

The following three however are outside of generated code and need to be fixed manually (however they are still inside of test code, meaning no undefined behavior is actually triggered in production code)

> warning: reference to packed field is unaligned
>    --> src/loader/x86_64/bzimage/mod.rs:243:9
>     |
> 243 |         assert_eq!(loader_result.setup_header.unwrap().header, 0x53726448);
>     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     |
> note: the lint level is defined here
>    --> src/loader/x86_64/bzimage/mod.rs:224:13
>     |
> 224 |     #[allow(unaligned_references)]
>     |             ^^^^^^^^^^^^^^^^^^^^
>     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>     = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
>     = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
>     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
>     = note: this warning originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
> 
> warning: reference to packed field is unaligned
>    --> src/loader/x86_64/bzimage/mod.rs:244:9
>     |
> 244 |         assert_eq!(loader_result.setup_header.unwrap().version, 0x20d);
>     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     |
> note: the lint level is defined here
>    --> src/loader/x86_64/bzimage/mod.rs:224:13
>     |
> 224 |     #[allow(unaligned_references)]
>     |             ^^^^^^^^^^^^^^^^^^^^
>     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>     = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
>     = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
>     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
>     = note: this warning originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
> 
> warning: reference to packed field is unaligned
>    --> src/loader/x86_64/bzimage/mod.rs:260:9
>     |
> 260 |         assert_eq!(0x53726448, loader_result.setup_header.unwrap().header);
>     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     |
> note: the lint level is defined here
>    --> src/loader/x86_64/bzimage/mod.rs:224:13
>     |
> 224 |     #[allow(unaligned_references)]
>     |             ^^^^^^^^^^^^^^^^^^^^
>     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>     = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
>     = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
>     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
>     = note: this warning originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants