blob: e4c85d96d3a251414030b1f3bc9123e76e38e4f9 [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
29#if defined(__clang__)
30// clang interprets -fno-builtin more loosely than you might expect,
31// and thinks it's okay to still substitute builtins as long as they're
32// named __aeabi_* rather than __builtin_*, which causes infinite
33// recursion if we have the fortified memcpy visible in this file.
34#undef _FORTIFY_SOURCE
35#endif
36
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080037#include <stddef.h>
38#include <string.h>
39
Elliott Hughesc999f762014-07-10 16:57:27 -070040extern int __cxa_atexit(void (*)(void*), void*, void*);
David 'Digit' Turner3e16f842009-05-14 14:25:26 +020041
Dan Albert690211f2014-09-26 15:36:14 -070042// All of these are weak symbols to avoid multiple definition errors when
43// linking with libstdc++-v3 or compiler-rt.
44
David 'Digit' Turner0ba91ed2009-05-20 11:42:52 +020045/* The "C++ ABI for ARM" document states that static C++ constructors,
46 * which are called from the .init_array, should manually call
Nick Kralevichbdbdbb82013-08-27 16:35:01 -070047 * __aeabi_atexit() to register static destructors explicitly.
David 'Digit' Turner0ba91ed2009-05-20 11:42:52 +020048 *
49 * Note that 'dso_handle' is the address of a magic linker-generate
50 * variable from the shared object that contains the constructor/destructor
51 */
52
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080053int __attribute__((weak))
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080054__aeabi_atexit_impl(void *object, void (*destructor) (void *), void *dso_handle) {
David 'Digit' Turner0ba91ed2009-05-20 11:42:52 +020055 return __cxa_atexit(destructor, object, dso_handle);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080056}
57
58
Dan Albert690211f2014-09-26 15:36:14 -070059void __attribute__((weak))
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080060__aeabi_memcpy8_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080061 memcpy(dest, src, n);
62}
63
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080064void __attribute__((weak)) __aeabi_memcpy4_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080065 memcpy(dest, src, n);
66}
67
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080068void __attribute__((weak)) __aeabi_memcpy_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080069 memcpy(dest, src, n);
70}
71
72
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080073void __attribute__((weak)) __aeabi_memmove8_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080074 memmove(dest, src, n);
75}
76
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080077void __attribute__((weak)) __aeabi_memmove4_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080078 memmove(dest, src, n);
79}
80
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080081void __attribute__((weak)) __aeabi_memmove_impl(void *dest, const void *src, size_t n) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080082 memmove(dest, src, n);
83}
84
85/*
Elliott Hughesc999f762014-07-10 16:57:27 -070086 * __aeabi_memset has the order of its second and third arguments reversed.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080087 * This allows __aeabi_memclr to tail-call __aeabi_memset
88 */
Elliott Hughesc999f762014-07-10 16:57:27 -070089
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080090void __attribute__((weak)) __aeabi_memset8_impl(void *dest, size_t n, int c) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080091 memset(dest, c, n);
92}
93
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080094void __attribute__((weak)) __aeabi_memset4_impl(void *dest, size_t n, int c) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080095 memset(dest, c, n);
96}
97
Dimitry Ivanovd90d0672016-01-05 16:38:43 -080098void __attribute__((weak)) __aeabi_memset_impl(void *dest, size_t n, int c) {
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080099 memset(dest, c, n);
100}
101
102
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800103void __attribute__((weak)) __aeabi_memclr8_impl(void *dest, size_t n) {
104 __aeabi_memset8_impl(dest, n, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800105}
106
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800107void __attribute__((weak)) __aeabi_memclr4_impl(void *dest, size_t n) {
108 __aeabi_memset4_impl(dest, n, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800109}
110
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800111void __attribute__((weak)) __aeabi_memclr_impl(void *dest, size_t n) {
112 __aeabi_memset_impl(dest, n, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800113}
Dimitry Ivanovd90d0672016-01-05 16:38:43 -0800114
115#define __AEABI_SYMVERS(fn_name) \
116__asm__(".symver " #fn_name "_impl, " #fn_name "@@LIBC"); \
117__asm__(".symver " #fn_name "_impl, " #fn_name "@LIBC_PRIVATE")
118
119__AEABI_SYMVERS(__aeabi_atexit);
120__AEABI_SYMVERS(__aeabi_memcpy8);
121__AEABI_SYMVERS(__aeabi_memcpy4);
122__AEABI_SYMVERS(__aeabi_memcpy);
123__AEABI_SYMVERS(__aeabi_memmove8);
124__AEABI_SYMVERS(__aeabi_memmove4);
125__AEABI_SYMVERS(__aeabi_memmove);
126__AEABI_SYMVERS(__aeabi_memset8);
127__AEABI_SYMVERS(__aeabi_memset4);
128__AEABI_SYMVERS(__aeabi_memset);
129__AEABI_SYMVERS(__aeabi_memclr8);
130__AEABI_SYMVERS(__aeabi_memclr4);
131__AEABI_SYMVERS(__aeabi_memclr);
132
133#undef __AEABI_SYMVERS