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

repr(C) is necessary #28

Closed
le-jzr opened this issue Apr 12, 2017 · 7 comments
Closed

repr(C) is necessary #28

le-jzr opened this issue Apr 12, 2017 · 7 comments
Assignees

Comments

@le-jzr
Copy link
Contributor

le-jzr commented Apr 12, 2017

Currently, several structures use #[repr(packed)]. This works merely by coincidence, since packed is just a modifier, not a standalone representation (equivalent to #[repr(rust, packed)]). Correct annotation should be #[repr(C, packed)].

Even better would be to fix the padding by fixing structure fields, since packed exists to allow misaligned field accesses (i.e. special code in place of every load and store), which is totally unnecessary for aligned multiboot data.

@phil-opp
Copy link
Member

Some discussion about the alignment of ElfSectionsTag: 0010836#commitcomment-21738992

Most important bit:

Hmmm, this seems wrong... Are we absolutely sure the structure layout is correct? As is, 64b fields in the ELF64 section table are misaligned, which feels like a very wrong thing to do.

@phil-opp
Copy link
Member

In general, I agree that we should replace all instances of #[repr(packed)] with #[repr(C, packed)], especially since struct field reordering optimizations are available in nightly now.

@le-jzr
Copy link
Contributor Author

le-jzr commented Apr 12, 2017

If it turns out that the structure layout is really what GRUB2 gives us currently (note that the layout as specified in the Multiboot specification doesn't have this issue), then I'd strongly suggest we just ignore the ElfSectionsTag entirely for ELF64, for safety reasons. Or provide a way to use it safely (as in, copy elsewhere).

@le-jzr
Copy link
Contributor Author

le-jzr commented Apr 12, 2017

Is it possible that grub actually gives the info in u32 fields even for ELF64? I can't check it right now.

@xacrimon
Copy link
Contributor

xacrimon commented May 2, 2018

As most of all the #[repr(packed) instances has been replaced with #[repr(C, packed)] I think this issue is solved. If there is another issue. Like with the commitcomment linked earlier, open another issue thread. If you think otherwise, just comment on this thread. If there is no input for a few days, then I'll close the issue.

@le-jzr
Copy link
Contributor Author

le-jzr commented May 2, 2018

I see a few structs that are still #[repr(packed)]. I'll make a pull request to fix those.

@xacrimon
Copy link
Contributor

xacrimon commented May 2, 2018

Pull request is ready to be merged. I'm going to close this. Reopen if necessary.

@xacrimon xacrimon closed this as completed May 2, 2018
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

3 participants