]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/builtins/int_util.c
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / builtins / int_util.c
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
9 #include "int_lib.h"
10
11 // NOTE: The definitions in this file are declared weak because we clients to be
12 // able to arbitrarily package individual functions into separate .a files. If
13 // we did not declare these weak, some link situations might end up seeing
14 // duplicate strong definitions of the same symbol.
15 //
16 // We can't use this solution for kernel use (which may not support weak), but
17 // currently expect that when built for kernel use all the functionality is
18 // packaged into a single library.
19
20 #ifdef KERNEL_USE
21
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
30 #elif __APPLE__
31
32 // from libSystem.dylib
33 NORETURN extern void __assert_rtn(const char *func, const char *file, int line,
34                                   const char *message);
35
36 #ifndef _WIN32
37 __attribute__((weak))
38 __attribute__((visibility("hidden")))
39 #endif
40 void __compilerrt_abort_impl(const char *file, int line, const char *function) {
41   __assert_rtn(function, file, line, "libcompiler_rt abort");
42 }
43
44 #elif __Fuchsia__
45
46 #ifndef _WIN32
47 __attribute__((weak))
48 __attribute__((visibility("hidden")))
49 #endif
50 void __compilerrt_abort_impl(const char *file, int line, const char *function) {
51   __builtin_trap();
52 }
53
54 #else
55
56 // Get the system definition of abort()
57 #include <stdlib.h>
58
59 #ifndef _WIN32
60 __attribute__((weak))
61 __attribute__((visibility("hidden")))
62 #endif
63 void __compilerrt_abort_impl(const char *file, int line, const char *function) {
64   abort();
65 }
66
67 #endif