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

Don't spill operands onto the stack in naked functions #75417

Merged
merged 2 commits into from
Aug 14, 2020

Conversation

npmccallum
Copy link
Contributor

Currently, the code spills operands onto the stack for the purpose of
debuginfo. However, naked functions can only contain an asm block. Therefore,
attempting to spill the operands on the stack is undefined behavior.

Fixes #42779
cc #32408

Note that this PR reverts #74105 which ultimately didn't fix the problem.

cc @haraldh @Amanieu @matthewjasper

This reverts commit 2567074.

This commit does not actually fix the problem. It merely removes the name of
the argument from the LLVM output. Even without the name, Rust codegen still
spills the (nameless) variable onto the stack which is the root cause. The root
cause is solved in the next commit.
Currently, the code spills operands onto the stack for the purpose of
debuginfo. However, naked functions can only contain an asm block. Therefore,
attempting to spill the operands on the stack is undefined behavior.

Fixes rust-lang#42779
cc rust-lang#32408
@rust-highfive
Copy link
Collaborator

r? @oli-obk

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 11, 2020
@npmccallum
Copy link
Contributor Author

r? @matthewjasper

@Amanieu
Copy link
Member

Amanieu commented Aug 11, 2020

Actually we need something even stronger here: we must never emit an alloca in LLVM IR for naked functions since those are directly converted to stack allocations in debug builds. The LLVM IR must contain only a single inlineasm instruction followed by an unreachable.

@npmccallum
Copy link
Contributor Author

Actually we need something even stronger here: we must never emit an alloca in LLVM IR for naked functions since those are directly converted to stack allocations in debug builds. The LLVM IR must contain only a single inlineasm instruction followed by an unreachable.

I agree. However, that should not block this fix, which is needed either way (and currently blocks my day job).

@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 13, 2020

📌 Commit 050fb38 has been approved by matthewjasper

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 14, 2020
Rollup of 12 pull requests

Successful merges:

 - rust-lang#74650 (Correctly parse `{} && false` in tail expression)
 - rust-lang#75319 (Fix ICE rust-lang#75307 in `format`)
 - rust-lang#75417 (Don't spill operands onto the stack in naked functions)
 - rust-lang#75452 (self-profile: Cache more query key strings when doing self-profiling.)
 - rust-lang#75459 (fix LocalInfo doc comment)
 - rust-lang#75462 (Remove unused tcx parameter)
 - rust-lang#75467 (Fix E0741 error code explanation)
 - rust-lang#75471 (Change registered "program name" for -Cllvm-args usage messages)
 - rust-lang#75477 (Expand function pointer docs)
 - rust-lang#75479 (make rustc-docs component available to rustup)
 - rust-lang#75496 (Prioritization WG: Open Zulip topics only for `I-prioritize` issues)
 - rust-lang#75500 (Disable zlib in LLVM on aarch64-apple-darwin)

Failed merges:

r? @ghost
@bors bors merged commit 1f73e89 into rust-lang:master Aug 14, 2020
npmccallum added a commit to enarx-archive/frenetic2 that referenced this pull request Aug 20, 2020
@bstrie bstrie added the A-naked Area: #[naked], prologue and epilogue-free, functions, https://git.io/vAzzS label Feb 2, 2022
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
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 S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Naked functions with arguments generate a prologue
8 participants