Skip to content

document #[align] on functions #1866

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/attributes/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,26 @@ Using the `instruction_set` attribute has the following effects:

* If the address of the function is taken as a function pointer, the low bit of the address will be set to 0 (arm) or 1 (thumb) depending on the instruction set.
* Any inline assembly in the function must use the specified instruction set instead of the target default.

r[attributes.codegen.align]
## The `align` attribute

r[attributes.codegen.align.allowed-positions]
The *`align` [attribute]* may be applied to function items.

r[attributes.codegen.align.behavior]
This attribute raises the aligmnent of a function's generated code.

```rust
#[align(32)]
fn aligned_to_32_bytes() {}
```

> [!NOTE]
> Some targets use pointer tagging on function pointers. Consequently, on those targets, a function's address may not be a multiple of its alignment.

r[attributes.codegen.align.minimum]
The alignment value that is specified is a minimum. The actual alignment may be higher.

r[attributes.codegen.align.syntax]
The alignment is specified as an integer parameter in the form of `#[align(x)]`. The alignment value must be a power of two from 1 up to 2<sup>29</sup>.
Loading