Skip to content
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

Should #[naked] functions default to #[inline(never)] ? #60919

Closed
fintelia opened this issue May 17, 2019 · 2 comments · Fixed by #79192
Closed

Should #[naked] functions default to #[inline(never)] ? #60919

fintelia opened this issue May 17, 2019 · 2 comments · Fixed by #79192
Labels
A-naked Area: #[naked], prologue and epilogue-free, functions, https://git.io/vAzzS C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@fintelia
Copy link
Contributor

Currently, the compiler is allowed to inline naked functions if it wants to. For a normal function, inlining is fine because the compiler can remove the function prologue/epilogue and the remaining will behave as expected. However for naked functions, the developer provides the prologue/epilogue and those aren't removed by the compiler. This almost surely will result in incorrect behavior. Accordingly I think it would make sense for the compiler to not inline naked functions unless the developer explicitly opted-in.

@fintelia fintelia changed the title Should #[naked] default to #[inline(never)] ? Should #[naked] functions default to #[inline(never)] ? May 17, 2019
@jonas-schievink jonas-schievink added A-naked Area: #[naked], prologue and epilogue-free, functions, https://git.io/vAzzS C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels May 17, 2019
@comex
Copy link
Contributor

comex commented Sep 28, 2019

In the other thread, alistair23 found that Clang automatically marks naked functions as noinline.

@npmccallum
Copy link
Contributor

Yes, #[naked] functions should imply #[inline(never)].

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
Never inline naked functions

The `#[naked]` attribute disabled prologue / epilogue emission for the
function and it is responsibility of a developer to provide them. The
compiler is no position to inline such functions correctly.

Disable inlining of naked functions at LLVM and MIR level.

Closes rust-lang#60919.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
Never inline naked functions

The `#[naked]` attribute disabled prologue / epilogue emission for the
function and it is responsibility of a developer to provide them. The
compiler is no position to inline such functions correctly.

Disable inlining of naked functions at LLVM and MIR level.

Closes rust-lang#60919.
@bors bors closed this as completed in 5c45969 Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-naked Area: #[naked], prologue and epilogue-free, functions, https://git.io/vAzzS C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants