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