Skip to content

Allow specifying function alignment #75072

Closed
@repnop

Description

@repnop

I've been recently writing a kernel for the RISC-V architecture, using strictly as much Rust as I can get away with and during which I've run into the need to have certain functions aligned to specific byte alignments (ex. any function placed in mtvec MUST be 4 byte aligned), and while I can seemingly accomplish this using asm!(".align <alignment>") I think it would make sense for that to be an attribute of the function itself, whether it be limited to extern "C" fns or valid on all ABIs. Example of what I am asking for:

#[no_mangle]
#[repr(align(4))]
extern "C" fn gets_put_in_mtvec() {
    // ... content here ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language 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