Skip to content

noreturn on diverging functions makes LLVM trash the link register on thumb targets #69231

Closed
@jonas-schievink

Description

@jonas-schievink

Downstream issue: rust-embedded/cortex-m-rt#139

It looks like LLVM is extremely eager to overwrite the Link Register without saving it as soon as noreturn is put on a function. Since rustc does that for any -> ! function, which includes many parts of the panic machinery, this effectively makes obtaining a backtrace on panic on embedded systems impossible.

This is somewhat analogous to omission of frame pointers on x86, so maybe -Cforce-frame-pointers can be repurposed to prevent this behavior on Thumb/ARM targets? I'm not sure there's even an LLVM feature to control this specifically, but I suppose rustc could always omit the noreturn.

Since this is only important in debug builds (that may be optimized, however), it might make sense to couple this behavior to whether debug assertions are enabled, but I'm not sure about that. What do you think? Would a patch doing something of this sort be accepted?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.O-ArmTarget: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 stateT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-embeddedWorking group: Embedded systems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions