-
Notifications
You must be signed in to change notification settings - Fork 314
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
{struct,union}: support #[repr(align(...))] and #[repr(packed)] #431
Commits on Dec 13, 2019
-
ir: {enum,struct,union}: check ReprStyle correctly
The equality checks for Repr to effectively check ReprStyle didn't make much sense -- it would result in Repr comparisons failing if ReprType was set. This becomes important when we add alignment information to Repr. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Configuration menu - View commit details
-
Copy full SHA for 615898a - Browse repository at this point
Copy the full SHA 615898aView commit details
Commits on Dec 15, 2019
-
ir: repr: support #[repr(align(...))] and #[repr(packed)] parsing
While #[repr(packed)] matches the rest of the currently-implemented reprs, #[repr(align(...))] adds another level of nesting and so it's necessary to handle arguments for nested #[repr(...)]s. However, arguments are only permitted for #[repr(align(...))] and any further nesting is ignored as before. It should be noted that #[repr(packed(...))] is also valid in Rust, but due to some complications with translating it to C, it is currently unsupported. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Configuration menu - View commit details
-
Copy full SHA for 6a24320 - Browse repository at this point
Copy the full SHA 6a24320View commit details -
ir: struct: support #[repr(align(...))] and #[repr(packed)]
As with #[must_use], this new support requires users to specify what annotations they would like to apply when an alignment-related repr is encountered. However, unlike #[must_use] all compilers appear to use the same attributes to indicate layout settings so there is just a single configuration for this new feature in a separate [layout] TOML table. In order to facilitate the fact that #[repr(align(...))] takes an argument which will likely need to be included in the final annotation, the user must specify a function-like macro which takes the alignment value as an argument. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Configuration menu - View commit details
-
Copy full SHA for 1cc3fc6 - Browse repository at this point
Copy the full SHA 1cc3fc6View commit details -
ir: union: support #[repr(align(...))] and #[repr(packed)]
Users configure the annotations for this feature using the same [layout] settings as for structures (because -- unlike #[must_use] -- all well-known compilers use the same annotations for all types). Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Configuration menu - View commit details
-
Copy full SHA for 5063065 - Browse repository at this point
Copy the full SHA 5063065View commit details -
{struct,union}: do not generate unsafe layouts
If the user has not specified a corresponding annotation for types that carry #[repr(packed)] or #[repr(align(...))] we must not generate the layout because it can cause interoperability issues (and possible memory unsafety) between C and Rust code. This unfortunately required some less-than-pretty plumbing changes so that the load phase of the parser has access to the complete Config object (luckily this does make the overall code look a bit cleaner IMHO). The individual IR loaders only get their corresponding structs, to avoid introducing confusing semantics. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Configuration menu - View commit details
-
Copy full SHA for 03e864f - Browse repository at this point
Copy the full SHA 03e864fView commit details -
tests: add tests for #[repr(packed)] and #[repr(align(...))]
The tests are very straightforward, and effecitvely are just ensuring that the formatting works correctly and is included in all of the important cases. It's also very important to ensure we do not generate laid-out structs for layouts which we cannot reasonably represent in C (such as in cases where we weren't told what annotation to use for packed and specifically-aligned structures). Thus, add some tests to verify that this is the case. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Configuration menu - View commit details
-
Copy full SHA for 9ef6398 - Browse repository at this point
Copy the full SHA 9ef6398View commit details -
docs: add documentation for new alignment config knobs
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Configuration menu - View commit details
-
Copy full SHA for dda0d00 - Browse repository at this point
Copy the full SHA dda0d00View commit details