Merge tag 'perf-tools-for-v6.6-1-2023-09-05' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-block.git] / rust / compiler_builtins.rs
CommitLineData
db958dcf
MO
1// SPDX-License-Identifier: GPL-2.0
2
3//! Our own `compiler_builtins`.
4//!
5//! Rust provides [`compiler_builtins`] as a port of LLVM's [`compiler-rt`].
6//! Since we do not need the vast majority of them, we avoid the dependency
7//! by providing this file.
8//!
9//! At the moment, some builtins are required that should not be. For instance,
10//! [`core`] has 128-bit integers functionality which we should not be compiling
11//! in. We will work with upstream [`core`] to provide feature flags to disable
12//! the parts we do not need. For the moment, we define them to [`panic!`] at
13//! runtime for simplicity to catch mistakes, instead of performing surgery
14//! on `core.o`.
15//!
16//! In any case, all these symbols are weakened to ensure we do not override
17//! those that may be provided by the rest of the kernel.
18//!
19//! [`compiler_builtins`]: https://github.com/rust-lang/compiler-builtins
20//! [`compiler-rt`]: https://compiler-rt.llvm.org/
21
22#![feature(compiler_builtins)]
23#![compiler_builtins]
24#![no_builtins]
25#![no_std]
26
27macro_rules! define_panicking_intrinsics(
28 ($reason: tt, { $($ident: ident, )* }) => {
29 $(
30 #[doc(hidden)]
cb7d9def 31 #[export_name = concat!("__rust", stringify!($ident))]
db958dcf
MO
32 pub extern "C" fn $ident() {
33 panic!($reason);
34 }
35 )*
36 }
37);
38
39define_panicking_intrinsics!("`f32` should not be used", {
89eed1ab 40 __addsf3,
db958dcf
MO
41 __eqsf2,
42 __gesf2,
43 __lesf2,
89eed1ab
MO
44 __ltsf2,
45 __mulsf3,
db958dcf
MO
46 __nesf2,
47 __unordsf2,
48});
49
50define_panicking_intrinsics!("`f64` should not be used", {
89eed1ab
MO
51 __adddf3,
52 __ledf2,
53 __ltdf2,
54 __muldf3,
db958dcf
MO
55 __unorddf2,
56});
57
58define_panicking_intrinsics!("`i128` should not be used", {
59 __ashrti3,
60 __muloti4,
61 __multi3,
62});
63
64define_panicking_intrinsics!("`u128` should not be used", {
65 __ashlti3,
66 __lshrti3,
67 __udivmodti4,
68 __udivti3,
69 __umodti3,
70});
cb7d9def
GG
71
72// NOTE: if you are adding a new intrinsic here, you should also add it to
73// `redirect-intrinsics` in `rust/Makefile`.