Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 1 | /* ===-- int_util.c - Implement internal utilities --------------------------=== |
| 2 | * |
Chandler Carruth | 7a739a0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 6 | * |
| 7 | * ===----------------------------------------------------------------------=== |
| 8 | */ |
| 9 | |
Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 10 | #include "int_lib.h" |
Saleem Abdulrasool | e252341 | 2015-10-06 04:33:08 +0000 | [diff] [blame] | 11 | #include "int_util.h" |
Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 12 | |
Daniel Dunbar | 1626d86 | 2011-11-29 19:44:14 +0000 | [diff] [blame] | 13 | /* NOTE: The definitions in this file are declared weak because we clients to be |
| 14 | * able to arbitrarily package individual functions into separate .a files. If |
| 15 | * we did not declare these weak, some link situations might end up seeing |
| 16 | * duplicate strong definitions of the same symbol. |
| 17 | * |
| 18 | * We can't use this solution for kernel use (which may not support weak), but |
| 19 | * currently expect that when built for kernel use all the functionality is |
| 20 | * packaged into a single library. |
| 21 | */ |
| 22 | |
Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 23 | #ifdef KERNEL_USE |
| 24 | |
Saleem Abdulrasool | d13e190 | 2015-10-11 17:35:38 +0000 | [diff] [blame] | 25 | NORETURN extern void panic(const char *, ...); |
Anton Korobeynikov | 6092c21 | 2013-07-16 22:37:55 +0000 | [diff] [blame] | 26 | #ifndef _WIN32 |
Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 27 | __attribute__((visibility("hidden"))) |
Anton Korobeynikov | 6092c21 | 2013-07-16 22:37:55 +0000 | [diff] [blame] | 28 | #endif |
Richard Smith | 6b0b63e | 2018-09-08 00:17:37 +0000 | [diff] [blame] | 29 | void __compilerrt_abort_impl(const char *file, int line, const char *function) { |
Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 30 | panic("%s:%d: abort in %s", file, line, function); |
| 31 | } |
| 32 | |
Tim Northover | 868082b | 2013-11-15 23:00:42 +0000 | [diff] [blame] | 33 | #elif __APPLE__ |
Nick Kledzik | c453bd5 | 2012-02-03 23:53:40 +0000 | [diff] [blame] | 34 | |
| 35 | /* from libSystem.dylib */ |
Saleem Abdulrasool | d13e190 | 2015-10-11 17:35:38 +0000 | [diff] [blame] | 36 | NORETURN extern void __assert_rtn(const char *func, const char *file, int line, |
| 37 | const char *message); |
Nick Kledzik | c453bd5 | 2012-02-03 23:53:40 +0000 | [diff] [blame] | 38 | |
Anton Korobeynikov | 6092c21 | 2013-07-16 22:37:55 +0000 | [diff] [blame] | 39 | #ifndef _WIN32 |
Nick Kledzik | c453bd5 | 2012-02-03 23:53:40 +0000 | [diff] [blame] | 40 | __attribute__((weak)) |
| 41 | __attribute__((visibility("hidden"))) |
Anton Korobeynikov | 6092c21 | 2013-07-16 22:37:55 +0000 | [diff] [blame] | 42 | #endif |
Richard Smith | 6b0b63e | 2018-09-08 00:17:37 +0000 | [diff] [blame] | 43 | void __compilerrt_abort_impl(const char *file, int line, const char *function) { |
Nick Kledzik | c453bd5 | 2012-02-03 23:53:40 +0000 | [diff] [blame] | 44 | __assert_rtn(function, file, line, "libcompiler_rt abort"); |
| 45 | } |
| 46 | |
Petr Hosek | 739a23e | 2017-07-12 19:33:30 +0000 | [diff] [blame] | 47 | #elif __Fuchsia__ |
| 48 | |
| 49 | #ifndef _WIN32 |
| 50 | __attribute__((weak)) |
| 51 | __attribute__((visibility("hidden"))) |
| 52 | #endif |
Richard Smith | 6b0b63e | 2018-09-08 00:17:37 +0000 | [diff] [blame] | 53 | void __compilerrt_abort_impl(const char *file, int line, const char *function) { |
Petr Hosek | 739a23e | 2017-07-12 19:33:30 +0000 | [diff] [blame] | 54 | __builtin_trap(); |
| 55 | } |
| 56 | |
Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 57 | #else |
| 58 | |
| 59 | /* Get the system definition of abort() */ |
| 60 | #include <stdlib.h> |
| 61 | |
Anton Korobeynikov | 6092c21 | 2013-07-16 22:37:55 +0000 | [diff] [blame] | 62 | #ifndef _WIN32 |
Daniel Dunbar | 1626d86 | 2011-11-29 19:44:14 +0000 | [diff] [blame] | 63 | __attribute__((weak)) |
Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 64 | __attribute__((visibility("hidden"))) |
Anton Korobeynikov | 6092c21 | 2013-07-16 22:37:55 +0000 | [diff] [blame] | 65 | #endif |
Richard Smith | 6b0b63e | 2018-09-08 00:17:37 +0000 | [diff] [blame] | 66 | void __compilerrt_abort_impl(const char *file, int line, const char *function) { |
Daniel Dunbar | 401f693 | 2011-11-16 01:19:19 +0000 | [diff] [blame] | 67 | abort(); |
| 68 | } |
| 69 | |
| 70 | #endif |