compiler_builtins.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0
  2. //! Our own `compiler_builtins`.
  3. //!
  4. //! Rust provides [`compiler_builtins`] as a port of LLVM's [`compiler-rt`].
  5. //! Since we do not need the vast majority of them, we avoid the dependency
  6. //! by providing this file.
  7. //!
  8. //! At the moment, some builtins are required that should not be. For instance,
  9. //! [`core`] has 128-bit integers functionality which we should not be compiling
  10. //! in. We will work with upstream [`core`] to provide feature flags to disable
  11. //! the parts we do not need. For the moment, we define them to [`panic!`] at
  12. //! runtime for simplicity to catch mistakes, instead of performing surgery
  13. //! on `core.o`.
  14. //!
  15. //! In any case, all these symbols are weakened to ensure we do not override
  16. //! those that may be provided by the rest of the kernel.
  17. //!
  18. //! [`compiler_builtins`]: https://github.com/rust-lang/compiler-builtins
  19. //! [`compiler-rt`]: https://compiler-rt.llvm.org/
  20. #![feature(compiler_builtins)]
  21. #![compiler_builtins]
  22. #![no_builtins]
  23. #![no_std]
  24. macro_rules! define_panicking_intrinsics(
  25. ($reason: tt, { $($ident: ident, )* }) => {
  26. $(
  27. #[doc(hidden)]
  28. #[no_mangle]
  29. pub extern "C" fn $ident() {
  30. panic!($reason);
  31. }
  32. )*
  33. }
  34. );
  35. define_panicking_intrinsics!("`f32` should not be used", {
  36. __eqsf2,
  37. __gesf2,
  38. __lesf2,
  39. __nesf2,
  40. __unordsf2,
  41. });
  42. define_panicking_intrinsics!("`f64` should not be used", {
  43. __unorddf2,
  44. });
  45. define_panicking_intrinsics!("`i128` should not be used", {
  46. __ashrti3,
  47. __muloti4,
  48. __multi3,
  49. });
  50. define_panicking_intrinsics!("`u128` should not be used", {
  51. __ashlti3,
  52. __lshrti3,
  53. __udivmodti4,
  54. __udivti3,
  55. __umodti3,
  56. });