blob: 2c5ecc75b831071d226aa8800945c9f8f5e1850e [file] [log] [blame]
Daniel Dunbar401f6932011-11-16 01:19:19 +00001/* ===-- int_util.c - Implement internal utilities --------------------------===
2 *
Chandler Carruth7a739a02019-01-19 10:56:40 +00003 * 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 Dunbar401f6932011-11-16 01:19:19 +00006 *
7 * ===----------------------------------------------------------------------===
8 */
9
Daniel Dunbar401f6932011-11-16 01:19:19 +000010#include "int_lib.h"
Saleem Abdulrasoole2523412015-10-06 04:33:08 +000011#include "int_util.h"
Daniel Dunbar401f6932011-11-16 01:19:19 +000012
Daniel Dunbar1626d862011-11-29 19:44:14 +000013/* 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 Dunbar401f6932011-11-16 01:19:19 +000023#ifdef KERNEL_USE
24
Saleem Abdulrasoold13e1902015-10-11 17:35:38 +000025NORETURN extern void panic(const char *, ...);
Anton Korobeynikov6092c212013-07-16 22:37:55 +000026#ifndef _WIN32
Daniel Dunbar401f6932011-11-16 01:19:19 +000027__attribute__((visibility("hidden")))
Anton Korobeynikov6092c212013-07-16 22:37:55 +000028#endif
Richard Smith6b0b63e2018-09-08 00:17:37 +000029void __compilerrt_abort_impl(const char *file, int line, const char *function) {
Daniel Dunbar401f6932011-11-16 01:19:19 +000030 panic("%s:%d: abort in %s", file, line, function);
31}
32
Tim Northover868082b2013-11-15 23:00:42 +000033#elif __APPLE__
Nick Kledzikc453bd52012-02-03 23:53:40 +000034
35/* from libSystem.dylib */
Saleem Abdulrasoold13e1902015-10-11 17:35:38 +000036NORETURN extern void __assert_rtn(const char *func, const char *file, int line,
37 const char *message);
Nick Kledzikc453bd52012-02-03 23:53:40 +000038
Anton Korobeynikov6092c212013-07-16 22:37:55 +000039#ifndef _WIN32
Nick Kledzikc453bd52012-02-03 23:53:40 +000040__attribute__((weak))
41__attribute__((visibility("hidden")))
Anton Korobeynikov6092c212013-07-16 22:37:55 +000042#endif
Richard Smith6b0b63e2018-09-08 00:17:37 +000043void __compilerrt_abort_impl(const char *file, int line, const char *function) {
Nick Kledzikc453bd52012-02-03 23:53:40 +000044 __assert_rtn(function, file, line, "libcompiler_rt abort");
45}
46
Petr Hosek739a23e2017-07-12 19:33:30 +000047#elif __Fuchsia__
48
49#ifndef _WIN32
50__attribute__((weak))
51__attribute__((visibility("hidden")))
52#endif
Richard Smith6b0b63e2018-09-08 00:17:37 +000053void __compilerrt_abort_impl(const char *file, int line, const char *function) {
Petr Hosek739a23e2017-07-12 19:33:30 +000054 __builtin_trap();
55}
56
Daniel Dunbar401f6932011-11-16 01:19:19 +000057#else
58
59/* Get the system definition of abort() */
60#include <stdlib.h>
61
Anton Korobeynikov6092c212013-07-16 22:37:55 +000062#ifndef _WIN32
Daniel Dunbar1626d862011-11-29 19:44:14 +000063__attribute__((weak))
Daniel Dunbar401f6932011-11-16 01:19:19 +000064__attribute__((visibility("hidden")))
Anton Korobeynikov6092c212013-07-16 22:37:55 +000065#endif
Richard Smith6b0b63e2018-09-08 00:17:37 +000066void __compilerrt_abort_impl(const char *file, int line, const char *function) {
Daniel Dunbar401f6932011-11-16 01:19:19 +000067 abort();
68}
69
70#endif