blob: c82f56d2320c76a8e48fa7b8da1f993269711902 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
Elliott Hughesc999f762014-07-10 16:57:27 -070028
Elliott Hughesc999f762014-07-10 16:57:27 -070029// clang interprets -fno-builtin more loosely than you might expect,
30// and thinks it's okay to still substitute builtins as long as they're
31// named __aeabi_* rather than __builtin_*, which causes infinite
32// recursion if we have the fortified memcpy visible in this file.
33#undef _FORTIFY_SOURCE
Elliott Hughesc999f762014-07-10 16:57:27 -070034
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035#include <stddef.h>
36#include <string.h>
37
Elliott Hughesc999f762014-07-10 16:57:27 -070038extern int __cxa_atexit(void (*)(void*), void*, void*);
David 'Digit' Turner3e16f842009-05-14 14:25:26 +020039
Dan Albert690211f2014-09-26 15:36:14 -070040// All of these are weak symbols to avoid multiple definition errors when
41// linking with libstdc++-v3 or compiler-rt.
42
David 'Digit' Turner0ba91ed2009-05-20 11:42:52 +020043/* The "C++ ABI for ARM" document states that static C++ constructors,
44 * which are called from the .init_array, should manually call
Nick Kralevichbdbdbb82013-08-27 16:35:01 -070045 * __aeabi_atexit() to register static destructors explicitly.
David 'Digit' Turner0ba91ed2009-05-20 11:42:52 +020046 *
47 * Note that 'dso_handle' is the address of a magic linker-generate
48 * variable from the shared object that contains the constructor/destructor
49 */
50
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051int __attribute__((weak))
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080052__aeabi_atexit_impl(void *object, void (*destructor) (void *), void *dso_handle) {
David 'Digit' Turner0ba91ed2009-05-20 11:42:52 +020053 return __cxa_atexit(destructor, object, dso_handle);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080054}
55
Dimitry Ivanov6f72fde2016-01-05 20:38:32 -080056int __attribute__((weak))
57__aeabi_atexit_impl2(void *object, void (*destructor) (void *), void *dso_handle) {
58 return __cxa_atexit(destructor, object, dso_handle);
59}
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080060
Dimitry Ivanov6f72fde2016-01-05 20:38:32 -080061
62void __attribute__((weak)) __aeabi_memcpy8_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080063 memcpy(dest, src, n);
64}
65
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080066void __attribute__((weak)) __aeabi_memcpy4_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080067 memcpy(dest, src, n);
68}
69
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080070void __attribute__((weak)) __aeabi_memcpy_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080071 memcpy(dest, src, n);
72}
73
Dimitry Ivanov6f72fde2016-01-05 20:38:32 -080074void __attribute__((weak)) __aeabi_memcpy8_impl2(void *dest, const void *src, size_t n) {
75 memcpy(dest, src, n);
76}
77
78void __attribute__((weak)) __aeabi_memcpy4_impl2(void *dest, const void *src, size_t n) {
79 memcpy(dest, src, n);
80}
81
82void __attribute__((weak)) __aeabi_memcpy_impl2(void *dest, const void *src, size_t n) {
83 memcpy(dest, src, n);
84}
85
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080086
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080087void __attribute__((weak)) __aeabi_memmove8_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080088 memmove(dest, src, n);
89}
90
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080091void __attribute__((weak)) __aeabi_memmove4_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080092 memmove(dest, src, n);
93}
94
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080095void __attribute__((weak)) __aeabi_memmove_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080096 memmove(dest, src, n);
97}
98
Dimitry Ivanov6f72fde2016-01-05 20:38:32 -080099void __attribute__((weak)) __aeabi_memmove8_impl2(void *dest, const void *src, size_t n) {
100 memmove(dest, src, n);
101}
102
103void __attribute__((weak)) __aeabi_memmove4_impl2(void *dest, const void *src, size_t n) {
104 memmove(dest, src, n);
105}
106
107void __attribute__((weak)) __aeabi_memmove_impl2(void *dest, const void *src, size_t n) {
108 memmove(dest, src, n);
109}
110
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800111/*
Elliott Hughesc999f762014-07-10 16:57:27 -0700112 * __aeabi_memset has the order of its second and third arguments reversed.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800113 * This allows __aeabi_memclr to tail-call __aeabi_memset
114 */
Elliott Hughesc999f762014-07-10 16:57:27 -0700115
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800116void __attribute__((weak)) __aeabi_memset8_impl(void *dest, size_t n, int c) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800117 memset(dest, c, n);
118}
119
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800120void __attribute__((weak)) __aeabi_memset4_impl(void *dest, size_t n, int c) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800121 memset(dest, c, n);
122}
123
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800124void __attribute__((weak)) __aeabi_memset_impl(void *dest, size_t n, int c) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800125 memset(dest, c, n);
126}
127
Dimitry Ivanov6f72fde2016-01-05 20:38:32 -0800128void __attribute__((weak)) __aeabi_memset8_impl2(void *dest, size_t n, int c) {
129 memset(dest, c, n);
130}
131
132void __attribute__((weak)) __aeabi_memset4_impl2(void *dest, size_t n, int c) {
133 memset(dest, c, n);
134}
135
136void __attribute__((weak)) __aeabi_memset_impl2(void *dest, size_t n, int c) {
137 memset(dest, c, n);
138}
139
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800140
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800141void __attribute__((weak)) __aeabi_memclr8_impl(void *dest, size_t n) {
142 __aeabi_memset8_impl(dest, n, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800143}
144
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800145void __attribute__((weak)) __aeabi_memclr4_impl(void *dest, size_t n) {
146 __aeabi_memset4_impl(dest, n, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800147}
148
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800149void __attribute__((weak)) __aeabi_memclr_impl(void *dest, size_t n) {
150 __aeabi_memset_impl(dest, n, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800151}
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800152
Dimitry Ivanov6f72fde2016-01-05 20:38:32 -0800153void __attribute__((weak)) __aeabi_memclr8_impl2(void *dest, size_t n) {
154 __aeabi_memset8_impl(dest, n, 0);
155}
156
157void __attribute__((weak)) __aeabi_memclr4_impl2(void *dest, size_t n) {
158 __aeabi_memset4_impl(dest, n, 0);
159}
160
161void __attribute__((weak)) __aeabi_memclr_impl2(void *dest, size_t n) {
162 __aeabi_memset_impl(dest, n, 0);
163}
164
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800165#define __AEABI_SYMVERS(fn_name) \
Dimitry Ivanov6d142bc2016-01-08 10:06:44 -0800166__asm__(".symver " #fn_name "_impl, " #fn_name "@@LIBC_N"); \
Dimitry Ivanov6f72fde2016-01-05 20:38:32 -0800167__asm__(".symver " #fn_name "_impl2, " #fn_name "@LIBC_PRIVATE")
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800168
169__AEABI_SYMVERS(__aeabi_atexit);
170__AEABI_SYMVERS(__aeabi_memcpy8);
171__AEABI_SYMVERS(__aeabi_memcpy4);
172__AEABI_SYMVERS(__aeabi_memcpy);
173__AEABI_SYMVERS(__aeabi_memmove8);
174__AEABI_SYMVERS(__aeabi_memmove4);
175__AEABI_SYMVERS(__aeabi_memmove);
176__AEABI_SYMVERS(__aeabi_memset8);
177__AEABI_SYMVERS(__aeabi_memset4);
178__AEABI_SYMVERS(__aeabi_memset);
179__AEABI_SYMVERS(__aeabi_memclr8);
180__AEABI_SYMVERS(__aeabi_memclr4);
181__AEABI_SYMVERS(__aeabi_memclr);
182
183#undef __AEABI_SYMVERS