blob: 420d1e237aae1c7727df3e7e181b4b7c96564c6b [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
Daniel Dunbar401f6932011-11-16 01:19:19 +000011#include "int_lib.h"
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080012#include "int_util.h"
Daniel Dunbar401f6932011-11-16 01:19:19 +000013
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
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080026NORETURN extern void panic(const char *, ...);
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
Tim Northover868082b2013-11-15 23:00:42 +000034#elif __APPLE__
Nick Kledzikc453bd52012-02-03 23:53:40 +000035
36/* from libSystem.dylib */
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080037NORETURN extern void __assert_rtn(const char *func, const char *file, int line,
38 const char *message);
Nick Kledzikc453bd52012-02-03 23:53:40 +000039
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
Daniel Dunbar401f6932011-11-16 01:19:19 +000048#else
49
50/* Get the system definition of abort() */
51#include <stdlib.h>
52
Anton Korobeynikov6092c212013-07-16 22:37:55 +000053#ifndef _WIN32
Daniel Dunbar1626d862011-11-29 19:44:14 +000054__attribute__((weak))
Daniel Dunbar401f6932011-11-16 01:19:19 +000055__attribute__((visibility("hidden")))
Anton Korobeynikov6092c212013-07-16 22:37:55 +000056#endif
Daniel Dunbar401f6932011-11-16 01:19:19 +000057void compilerrt_abort_impl(const char *file, int line, const char *function) {
58 abort();
59}
60
61#endif