int_util.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===-- int_util.c - Implement internal utilities -------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "int_lib.h"
  9. // NOTE: The definitions in this file are declared weak because we clients to be
  10. // able to arbitrarily package individual functions into separate .a files. If
  11. // we did not declare these weak, some link situations might end up seeing
  12. // duplicate strong definitions of the same symbol.
  13. //
  14. // We can't use this solution for kernel use (which may not support weak), but
  15. // currently expect that when built for kernel use all the functionality is
  16. // packaged into a single library.
  17. #ifdef KERNEL_USE
  18. NORETURN extern void panic(const char *, ...);
  19. #ifndef _WIN32
  20. __attribute__((visibility("hidden")))
  21. #endif
  22. void __compilerrt_abort_impl(const char *file, int line, const char *function) {
  23. panic("%s:%d: abort in %s", file, line, function);
  24. }
  25. #elif __APPLE__
  26. // from libSystem.dylib
  27. NORETURN extern void __assert_rtn(const char *func, const char *file, int line,
  28. const char *message);
  29. __attribute__((weak))
  30. __attribute__((visibility("hidden")))
  31. void __compilerrt_abort_impl(const char *file, int line, const char *function) {
  32. __assert_rtn(function, file, line, "libcompiler_rt abort");
  33. }
  34. #else
  35. #ifdef _WIN32
  36. #include <stdlib.h>
  37. #endif
  38. #ifndef _WIN32
  39. __attribute__((weak))
  40. __attribute__((visibility("hidden")))
  41. #endif
  42. void __compilerrt_abort_impl(const char *file, int line, const char *function) {
  43. #if !__STDC_HOSTED__
  44. // Avoid depending on libc when compiling with -ffreestanding.
  45. __builtin_trap();
  46. #elif defined(_WIN32)
  47. abort();
  48. #else
  49. __builtin_abort();
  50. #endif
  51. }
  52. #endif