1401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar/* ===-- int_util.c - Implement internal utilities --------------------------===
2401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar *
3401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar *                     The LLVM Compiler Infrastructure
4401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar *
5401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar * This file is dual licensed under the MIT and the University of Illinois Open
6401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar * Source Licenses. See LICENSE.TXT for details.
7401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar *
8401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar * ===----------------------------------------------------------------------===
9401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar */
10401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar
11401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar#include "int_util.h"
12401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar#include "int_lib.h"
13401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar
141626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar/* NOTE: The definitions in this file are declared weak because we clients to be
151626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar * able to arbitrarily package individual functions into separate .a files. If
161626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar * we did not declare these weak, some link situations might end up seeing
171626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar * duplicate strong definitions of the same symbol.
181626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar *
191626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar * We can't use this solution for kernel use (which may not support weak), but
201626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar * currently expect that when built for kernel use all the functionality is
211626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar * packaged into a single library.
221626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar */
231626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar
24401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar#ifdef KERNEL_USE
25401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar
26401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbarextern void panic(const char *, ...) __attribute__((noreturn));
27401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar__attribute__((visibility("hidden")))
28401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbarvoid compilerrt_abort_impl(const char *file, int line, const char *function) {
29401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar  panic("%s:%d: abort in %s", file, line, function);
30401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar}
31401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar
32c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik#elif __APPLE__ && !__STATIC__
33c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik
34c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik/* from libSystem.dylib */
35c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzikextern void __assert_rtn(const char *func, const char *file,
36c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik                     int line, const char * message) __attribute__((noreturn));
37c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik
38c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik__attribute__((weak))
39c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik__attribute__((visibility("hidden")))
40c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzikvoid compilerrt_abort_impl(const char *file, int line, const char *function) {
41c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik  __assert_rtn(function, file, line, "libcompiler_rt abort");
42c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik}
43c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik
44c453bd5ba0faad8344cb94d627a6683a9ad14ca7Nick Kledzik
45401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar#else
46401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar
47401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar/* Get the system definition of abort() */
48401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar#include <stdlib.h>
49401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar
501626d864159d42d1c5a492c1cb686f629e81f815Daniel Dunbar__attribute__((weak))
51401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar__attribute__((visibility("hidden")))
52401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbarvoid compilerrt_abort_impl(const char *file, int line, const char *function) {
53401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar  abort();
54401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar}
55401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar
56401f693a874c0f2fd9e37173e3ab7045a1bdeb3dDaniel Dunbar#endif
57