blob: 6d8922a7da43140d27eb96e9f53ddf32b7a7baf7 [file] [log] [blame]
Daniel Dunbar401f6932011-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
11#include "int_util.h"
12#include "int_lib.h"
13
Daniel Dunbar1626d862011-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 Dunbar401f6932011-11-16 01:19:19 +000024#ifdef KERNEL_USE
25
26extern void panic(const char *, ...) __attribute__((noreturn));
Anton Korobeynikov6092c212013-07-16 22:37:55 +000027#ifndef _WIN32
Daniel Dunbar401f6932011-11-16 01:19:19 +000028__attribute__((visibility("hidden")))
Anton Korobeynikov6092c212013-07-16 22:37:55 +000029#endif
Daniel Dunbar401f6932011-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
Nick Kledzikc453bd52012-02-03 23:53:40 +000034#elif __APPLE__ && !__STATIC__
35
36/* from libSystem.dylib */
37extern void __assert_rtn(const char *func, const char *file,
38 int line, const char * message) __attribute__((noreturn));
39
Anton Korobeynikov6092c212013-07-16 22:37:55 +000040#ifndef _WIN32
Nick Kledzikc453bd52012-02-03 23:53:40 +000041__attribute__((weak))
42__attribute__((visibility("hidden")))
Anton Korobeynikov6092c212013-07-16 22:37:55 +000043#endif
Nick Kledzikc453bd52012-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
48
Daniel Dunbar401f6932011-11-16 01:19:19 +000049#else
50
51/* Get the system definition of abort() */
52#include <stdlib.h>
53
Anton Korobeynikov6092c212013-07-16 22:37:55 +000054#ifndef _WIN32
Daniel Dunbar1626d862011-11-29 19:44:14 +000055__attribute__((weak))
Daniel Dunbar401f6932011-11-16 01:19:19 +000056__attribute__((visibility("hidden")))
Anton Korobeynikov6092c212013-07-16 22:37:55 +000057#endif
Daniel Dunbar401f6932011-11-16 01:19:19 +000058void compilerrt_abort_impl(const char *file, int line, const char *function) {
59 abort();
60}
61
62#endif