The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 28 | |
| 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 Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | #include <stddef.h> |
| 38 | #include <string.h> |
| 39 | |
Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 40 | extern int __cxa_atexit(void (*)(void*), void*, void*); |
David 'Digit' Turner | 3e16f84 | 2009-05-14 14:25:26 +0200 | [diff] [blame] | 41 | |
Dan Albert | 690211f | 2014-09-26 15:36:14 -0700 | [diff] [blame] | 42 | // All of these are weak symbols to avoid multiple definition errors when |
| 43 | // linking with libstdc++-v3 or compiler-rt. |
| 44 | |
David 'Digit' Turner | 0ba91ed | 2009-05-20 11:42:52 +0200 | [diff] [blame] | 45 | /* The "C++ ABI for ARM" document states that static C++ constructors, |
| 46 | * which are called from the .init_array, should manually call |
Nick Kralevich | bdbdbb8 | 2013-08-27 16:35:01 -0700 | [diff] [blame] | 47 | * __aeabi_atexit() to register static destructors explicitly. |
David 'Digit' Turner | 0ba91ed | 2009-05-20 11:42:52 +0200 | [diff] [blame] | 48 | * |
| 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 Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 53 | int __attribute__((weak)) |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 54 | __aeabi_atexit_impl(void *object, void (*destructor) (void *), void *dso_handle) { |
David 'Digit' Turner | 0ba91ed | 2009-05-20 11:42:52 +0200 | [diff] [blame] | 55 | return __cxa_atexit(destructor, object, dso_handle); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame^] | 58 | int __attribute__((weak)) |
| 59 | __aeabi_atexit_impl2(void *object, void (*destructor) (void *), void *dso_handle) { |
| 60 | return __cxa_atexit(destructor, object, dso_handle); |
| 61 | } |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 62 | |
Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame^] | 63 | |
| 64 | void __attribute__((weak)) __aeabi_memcpy8_impl(void *dest, const void *src, size_t n) { |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 65 | memcpy(dest, src, n); |
| 66 | } |
| 67 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 68 | void __attribute__((weak)) __aeabi_memcpy4_impl(void *dest, const void *src, size_t n) { |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 69 | memcpy(dest, src, n); |
| 70 | } |
| 71 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 72 | void __attribute__((weak)) __aeabi_memcpy_impl(void *dest, const void *src, size_t n) { |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 73 | memcpy(dest, src, n); |
| 74 | } |
| 75 | |
Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame^] | 76 | void __attribute__((weak)) __aeabi_memcpy8_impl2(void *dest, const void *src, size_t n) { |
| 77 | memcpy(dest, src, n); |
| 78 | } |
| 79 | |
| 80 | void __attribute__((weak)) __aeabi_memcpy4_impl2(void *dest, const void *src, size_t n) { |
| 81 | memcpy(dest, src, n); |
| 82 | } |
| 83 | |
| 84 | void __attribute__((weak)) __aeabi_memcpy_impl2(void *dest, const void *src, size_t n) { |
| 85 | memcpy(dest, src, n); |
| 86 | } |
| 87 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 88 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 89 | void __attribute__((weak)) __aeabi_memmove8_impl(void *dest, const void *src, size_t n) { |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 90 | memmove(dest, src, n); |
| 91 | } |
| 92 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 93 | void __attribute__((weak)) __aeabi_memmove4_impl(void *dest, const void *src, size_t n) { |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 94 | memmove(dest, src, n); |
| 95 | } |
| 96 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 97 | void __attribute__((weak)) __aeabi_memmove_impl(void *dest, const void *src, size_t n) { |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 98 | memmove(dest, src, n); |
| 99 | } |
| 100 | |
Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame^] | 101 | void __attribute__((weak)) __aeabi_memmove8_impl2(void *dest, const void *src, size_t n) { |
| 102 | memmove(dest, src, n); |
| 103 | } |
| 104 | |
| 105 | void __attribute__((weak)) __aeabi_memmove4_impl2(void *dest, const void *src, size_t n) { |
| 106 | memmove(dest, src, n); |
| 107 | } |
| 108 | |
| 109 | void __attribute__((weak)) __aeabi_memmove_impl2(void *dest, const void *src, size_t n) { |
| 110 | memmove(dest, src, n); |
| 111 | } |
| 112 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 113 | /* |
Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 114 | * __aeabi_memset has the order of its second and third arguments reversed. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 115 | * This allows __aeabi_memclr to tail-call __aeabi_memset |
| 116 | */ |
Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 117 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 118 | void __attribute__((weak)) __aeabi_memset8_impl(void *dest, size_t n, int c) { |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 119 | memset(dest, c, n); |
| 120 | } |
| 121 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 122 | void __attribute__((weak)) __aeabi_memset4_impl(void *dest, size_t n, int c) { |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 123 | memset(dest, c, n); |
| 124 | } |
| 125 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 126 | void __attribute__((weak)) __aeabi_memset_impl(void *dest, size_t n, int c) { |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 127 | memset(dest, c, n); |
| 128 | } |
| 129 | |
Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame^] | 130 | void __attribute__((weak)) __aeabi_memset8_impl2(void *dest, size_t n, int c) { |
| 131 | memset(dest, c, n); |
| 132 | } |
| 133 | |
| 134 | void __attribute__((weak)) __aeabi_memset4_impl2(void *dest, size_t n, int c) { |
| 135 | memset(dest, c, n); |
| 136 | } |
| 137 | |
| 138 | void __attribute__((weak)) __aeabi_memset_impl2(void *dest, size_t n, int c) { |
| 139 | memset(dest, c, n); |
| 140 | } |
| 141 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 142 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 143 | void __attribute__((weak)) __aeabi_memclr8_impl(void *dest, size_t n) { |
| 144 | __aeabi_memset8_impl(dest, n, 0); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 147 | void __attribute__((weak)) __aeabi_memclr4_impl(void *dest, size_t n) { |
| 148 | __aeabi_memset4_impl(dest, n, 0); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 151 | void __attribute__((weak)) __aeabi_memclr_impl(void *dest, size_t n) { |
| 152 | __aeabi_memset_impl(dest, n, 0); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 153 | } |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 154 | |
Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame^] | 155 | void __attribute__((weak)) __aeabi_memclr8_impl2(void *dest, size_t n) { |
| 156 | __aeabi_memset8_impl(dest, n, 0); |
| 157 | } |
| 158 | |
| 159 | void __attribute__((weak)) __aeabi_memclr4_impl2(void *dest, size_t n) { |
| 160 | __aeabi_memset4_impl(dest, n, 0); |
| 161 | } |
| 162 | |
| 163 | void __attribute__((weak)) __aeabi_memclr_impl2(void *dest, size_t n) { |
| 164 | __aeabi_memset_impl(dest, n, 0); |
| 165 | } |
| 166 | |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 167 | #define __AEABI_SYMVERS(fn_name) \ |
| 168 | __asm__(".symver " #fn_name "_impl, " #fn_name "@@LIBC"); \ |
Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame^] | 169 | __asm__(".symver " #fn_name "_impl2, " #fn_name "@LIBC_PRIVATE") |
Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 170 | |
| 171 | __AEABI_SYMVERS(__aeabi_atexit); |
| 172 | __AEABI_SYMVERS(__aeabi_memcpy8); |
| 173 | __AEABI_SYMVERS(__aeabi_memcpy4); |
| 174 | __AEABI_SYMVERS(__aeabi_memcpy); |
| 175 | __AEABI_SYMVERS(__aeabi_memmove8); |
| 176 | __AEABI_SYMVERS(__aeabi_memmove4); |
| 177 | __AEABI_SYMVERS(__aeabi_memmove); |
| 178 | __AEABI_SYMVERS(__aeabi_memset8); |
| 179 | __AEABI_SYMVERS(__aeabi_memset4); |
| 180 | __AEABI_SYMVERS(__aeabi_memset); |
| 181 | __AEABI_SYMVERS(__aeabi_memclr8); |
| 182 | __AEABI_SYMVERS(__aeabi_memclr4); |
| 183 | __AEABI_SYMVERS(__aeabi_memclr); |
| 184 | |
| 185 | #undef __AEABI_SYMVERS |