about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatryk Wychowaniec <pwychowaniec@pm.me>2025-04-20 09:05:10 +0200
committerTrevor Gross <t.gross35@gmail.com>2025-04-21 03:02:24 -0400
commite0d07241d06960b248d32fc2d33e5082c5ec8d53 (patch)
treeb0d11f1b05999437a7769c310f0299285e371da1
parent97ddaca3565d2720c2ccfe78e02e841dc3872005 (diff)
downloadrust-e0d07241d06960b248d32fc2d33e5082c5ec8d53.tar.gz
rust-e0d07241d06960b248d32fc2d33e5082c5ec8d53.zip
avr: Provide `abort()`
-rw-r--r--library/compiler-builtins/compiler-builtins/src/avr.rs23
-rw-r--r--library/compiler-builtins/compiler-builtins/src/lib.rs3
2 files changed, 26 insertions, 0 deletions
diff --git a/library/compiler-builtins/compiler-builtins/src/avr.rs b/library/compiler-builtins/compiler-builtins/src/avr.rs
new file mode 100644
index 00000000000..359a1d1acc1
--- /dev/null
+++ b/library/compiler-builtins/compiler-builtins/src/avr.rs
@@ -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 {}
+    }
+}
diff --git a/library/compiler-builtins/compiler-builtins/src/lib.rs b/library/compiler-builtins/compiler-builtins/src/lib.rs
index 16de96b4da0..0678556037f 100644
--- a/library/compiler-builtins/compiler-builtins/src/lib.rs
+++ b/library/compiler-builtins/compiler-builtins/src/lib.rs
@@ -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;