diff --git a/ndk/platforms/README.CRT.TXT b/ndk/platforms/README.CRT.TXT new file mode 100644 index 000000000..82d0a1a6f --- /dev/null +++ b/ndk/platforms/README.CRT.TXT @@ -0,0 +1,274 @@ +This directory contains the sources of the C runtime object files +required by the Android NDK toolchains. This document explains +what they are, as well as a few important details about them. + +The files are located under the following directories: + + android-3/arch-arm/src/ + android-9/arch-x86/src/ + android-9/arch-mips/src/ + +They are all *assembly* files with an .S extension, which means that +they'll be sent to the C-preprocessor before being assembled into +object files. They have the following names and usage: + + crtbegin_static.S + This file contains a tiny ELF startup entry point (named '_start') + that is linked into every Android _static_ executable. These binaries can + run on any Linux ARM system, but cannot perform dynamic linking at all. + + Note that the kernel calls the '_start' entry point directly when it + launches such an executable. The _start stub is used to call the + C library's runtime initialization, passing it the address of the + 'main' function. + + crtbegin_dynamic.S + This is equivalent to crtbegin_static.S, for for _dynamic_ executables. + These executables always link to the system C library dynamically. + + When the kernel launches such an executable, it actually starts the + dynamic linker (/system/bin/linker), which loads and relocates the + executable (possibly loading any dependent system libraries as well), + then call the _start stub. + + crtbegin_so.S + This is equivalent to crtbegin_dynamic.S, but shall be used for + shared libraries. One major difference is that there is no _start + entry point. + + crtend_android.S + This source file shall be used when generating an executable, i.e. used + in association with either crtbegin_static.S or crtbegin_dynamic.S + + crtend.S + This source file is _strictly_ equivalent to crtend_android.S. + Actually, it *must* be compiled into an object named 'crtend_android.o' + because that's the hard-coded name that the toolchain binaries expect. + + (the naming difference for this source file is purely historical, it + could probably be removed in the future). + + crtend_so.S + This source's object file shall be used when generating a shared library, + i.e. used in association with crtbegin_so.S only. + +Content of these files: + +ELF section (lists); + + crtbegin_static.S + crtbegin_dynamic.S contain a '_start' entry point for + the corresponding executable. crtbegin_so.S doesn't need any. + + all crtbegin_XXX.s files contain the head of various ELF sections, which are + used to list of ELF constructors and destructors. The sections are: + + .init_array: + Contains a list of function addresses that are run at load time. + This means they are run *before* 'main', in the case of executables, + or during 'dlopen()' for shared libraries (either implicit or explicit). + + The functions are called in list order (from first to last). + + .fini_array: + Contains a list of destructor addresses that are run at unload time. + This means they are run *after* 'exit', in the case of executables, + or during 'dlclose()' for shared libraries (either implicit or explicit). + + The functions are called in _reverse_ list order (from last to first). + + .preinit_array: + This section can *only* appear in executables. It contains a list of + constructors that are run _before_ the ones in .init_array, or those + of any dependent shared library (if any). + + .ctors + This section shall *not* be used on Android. Used on some GLibc-based + Linux systems to hold list of constructors. The toolchains should + place all constructors in .init_array instead. + + .dtors + This section shall *not* be used on Android. Used on some GLibc-based + Linux systems to hold a list of destructors. The toolchains should + place all destructors in .fini_array instead. + + +__dso_handle symbol: + + To properly support the C++ ABI, a unique *local* *hidden* symbol named + '__dso_handle' must be defined in each shared library. + + This is used to implement static C++ object initialization in a shared + library, as in: + + static Foo foo(10); + + The statement above creates a hidden function, which address will be added + to the .init_array section described above. Its compiler-generated code + will perform the object construction, and also register static destructor + using a call that looks like: + + __cxa_atexit( Foo::~Foo, &foo, &__dso_handle ); + + Where '__cxa_atexit' is a special C++ support function provided by the + C library. Doing this ensures that the destructor for 'foo' will be + automatically called when the shared library containing this code is + unloaded (i.e. either through 'dlclose' or at program exit). + + The value of __dso_handle is normally never taken directly. + + See http://sourcery.mentor.com/public/cxx-abi/abi.html#dso-dtor + + WARNING: There is a big caveat regarding this symbol. Read the section + named 'IMPORTANT BACKWARDS COMPATIBILITY ISSUES' below. + + +atexit() implementation: + + The Posix standard doesn't mandate the program behaviour's when a shared + library which registered a function with 'atexit' is unloaded explicitely + (e.g. with 'dlclose()'). + + On most BSD systems (including OS X), unloading the library succeeds, but + the program will crash when it calls exit() or returns from main(). + + On Linux, GLibc provides an implementation that automatically unregisters + such atexit() handlers when the corresponding shared library is unloaded. + + However, this requires that the atexit() implementation be part of the + shared library itself, rather than the C library. + + The crtbegin_shared.S and crtbegin_static.S files contain an tiny + implementation of atexit() in assembler that essentially does: + + void atexit(void(*myfunc)(void)) + { + __cxa_atexit(myfunc, NULL, &__dso_handle); + } + + Because it references the shared library's hidden __dso_handle symbol, + this code cannot be in the C library itself. + + Note that crtbegin_static.S should *not* provide an atexit() function + (the latter should be provided by libc.a instead). + + See 'BACKWARDS COMPATIBILITY ISSUES' section below. + + + +BACKWARDS COMPATIBILITY ISSUES: +------------------------------- + +To maintain binary compatibility to all existing NDK-generated machine code, +the system's C library (i.e. /system/lib/libc.so) needs to exports symbols +that shall *not* be exported by the NDK-provided link-time libraries (i.e. +$NDK/platforms/android-$LEVEL/arch-$ARCH/usr/lib/libc.so). + +Starting from NDK r7, the NDK libc.so is itself generated by a script +(gen-platforms.sh) from a list of symbol files (see libc.so.functions.txt +and libc.so.variables.txt) and does not contain any implementation code. + +The NDK libc.a, on the other hand, is a copy of a given version of the system +C static library, and shall only be used to generate static executables (it +is also required to build gdbserver). + +1. libgcc compatibility symbols: + + None of the link-time NDK shared libraries should export any libgcc symbol. + + However, on ARM, the system C library needs to export some of them to + maintain binary compatibility with 'legacy' NDK machine code. Details are + under bionic/libc/arch-arm/bionic/libgcc_compat.c. + + Note that gen-platforms.sh takes care of this by explicitely removing any + libgcc symbol from the link-time shared libraries it generates. This is done + by using the lists under: + + $NDK/build/tools/toolchain-symbols/$ARCH/libgcc.a.functions.txt + + You will need to update these files when the toolchain changes. + + Note that all libgcc releases should be backwards-compatible, i.e. newer + releases always contain all the symbols from previous ones). + + +2. __dso_handle compatibility symbol: + + Earlier versions of the C library exported a __dso_handle symbol + *incorrectly*. As such: + + - the system's libc.so shall always export its __dso_handle, as *global* + and *public* (in ELF visibility terms). A weak symbol definition is ok + but not necessary. This is only to ensure binary compatibility with + 'legacy' NDK machine code. + + - the NDK link-time libc.so shall *never* export or contain any + __dso_handle symbol. + + - The NDK's crtbegin_dynamic.S and crtbegin_so.S shall provide a *local* + and *hidden* __dso_handle symbol. + + - The NDK's libc.a will containg a *global* and *public* __dso_handle, since + it is a copy of a release-specific system libc.so. + + - crtbegin_static.S shall not provide any __dso_handle symbol, since static + executables will use the one in libc.a instead. + +Note that existing NDK machine code that links against the system libc's +__dso_handle will not have their C++ destructors run correctly when the +library is unloaded. However, this bug can be solved by simply recompiling +/relinking against a newer NDK release, without touching the original +sources. + + + +3. atexit compatibility symbol: + + Earlier versions of the C library implemented and exported an atexit() + function. While this is compliant with Posix, this doesn't allow a useful + GLibc extension which automatically un-registers atexit() handlers when + a shared library is unloaded with dlclose(). + + To support this, while providing binary compatibility, the following + must apply: + + - The platform's /system/lib/libc.so should *always* export a working + atexit() implementation (used by 'legacy' NDK machine code). + + - The NDK link-time libc.so should *never* export atexit() + + - crtbegin_shared.S, crtbegin_so.S shall define a *local* *hidden* + symbol for atexit(), with a tiny implementation that amounts to the + following code: + + void atexit( void(*handler)(void) ) + { + __cxa_atexit( handler, NULL, &__dso_handle ); + } + + - The NDK libc.a shall provide an atexit() implementation, and + crtbegin_static.S shall *not* provide one to avoid conflicts. + +Note that existing NDK machine code that links against the system libc's +atexit symbol will not have their atexit-handler automatically unregistered +when the library is unloaded. However, this bug can be solved by simply +recompiling/relinking against a newer NDK release, without touching the +original sources. + +4. __atomic_xxx sompatibility symbols: + +This issues is detailed in ndk/docs/ANDROID-ATOMICS.html and +bionic/libc/arch-arm/bionic/atomics_arm.c. In a nutshell: + + - The system C library *shall* always export on *ARM* the __atomic_cmpxchg, + __atomic_inc and __atomic_dec functions to support legacy NDK machine code. + Their implementation should have full (i.e. acquire+release) memory ordering + semantics. + + - The system C library for other CPU architectures (e.g. x86 or mips) *shall* + *not* export any of these symbols. + + - The NDK libc.so *shall* *not* export these symbols at all. + + - The NDK header shall provide inlined-static versions of + these functions that use the built-in GCC atomic functions instead. + diff --git a/ndk/platforms/android-3/arch-arm/lib/crtbegin_dynamic.o b/ndk/platforms/android-3/arch-arm/lib/crtbegin_dynamic.o deleted file mode 100644 index f34cba84e..000000000 Binary files a/ndk/platforms/android-3/arch-arm/lib/crtbegin_dynamic.o and /dev/null differ diff --git a/ndk/platforms/android-3/arch-arm/lib/crtbegin_so.o b/ndk/platforms/android-3/arch-arm/lib/crtbegin_so.o deleted file mode 100644 index 523017896..000000000 Binary files a/ndk/platforms/android-3/arch-arm/lib/crtbegin_so.o and /dev/null differ diff --git a/ndk/platforms/android-3/arch-arm/lib/crtbegin_static.o b/ndk/platforms/android-3/arch-arm/lib/crtbegin_static.o deleted file mode 100644 index f34cba84e..000000000 Binary files a/ndk/platforms/android-3/arch-arm/lib/crtbegin_static.o and /dev/null differ diff --git a/ndk/platforms/android-3/arch-arm/lib/crtend_android.o b/ndk/platforms/android-3/arch-arm/lib/crtend_android.o deleted file mode 100644 index c57149e5d..000000000 Binary files a/ndk/platforms/android-3/arch-arm/lib/crtend_android.o and /dev/null differ diff --git a/ndk/platforms/android-3/arch-arm/lib/crtend_so.o b/ndk/platforms/android-3/arch-arm/lib/crtend_so.o deleted file mode 100644 index c54db97fd..000000000 Binary files a/ndk/platforms/android-3/arch-arm/lib/crtend_so.o and /dev/null differ diff --git a/ndk/platforms/android-3/arch-arm/src/__dso_handle.S b/ndk/platforms/android-3/arch-arm/src/__dso_handle.S new file mode 100644 index 000000000..2d783894d --- /dev/null +++ b/ndk/platforms/android-3/arch-arm/src/__dso_handle.S @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +# The __dso_handle global variable is used by static +# C++ constructors and destructors in the binary. +# See http://www.codesourcery.com/public/cxx-abi/abi.html#dso-dtor +# + .data + .align 4 + +/* CRT_LEGACY_WORKAROUND is only defined when building this file + * for the C library. This forces __dso_handle to be exported by + * it. This is only required to ensure binary compatibility with + * old NDK application machine code that contains reference to + * the symbol, but do not have a proper definition for it. + * + * These binaries cannot call their destructorson dlclose(), but + * at least they will not fail to load. + * + * When this file is built for the NDK, CRT_LEGACY_WORKAROUND + * should never be defined. + */ + +#ifndef CRT_LEGACY_WORKAROUND + .hidden __dso_handle +#endif + + .globl __dso_handle +__dso_handle: + .long __dso_handle diff --git a/ndk/platforms/android-3/arch-arm/src/__dso_handle_so.S b/ndk/platforms/android-3/arch-arm/src/__dso_handle_so.S new file mode 100644 index 000000000..77a5d7fba --- /dev/null +++ b/ndk/platforms/android-3/arch-arm/src/__dso_handle_so.S @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +# The __dso_handle global variable is used by static +# C++ constructors and destructors in the binary. +# See http://www.codesourcery.com/public/cxx-abi/abi.html#dso-dtor +# + .data + .align 4 + .hidden __dso_handle + .globl __dso_handle +__dso_handle: + .long __dso_handle diff --git a/ndk/platforms/android-3/arch-arm/src/atexit.S b/ndk/platforms/android-3/arch-arm/src/atexit.S new file mode 100644 index 000000000..b6401edab --- /dev/null +++ b/ndk/platforms/android-3/arch-arm/src/atexit.S @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* CRT_LEGACY_WORKAROUND should only be defined when building + * this file as part of the platform's C library. + * + * The C library already defines a function named 'atexit()' + * for backwards compatibility with older NDK-generated binaries. + * + * For newer ones, 'atexit' is actually embedded in the C + * runtime objects that are linked into the final ELF + * binary (shared library or executable), and will call + * __cxa_atexit() in order to un-register any atexit() + * handler when a library is unloaded. + * + * This function must be global *and* hidden. Only the + * code inside the same ELF binary should be able to access it. + */ +#ifndef CRT_LEGACY_WORKAROUND + .arch armv5te + .fpu softvfp + .eabi_attribute 20, 1 + .eabi_attribute 21, 1 + .eabi_attribute 23, 3 + .eabi_attribute 24, 1 + .eabi_attribute 25, 1 + .eabi_attribute 26, 2 + .eabi_attribute 30, 4 + .eabi_attribute 18, 4 + .hidden atexit + .code 16 + .thumb_func + .text + .align 0 + .global atexit + .type atexit, #function +atexit: .fnstart +.LFB0: + .save {r4, lr} + push {r4, lr} +.LCFI0: + ldr r3, .L3 + mov r1, #0 + @ sp needed for prologue +.LPIC0: + add r3, pc + ldr r2, [r3] + ldr r3, =__cxa_atexit + blx r3 + pop {r4, pc} +.L4: + .align 2 +.L3: + .word __dso_handle-(.LPIC0+4) +.LFE0: + .fnend + .size atexit, . - atexit +#endif diff --git a/ndk/platforms/android-3/arch-arm/src/crtbegin_dynamic.S b/ndk/platforms/android-3/arch-arm/src/crtbegin_dynamic.S new file mode 100644 index 000000000..6ca08458e --- /dev/null +++ b/ndk/platforms/android-3/arch-arm/src/crtbegin_dynamic.S @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + .text + .align 4 + .type _start,#function + .globl _start + +# this is the small startup code that is first run when +# any executable that is dynamically-linked with Bionic +# runs. +# +# it's purpose is to call __libc_init with appropriate +# arguments, which are: +# +# - the address of the raw data block setup by the Linux +# kernel ELF loader +# +# - address of an "onexit" function, not used on any +# platform supported by Bionic +# +# - address of the "main" function of the program. +# +# - address of the constructor list +# +_start: + mov r0, sp + mov r1, #0 + ldr r2, =main + adr r3, 1f + ldr r4, =__libc_init + bx r4 + +1: .long __PREINIT_ARRAY__ + .long __INIT_ARRAY__ + .long __FINI_ARRAY__ + .long __CTOR_LIST__ + + .section .preinit_array, "aw" + .globl __PREINIT_ARRAY__ +__PREINIT_ARRAY__: + .long -1 + + .section .init_array, "aw" + .globl __INIT_ARRAY__ +__INIT_ARRAY__: + .long -1 + + .section .fini_array, "aw" + .globl __FINI_ARRAY__ +__FINI_ARRAY__: + .long -1 + + .section .ctors, "aw" + .globl __CTOR_LIST__ +__CTOR_LIST__: + .long -1 + +#include "__dso_handle.S" +#include "atexit.S" diff --git a/ndk/platforms/android-3/arch-arm/src/crtbegin_so.S b/ndk/platforms/android-3/arch-arm/src/crtbegin_so.S new file mode 100644 index 000000000..9275b1e01 --- /dev/null +++ b/ndk/platforms/android-3/arch-arm/src/crtbegin_so.S @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +# Implement static C++ destructors when the shared +# library is unloaded through dlclose(). +# +# A call to this function must be the first entry +# in the .fini_array. See 3.3.5.3.C of C++ ABI +# standard. +# +__on_dlclose: + adr r0, 0f + ldr r0, [r0] + b __cxa_finalize + +0: + .long __dso_handle + + .section .init_array, "aw" + .globl __INIT_ARRAY__ +__INIT_ARRAY__: + .long -1 + + .section .fini_array, "aw" + .globl __FINI_ARRAY__ +__FINI_ARRAY__: + .long -1 + .long __on_dlclose + +#ifdef CRT_LEGACY_WORKAROUND +#include "__dso_handle.S" +#else +#include "__dso_handle_so.S" +#endif + +#include "atexit.S" diff --git a/ndk/platforms/android-3/arch-arm/src/crtbegin_static.S b/ndk/platforms/android-3/arch-arm/src/crtbegin_static.S new file mode 100644 index 000000000..ec13351eb --- /dev/null +++ b/ndk/platforms/android-3/arch-arm/src/crtbegin_static.S @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + .text + .align 4 + .type _start,#function + .globl _start + +# this is the small startup code that is first run when +# any executable that is statically-linked with Bionic +# runs. +# +# it's purpose is to call __libc_init with appropriate +# arguments, which are: +# +# - the address of the raw data block setup by the Linux +# kernel ELF loader +# +# - address of an "onexit" function, not used on any +# platform supported by Bionic +# +# - address of the "main" function of the program. +# +# - address of the constructor list +# +_start: + mov r0, sp + mov r1, #0 + ldr r2, =main + adr r3, 1f + ldr r4, =__libc_init + bx r4 + +1: .long __PREINIT_ARRAY__ + .long __INIT_ARRAY__ + .long __FINI_ARRAY__ + .long __CTOR_LIST__ + + .section .preinit_array, "aw" + .globl __PREINIT_ARRAY__ +__PREINIT_ARRAY__: + .long -1 + + .section .init_array, "aw" + .globl __INIT_ARRAY__ +__INIT_ARRAY__: + .long -1 + + .section .fini_array, "aw" + .globl __FINI_ARRAY__ +__FINI_ARRAY__: + .long -1 + + .section .ctors, "aw" + .globl __CTOR_LIST__ +__CTOR_LIST__: + .long -1 + + +#include "__dso_handle.S" +/* NOTE: atexit() is not be provided by crtbegin_static.S, but by libc.a */ + diff --git a/ndk/platforms/android-3/arch-arm/src/crtend.S b/ndk/platforms/android-3/arch-arm/src/crtend.S new file mode 100644 index 000000000..2f3b1ede3 --- /dev/null +++ b/ndk/platforms/android-3/arch-arm/src/crtend.S @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + .section .preinit_array, "aw" + .long 0 + + .section .init_array, "aw" + .long 0 + + .section .fini_array, "aw" + .long 0 + + .section .ctors, "aw" + .long 0 + diff --git a/ndk/platforms/android-3/arch-arm/src/crtend_so.S b/ndk/platforms/android-3/arch-arm/src/crtend_so.S new file mode 100644 index 000000000..a1281c402 --- /dev/null +++ b/ndk/platforms/android-3/arch-arm/src/crtend_so.S @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* This is the same than crtend.S except that a shared library + * cannot have a .preinit_array + */ + + .section .init_array, "aw" + .long 0 + + .section .fini_array, "aw" + .long 0 + diff --git a/ndk/platforms/android-9/arch-mips/lib/crtbegin_dynamic.o b/ndk/platforms/android-9/arch-mips/lib/crtbegin_dynamic.o deleted file mode 100644 index 3202d1a1c..000000000 Binary files a/ndk/platforms/android-9/arch-mips/lib/crtbegin_dynamic.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-mips/lib/crtbegin_so.o b/ndk/platforms/android-9/arch-mips/lib/crtbegin_so.o deleted file mode 100644 index ddfd10072..000000000 Binary files a/ndk/platforms/android-9/arch-mips/lib/crtbegin_so.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-mips/lib/crtbegin_static.o b/ndk/platforms/android-9/arch-mips/lib/crtbegin_static.o deleted file mode 100644 index 34c5337f8..000000000 Binary files a/ndk/platforms/android-9/arch-mips/lib/crtbegin_static.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-mips/lib/crtend_android.o b/ndk/platforms/android-9/arch-mips/lib/crtend_android.o deleted file mode 100644 index 4ac6536d4..000000000 Binary files a/ndk/platforms/android-9/arch-mips/lib/crtend_android.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-mips/lib/crtend_so.o b/ndk/platforms/android-9/arch-mips/lib/crtend_so.o deleted file mode 100644 index 5c686298c..000000000 Binary files a/ndk/platforms/android-9/arch-mips/lib/crtend_so.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-mips/src/crtbegin_static.S b/ndk/platforms/android-9/arch-mips/src/crtbegin_static.S index 9f00811ea..16534e88b 100644 --- a/ndk/platforms/android-9/arch-mips/src/crtbegin_static.S +++ b/ndk/platforms/android-9/arch-mips/src/crtbegin_static.S @@ -228,4 +228,4 @@ $L3: .weak __register_frame_info .include "__dso_handle.S" -.include "atexit.S" +/* NOTE: atexit() is not be provided by crtbegin_static.S, but by libc.a */ diff --git a/ndk/platforms/android-9/arch-x86/lib/crtbegin_dynamic.o b/ndk/platforms/android-9/arch-x86/lib/crtbegin_dynamic.o deleted file mode 100644 index 17704f55b..000000000 Binary files a/ndk/platforms/android-9/arch-x86/lib/crtbegin_dynamic.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-x86/lib/crtbegin_so.o b/ndk/platforms/android-9/arch-x86/lib/crtbegin_so.o deleted file mode 100644 index cf50f1de8..000000000 Binary files a/ndk/platforms/android-9/arch-x86/lib/crtbegin_so.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-x86/lib/crtbegin_static.o b/ndk/platforms/android-9/arch-x86/lib/crtbegin_static.o deleted file mode 100644 index 17704f55b..000000000 Binary files a/ndk/platforms/android-9/arch-x86/lib/crtbegin_static.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-x86/lib/crtend_android.o b/ndk/platforms/android-9/arch-x86/lib/crtend_android.o deleted file mode 100644 index 87716a04c..000000000 Binary files a/ndk/platforms/android-9/arch-x86/lib/crtend_android.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-x86/lib/crtend_so.o b/ndk/platforms/android-9/arch-x86/lib/crtend_so.o deleted file mode 100644 index 4c4460fbe..000000000 Binary files a/ndk/platforms/android-9/arch-x86/lib/crtend_so.o and /dev/null differ diff --git a/ndk/platforms/android-9/arch-x86/src/__dso_handle.S b/ndk/platforms/android-9/arch-x86/src/__dso_handle.S new file mode 100644 index 000000000..3e801284f --- /dev/null +++ b/ndk/platforms/android-9/arch-x86/src/__dso_handle.S @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +# The __dso_handle global variable is used by static +# C++ constructors and destructors in the binary. +# See http://www.codesourcery.com/public/cxx-abi/abi.html#dso-dtor +# + .section .bss + .align 4 + +#ifndef CRT_LEGACY_WORKAROUND + .hidden __dso_handle +#endif + + .globl __dso_handle +__dso_handle: + .long 0 diff --git a/ndk/platforms/android-9/arch-x86/src/__dso_handle_so.S b/ndk/platforms/android-9/arch-x86/src/__dso_handle_so.S new file mode 100644 index 000000000..77a5d7fba --- /dev/null +++ b/ndk/platforms/android-9/arch-x86/src/__dso_handle_so.S @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +# The __dso_handle global variable is used by static +# C++ constructors and destructors in the binary. +# See http://www.codesourcery.com/public/cxx-abi/abi.html#dso-dtor +# + .data + .align 4 + .hidden __dso_handle + .globl __dso_handle +__dso_handle: + .long __dso_handle diff --git a/ndk/platforms/android-9/arch-x86/src/__stack_chk_fail_local.S b/ndk/platforms/android-9/arch-x86/src/__stack_chk_fail_local.S new file mode 100644 index 000000000..59fe86ec3 --- /dev/null +++ b/ndk/platforms/android-9/arch-x86/src/__stack_chk_fail_local.S @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* + * Contributed by: Intel Corporation + */ + + .text + .p2align 4,,15 + .globl __stack_chk_fail_local + .hidden __stack_chk_fail_local + .type __stack_chk_fail_local, @function + +__stack_chk_fail_local: +#ifdef __PIC__ + pushl %ebx + call __x86.get_pc_thunk.bx + addl $_GLOBAL_OFFSET_TABLE_, %ebx + call __stack_chk_fail@PLT +#else /* PIC */ + jmp __stack_chk_fail +#endif /* not PIC */ + + .size __stack_chk_fail_local, .-__stack_chk_fail_local diff --git a/ndk/platforms/android-9/arch-x86/src/atexit.S b/ndk/platforms/android-9/arch-x86/src/atexit.S new file mode 100644 index 000000000..b28f40bb6 --- /dev/null +++ b/ndk/platforms/android-9/arch-x86/src/atexit.S @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + .text + .p2align 4,,15 + .globl atexit + .hidden atexit + .type atexit, @function +atexit: + pushl %ebp + movl %esp, %ebp + pushl %ebx + call __x86.get_pc_thunk.bx + addl $_GLOBAL_OFFSET_TABLE_, %ebx + subl $20, %esp + movl $0, 4(%esp) + movl __dso_handle@GOTOFF(%ebx), %eax + movl %eax, 8(%esp) + movl 8(%ebp), %eax + movl %eax, (%esp) + call __cxa_atexit@PLT + addl $20, %esp + popl %ebx + popl %ebp + ret + .size atexit, .-atexit + + .section .text.__x86.get_pc_thunk.bx,"axG",@progbits,__x86.get_pc_thunk.bx,comdat + .globl __x86.get_pc_thunk.bx + .hidden __x86.get_pc_thunk.bx + .type __x86.get_pc_thunk.bx, @function +__x86.get_pc_thunk.bx: + nop + nop + nop + nop + nop + nop + nop + nop + movl (%esp), %ebx + ret diff --git a/ndk/platforms/android-9/arch-x86/src/crtbegin_dynamic.S b/ndk/platforms/android-9/arch-x86/src/crtbegin_dynamic.S new file mode 100644 index 000000000..177244b70 --- /dev/null +++ b/ndk/platforms/android-9/arch-x86/src/crtbegin_dynamic.S @@ -0,0 +1,139 @@ +# bionic/arch-x86/bionic/crtbegin_dynamic.S +# +# Copyright 2006, The Android Open Source Project +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of Google Inc. nor the names of its contributors may +# be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + .text + .align 4 + .type _start, @function + .globl _start + +# this is the small startup code that is first run when +# any executable that is dynamically-linked with Bionic +# runs. +# +# it's purpose is to call __libc_init with appropriate +# arguments, which are: +# +# - the address of the raw data block setup by the Linux +# kernel ELF loader +# +# - address of an "onexit" function, not used on any +# platform supported by Bionic +# +# - address of the "main" function of the program. We +# can't hard-code it in the adr pseudo instruction +# so we use a tiny trampoline that will get relocated +# by the dynamic linker before this code runs +# +# - address of the constructor list +# +_start: + mov %esp, %eax + # before push arguments, align the stack to a 16 byte boundary + andl $~15, %esp + mov $1f, %edx + pushl %edx + mov $0f, %edx + pushl %edx + mov $0, %edx + pushl %edx + pushl %eax + call __libc_init + +0: + jmp main + +1: .long __PREINIT_ARRAY__ + .long __INIT_ARRAY__ + .long __FINI_ARRAY__ + + .section .preinit_array, "aw" + .globl __PREINIT_ARRAY__ +__PREINIT_ARRAY__: + .long -1 + + .section .init_array, "aw" + .globl __INIT_ARRAY__ +__INIT_ARRAY__: + .long -1 + .long frame_dummy + + .section .fini_array, "aw" + .globl __FINI_ARRAY__ +__FINI_ARRAY__: + .long -1 + .long __do_global_dtors_aux + + .section .eh_frame,"a",@progbits + .align 4 + .type __EH_FRAME_BEGIN__, @object +__EH_FRAME_BEGIN__: + .text + .p2align 4,,15 + .type __do_global_dtors_aux, @function +__do_global_dtors_aux: + pushl %ebp + movl %esp, %ebp + subl $24, %esp + cmpb $0, completed.4454 + jne .L4 + movl $__deregister_frame_info_bases, %eax + testl %eax, %eax + je .L3 + movl $__EH_FRAME_BEGIN__, (%esp) + call __deregister_frame_info_bases +.L3: + movb $1, completed.4454 +.L4: + leave + ret + .text + .p2align 4,,15 + .type frame_dummy, @function +frame_dummy: + pushl %ebp + movl $__register_frame_info_bases, %eax + movl %esp, %ebp + subl $24, %esp + testl %eax, %eax + je .L7 + movl %ebx, 12(%esp) + movl $0, 8(%esp) + movl $object.4466, 4(%esp) + movl $__EH_FRAME_BEGIN__, (%esp) + call __register_frame_info_bases +.L7: + leave + ret + .local completed.4454 + .comm completed.4454,1,1 + .local object.4466 + .comm object.4466,24,4 + .weak __register_frame_info_bases + .weak __deregister_frame_info_bases + +#include "__dso_handle.S" +#include "atexit.S" +#include "__stack_chk_fail_local.S" diff --git a/ndk/platforms/android-9/arch-x86/src/crtbegin_so.S b/ndk/platforms/android-9/arch-x86/src/crtbegin_so.S new file mode 100644 index 000000000..99662fe16 --- /dev/null +++ b/ndk/platforms/android-9/arch-x86/src/crtbegin_so.S @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +.section .init_array, "aw" +.align 4 +.type __INIT_ARRAY__, @object +.globl __INIT_ARRAY__ +__INIT_ARRAY__: + .long -1 + .long frame_dummy + +.section .fini_array, "aw" +.align 4 +.type __FINI_ARRAY__, @object +.globl __FINI_ARRAY__ +__FINI_ARRAY__: + .long -1 + .long __do_global_dtors_aux + + .section .eh_frame,"a",@progbits + .align 4 + .type __EH_FRAME_BEGIN__, @object +__EH_FRAME_BEGIN__: + .text + .p2align 4,,15 + .type __do_global_dtors_aux, @function +__do_global_dtors_aux: + pushl %ebp + movl %esp, %ebp + pushl %ebx + call __x86.get_pc_thunk.bx + addl $_GLOBAL_OFFSET_TABLE_, %ebx + subl $20, %esp + cmpb $0, completed.4454@GOTOFF(%ebx) + jne .L5 + movl __dso_handle@GOTOFF(%ebx), %eax + movl %eax, (%esp) + call __cxa_finalize@PLT + movl __deregister_frame_info_bases@GOT(%ebx), %eax + testl %eax, %eax + je .L4 + leal __EH_FRAME_BEGIN__@GOTOFF(%ebx), %eax + movl %eax, (%esp) + call __deregister_frame_info_bases@PLT +.L4: + movb $1, completed.4454@GOTOFF(%ebx) +.L5: + addl $20, %esp + popl %ebx + popl %ebp + ret + .text + .p2align 4,,15 + .type frame_dummy, @function +frame_dummy: + pushl %ebp + movl %esp, %ebp + pushl %ebx + call __x86.get_pc_thunk.bx + addl $_GLOBAL_OFFSET_TABLE_, %ebx + subl $20, %esp + movl __register_frame_info_bases@GOT(%ebx), %eax + testl %eax, %eax + je .L8 + leal object.4469@GOTOFF(%ebx), %eax + movl %eax, 4(%esp) + leal __EH_FRAME_BEGIN__@GOTOFF(%ebx), %eax + movl %ebx, 12(%esp) + movl $0, 8(%esp) + movl %eax, (%esp) + call __register_frame_info_bases@PLT +.L8: + addl $20, %esp + popl %ebx + popl %ebp + ret + .local completed.4454 + .comm completed.4454,1,1 + .local object.4469 + .comm object.4469,24,4 + .weak __register_frame_info_bases + .weak __deregister_frame_info_bases + +#include "__dso_handle_so.S" +#include "atexit.S" +#include "__stack_chk_fail_local.S" diff --git a/ndk/platforms/android-9/arch-x86/src/crtbegin_static.S b/ndk/platforms/android-9/arch-x86/src/crtbegin_static.S new file mode 100644 index 000000000..4f95b1e40 --- /dev/null +++ b/ndk/platforms/android-9/arch-x86/src/crtbegin_static.S @@ -0,0 +1,139 @@ +# bionic/arch-x86/bionic/crtbegin_static.S +# +# Copyright 2006, The Android Open Source Project +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of Google Inc. nor the names of its contributors may +# be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + .text + .align 4 + .type _start, @function + .globl _start + +# this is the small startup code that is first run when +# any executable that is statically-linked with Bionic +# runs. +# +# it's purpose is to call __libc_init with appropriate +# arguments, which are: +# +# - the address of the raw data block setup by the Linux +# kernel ELF loader +# +# - address of an "onexit" function, not used on any +# platform supported by Bionic +# +# - address of the "main" function of the program. We +# can't hard-code it in the adr pseudo instruction +# so we use a tiny trampoline that will get relocated +# by the dynamic linker before this code runs +# +# - address of the constructor list +# +_start: + mov %esp, %eax + # before push arguments, align the stack to a 16 byte boundary + andl $~15, %esp + mov $1f, %edx + pushl %edx + mov $0f, %edx + pushl %edx + mov $0, %edx + pushl %edx + pushl %eax + call __libc_init + +0: jmp main + +1: .long __PREINIT_ARRAY__ + .long __INIT_ARRAY__ + .long __FINI_ARRAY__ + + .section .preinit_array, "aw" + .globl __PREINIT_ARRAY__ +__PREINIT_ARRAY__: + .long -1 + + .section .init_array, "aw" + .globl __INIT_ARRAY__ +__INIT_ARRAY__: + .long -1 + .long frame_dummy + + .section .fini_array, "aw" + .globl __FINI_ARRAY__ +__FINI_ARRAY__: + .long -1 + .long __do_global_dtors_aux + + .section .eh_frame,"a",@progbits + .align 4 + .type __EH_FRAME_BEGIN__, @object +__EH_FRAME_BEGIN__: + .text + .p2align 4,,15 + .type __do_global_dtors_aux, @function +__do_global_dtors_aux: + pushl %ebp + movl %esp, %ebp + subl $24, %esp + cmpb $0, completed.4454 + jne .L4 + movl $__deregister_frame_info_bases, %eax + testl %eax, %eax + je .L3 + movl $__EH_FRAME_BEGIN__, (%esp) + call __deregister_frame_info_bases +.L3: + movb $1, completed.4454 +.L4: + leave + ret + .text + .p2align 4,,15 + .type frame_dummy, @function +frame_dummy: + pushl %ebp + movl $__register_frame_info_bases, %eax + movl %esp, %ebp + subl $24, %esp + testl %eax, %eax + je .L7 + movl %ebx, 12(%esp) + movl $0, 8(%esp) + movl $object.4466, 4(%esp) + movl $__EH_FRAME_BEGIN__, (%esp) + call __register_frame_info_bases +.L7: + leave + ret + .local completed.4454 + .comm completed.4454,1,1 + .local object.4466 + .comm object.4466,24,4 + .weak __register_frame_info_bases + .weak __deregister_frame_info_bases + +#include "__dso_handle.S" +#include "__stack_chk_fail_local.S" +/* NOTE: atexit() is not be provided by crtbegin_static.S, but by libc.a */ + diff --git a/ndk/platforms/android-9/arch-x86/src/crtend.S b/ndk/platforms/android-9/arch-x86/src/crtend.S new file mode 100644 index 000000000..68447e7db --- /dev/null +++ b/ndk/platforms/android-9/arch-x86/src/crtend.S @@ -0,0 +1,15 @@ + .section .preinit_array, "aw" + .long 0 + + .section .init_array, "aw" + .long 0 + + .section .fini_array, "aw" + .long 0 + + .section .eh_frame,"a",@progbits + .align 4 + .type __FRAME_END__, @object + .size __FRAME_END__, 4 +__FRAME_END__: + .zero 4 diff --git a/ndk/platforms/android-9/arch-x86/src/crtend_so.S b/ndk/platforms/android-9/arch-x86/src/crtend_so.S new file mode 100644 index 000000000..63e58b970 --- /dev/null +++ b/ndk/platforms/android-9/arch-x86/src/crtend_so.S @@ -0,0 +1,12 @@ +.section .init_array, "aw" + .long 0 + +.section .fini_array, "aw" + .long 0 + + .section .eh_frame,"a",@progbits + .align 4 + .type __FRAME_END__, @object + .size __FRAME_END__, 4 +__FRAME_END__: + .zero 4