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