You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"fngets_put_in_mtvec(){// ... content here ...}
Reacted by Esteban Blanc, BlackHoleFox, memoryruins, leonardo-m, yvt, David Hoppenbrouwers and Jakub Beránek
Using https://c.godbolt.org/z/E7ETx8 to verify, it looks like both GCC and Clang support using __attribute__((aligned(<alignment>))) to specify function alignment on a per-function basis
@Skallwar oh, somehow I missed the notification from this issue. yeah, currently I'm (ab)using that in a #[naked] fn (I have no idea if it works for non-naked fns).
Activity
hanna-kruppe commentedon Aug 3, 2020
For context, how is this requirement addressed by C toolchains?
repnop commentedon Aug 3, 2020
Using https://c.godbolt.org/z/E7ETx8 to verify, it looks like both GCC and Clang support using
__attribute__((aligned(<alignment>)))to specify function alignment on a per-function basisnbdd0121 commentedon Aug 3, 2020
I believe you would need to use assembly for interrupt handlers because naked functions don't work as intended anyway.
Skallwar commentedon Nov 17, 2020
I'm on the exact same situation as @repnop, with the exact same context.
asm!(".align <alignment>")inside the function worked for you?Skallwar commentedon Nov 19, 2020
If this is something that should be part of the language, I would gladly try to implement it
sampersand commentedon Jan 14, 2021
I'd also find this quite helpful for some low-level bit twiddling I'm doing.
repnop commentedon Jan 21, 2021
@Skallwar oh, somehow I missed the notification from this issue. yeah, currently I'm (ab)using that in a
#[naked]fn (I have no idea if it works for non-naked fns).Opened a PR so we'll see where this goes :)
Auto merge of rust-lang#81234 - repnop:fn-alignment, r=lcnr
memoryruins commentedon Apr 6, 2021
The tracking issue for
#![feature(fn_align)]is now #82232