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

Assertion `MFI.isCalleeSavedInfoValid() && "CalleeSavedInfo not calculated"' failed on AArch64 #75096

Closed
pietroalbini opened this issue Aug 3, 2020 · 5 comments · Fixed by #75224
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state

Comments

@pietroalbini
Copy link
Member

pietroalbini commented Aug 3, 2020

The debuginfo/function-arguments-naked.rs test is failing on AArch64's CI:

---- [debuginfo-gdb] debuginfo/function-arguments-naked.rs stdout ----
NOTE: compiletest thinks it is using GDB with native rust support

error: compilation failed!
status: signal: 6
command: "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/debuginfo/function-arguments-naked.rs" "-Zthreads=1" "--target=aarch64-unknown-linux-gnu" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/debuginfo/function-arguments-naked.gdb/a" "-Crpath" "-Zunstable-options" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-g" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/debuginfo/function-arguments-naked.gdb/auxiliary"
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
warning: unused variable: `x`
  --> /checkout/src/test/debuginfo/function-arguments-naked.rs:36:10
   |
36 | fn naked(x: usize, y: usize) {
   |          ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `y`
  --> /checkout/src/test/debuginfo/function-arguments-naked.rs:36:20
   |
36 | fn naked(x: usize, y: usize) {
   |                    ^ help: if this is intentional, prefix it with an underscore: `_y`

rustc: /checkout/src/llvm-project/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h:197: unsigned int llvm::AArch64FunctionInfo::getCalleeSavedStackSize(const llvm::MachineFrameInfo&) const: Assertion `MFI.isCalleeSavedInfoValid() && "CalleeSavedInfo not calculated"' failed.

------------------------------------------
@pietroalbini pietroalbini added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state C-bug Category: This is a bug. labels Aug 3, 2020
@pietroalbini
Copy link
Member Author

@rustbot ping arm

@rustbot
Copy link
Collaborator

rustbot commented Aug 3, 2020

Hey ARM Group! This bug has been identified as a good "ARM candidate".
In case it's useful, here are some instructions for tackling these sorts of
bugs. Maybe take a look?
Thanks! <3

cc @JamieCunliffe @joaopaulocarreiro @raw-bin @Stammark @vigoux

@mati865

This comment has been minimized.

@JamieCunliffe
Copy link
Contributor

JamieCunliffe commented Aug 3, 2020

The test is causing an infinite loop due to the link register being updated during the call to zzz, that call is causing the link register to be the ret instruction after that call, the ret instruction then returns to the link register causing an infinite loop. Normally before the call the link register would be saved and then restored after the call, however due to this being a naked function that isn't happening.

The emitted LLVM IR is just calling the function and that call isn't preserving anything so this could change in a future version of LLVM I suppose.
Although with c++ and clang that code would fail to compile as you can only use asm inside a naked function. https://internals.rust-lang.org/t/idea-naked-functions-2-0/11637/25 suggests it's a bug in rustc for allowing the code to compile, @Amanieu is that still your understanding?

I also suspect it's why this #74847 was raised.

I can get the test to pass, but I'm wondering if the test is actually correct in it's current state.

EDIT: It's probably worth pointing out that the code in that test will segfault on x86_64

@Amanieu
Copy link
Member

Amanieu commented Aug 3, 2020

The test is definitely incorrect. Using anything other than inline asm in a naked function is UB.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 8, 2020
…ked, r=Amanieu

Don't call a function in function-arguments-naked.rs

Fixes rust-lang#75096

It's U.B. to use anything other than inline assmebling in a naked
function. Fortunately, the `#break` directive works fine without
anything in the function body.
@bors bors closed this as completed in bbcacdd Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants