Skip to content

avr: Provide abort() #830

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

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
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 compiler-builtins/src/avr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
intrinsics! {
pub unsafe extern "C" fn abort() -> ! {
// On AVRs, an architecture that doesn't support traps, unreachable code
// paths get lowered into calls to `abort`:
//
// https://github.com/llvm/llvm-project/blob/cbe8f3ad7621e402b050e768f400ff0d19c3aedd/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp#L4462
//
// When control gets here, it means that either core::intrinsics::abort()
// was called or an undefined bebavior has occurred, so there's not that
// much we can do to recover - we can't `panic!()`, because for all we
// know the environment is gone now, so panicking might end up with us
// getting back to this very function.
//
// So let's do the next best thing, loop.
//
// Alternatively we could (try to) restart the program, but since
// undefined behavior is undefined, there's really no obligation for us
// to do anything here - for all we care, we could just set the chip on
// fire; but that'd be bad for the environment.

loop {}
}
}
3 changes: 3 additions & 0 deletions compiler-builtins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub mod aarch64_linux;
))]
pub mod arm_linux;

#[cfg(target_arch = "avr")]
pub mod avr;

#[cfg(target_arch = "hexagon")]
pub mod hexagon;

Expand Down
Loading