int_util.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* ===-- int_util.c - Implement internal utilities --------------------------===
  2. *
  3. * The LLVM Compiler Infrastructure
  4. *
  5. * This file is dual licensed under the MIT and the University of Illinois Open
  6. * Source Licenses. See LICENSE.TXT for details.
  7. *
  8. * ===----------------------------------------------------------------------===
  9. */
  10. #include "int_lib.h"
  11. #include "int_util.h"
  12. /* NOTE: The definitions in this file are declared weak because we clients to be
  13. * able to arbitrarily package individual functions into separate .a files. If
  14. * we did not declare these weak, some link situations might end up seeing
  15. * duplicate strong definitions of the same symbol.
  16. *
  17. * We can't use this solution for kernel use (which may not support weak), but
  18. * currently expect that when built for kernel use all the functionality is
  19. * packaged into a single library.
  20. */
  21. #ifdef KERNEL_USE
  22. NORETURN extern void panic(const char *, ...);
  23. #ifndef _WIN32
  24. __attribute__((visibility("hidden")))
  25. #endif
  26. void compilerrt_abort_impl(const char *file, int line, const char *function) {
  27. panic("%s:%d: abort in %s", file, line, function);
  28. }
  29. #elif __APPLE__
  30. /* from libSystem.dylib */
  31. NORETURN extern void __assert_rtn(const char *func, const char *file, int line,
  32. const char *message);
  33. #ifndef _WIN32
  34. __attribute__((weak))
  35. __attribute__((visibility("hidden")))
  36. #endif
  37. void compilerrt_abort_impl(const char *file, int line, const char *function) {
  38. __assert_rtn(function, file, line, "libcompiler_rt abort");
  39. }
  40. #else
  41. /* Get the system definition of abort() */
  42. #include <stdlib.h>
  43. #ifndef _WIN32
  44. __attribute__((weak))
  45. __attribute__((visibility("hidden")))
  46. #endif
  47. void compilerrt_abort_impl(const char *file, int line, const char *function) {
  48. abort();
  49. }
  50. #endif