Skip to content

Add -Zrandomize-layout flag to better detect code that rely on unspecified behavior related to memory layout #77316

Closed
@marmeladema

Description

@marmeladema

In order to better detect code that rely on unspecified behavior related to memory layout, it could be useful to have a -Zrandomize-layout flag that add some padding bytes at the start of all #[repr(rust)] structs and unions. It should also add different amounts of padding to different fields.

This should help detecting invalid transmutes, or invalid unions.

Zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Transmute.20safety.20question

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zrandomize-layoutUnstable option: Randomize the layout of types.A-layoutArea: Memory layout of typesC-feature-acceptedCategory: A feature request that has been accepted pending implementation.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions