blob: de87410dbca281b4d4054eaafbff1329b57ef642 [file] [log] [blame]
Daniel Dunbar2b88e032011-11-16 01:19:19 +00001/* ===-- 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 Dunbar2b88e032011-11-16 01:19:19 +000011#include "int_lib.h"
Saleem Abdulrasoold2eb26c2015-10-06 04:33:08 +000012#include "int_util.h"
Daniel Dunbar2b88e032011-11-16 01:19:19 +000013
Daniel Dunbare2ed5fb2011-11-29 19:44:14 +000014/* 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 Dunbar2b88e032011-11-16 01:19:19 +000024#ifdef KERNEL_USE
25
Saleem Abdulrasool8b3353f2015-10-11 17:35:38 +000026NORETURN extern void panic(const char *, ...);
Anton Korobeynikovec42bd92013-07-16 22:37:55 +000027#ifndef _WIN32
Daniel Dunbar2b88e032011-11-16 01:19:19 +000028__attribute__((visibility("hidden")))
Anton Korobeynikovec42bd92013-07-16 22:37:55 +000029#endif
Daniel Dunbar2b88e032011-11-16 01:19:19 +000030void compilerrt_abort_impl(const char *file, int line, const char *function) {
31 panic("%s:%d: abort in %s", file, line, function);
32}
33
Tim Northover084647d2013-11-15 23:00:42 +000034#elif __APPLE__
Nick Kledzik686f0d12012-02-03 23:53:40 +000035
36/* from libSystem.dylib */
Saleem Abdulrasool8b3353f2015-10-11 17:35:38 +000037NORETURN extern void __assert_rtn(const char *func, const char *file, int line,
38 const char *message);
Nick Kledzik686f0d12012-02-03 23:53:40 +000039
Anton Korobeynikovec42bd92013-07-16 22:37:55 +000040#ifndef _WIN32
Nick Kledzik686f0d12012-02-03 23:53:40 +000041__attribute__((weak))
42__attribute__((visibility("hidden")))
Anton Korobeynikovec42bd92013-07-16 22:37:55 +000043#endif
Nick Kledzik686f0d12012-02-03 23:53:40 +000044void compilerrt_abort_impl(const char *file, int line, const char *function) {
45 __assert_rtn(function, file, line, "libcompiler_rt abort");
46}
47
Petr Hosek969518b2017-07-12 19:33:30 +000048#elif __Fuchsia__
49
50#ifndef _WIN32
51__attribute__((weak))
52__attribute__((visibility("hidden")))
53#endif
54void compilerrt_abort_impl(const char *file, int line, const char *function) {
55 __builtin_trap();
56}
57
Daniel Dunbar2b88e032011-11-16 01:19:19 +000058#else
59
60/* Get the system definition of abort() */
61#include <stdlib.h>
62
Anton Korobeynikovec42bd92013-07-16 22:37:55 +000063#ifndef _WIN32
Daniel Dunbare2ed5fb2011-11-29 19:44:14 +000064__attribute__((weak))
Daniel Dunbar2b88e032011-11-16 01:19:19 +000065__attribute__((visibility("hidden")))
Anton Korobeynikovec42bd92013-07-16 22:37:55 +000066#endif
Daniel Dunbar2b88e032011-11-16 01:19:19 +000067void compilerrt_abort_impl(const char *file, int line, const char *function) {
68 abort();
69}
70
71#endif