diff options
Diffstat (limited to 'libc/arch-x86/bionic')
-rw-r--r-- | libc/arch-x86/bionic/__stack_chk_fail_local.S | 48 | ||||
-rw-r--r-- | libc/arch-x86/bionic/atexit.S | 66 | ||||
-rw-r--r-- | libc/arch-x86/bionic/atomics_x86.S | 97 | ||||
-rw-r--r-- | libc/arch-x86/bionic/clone.S | 5 | ||||
-rw-r--r-- | libc/arch-x86/bionic/crtbegin_dynamic.S | 64 | ||||
-rw-r--r-- | libc/arch-x86/bionic/crtbegin_so.S | 118 | ||||
-rw-r--r-- | libc/arch-x86/bionic/crtbegin_static.S | 56 | ||||
-rw-r--r-- | libc/arch-x86/bionic/crtend.S | 10 | ||||
-rw-r--r-- | libc/arch-x86/bionic/crtend_so.S | 49 |
9 files changed, 327 insertions, 186 deletions
diff --git a/libc/arch-x86/bionic/__stack_chk_fail_local.S b/libc/arch-x86/bionic/__stack_chk_fail_local.S new file mode 100644 index 000000000..59fe86ec3 --- /dev/null +++ b/libc/arch-x86/bionic/__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/libc/arch-x86/bionic/atexit.S b/libc/arch-x86/bionic/atexit.S new file mode 100644 index 000000000..b28f40bb6 --- /dev/null +++ b/libc/arch-x86/bionic/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/libc/arch-x86/bionic/atomics_x86.S b/libc/arch-x86/bionic/atomics_x86.S index 666e1821c..e98a391ee 100644 --- a/libc/arch-x86/bionic/atomics_x86.S +++ b/libc/arch-x86/bionic/atomics_x86.S @@ -73,100 +73,3 @@ __futex_syscall4: popl %esi popl %ebx ret - -/* int __atomic_cmpxchg(int old, int new, volatile int* addr) */ - -.text -.globl __atomic_cmpxchg -.type __atomic_cmpxchg, @function -.align 4 -__atomic_cmpxchg: - mov 4(%esp), %eax /* old */ - mov 8(%esp), %ecx /* new */ - mov 12(%esp), %edx /* addr */ - lock cmpxchg %ecx, (%edx) - jnz 1f - xor %eax, %eax - jmp 2f -1: - movl $1, %eax -2: - ret /* 0 == success, 1 == failure */ - - -/* int __atomic_swap(int new, volatile int* addr) */ - -.text -.globl __atomic_swap -.type __atomic_swap, @function -.align 4 -__atomic_swap: - mov 4(%esp), %ecx /* new */ - mov 8(%esp), %edx /* addr */ - lock xchg %ecx, (%edx) - mov %ecx, %eax - ret - - -/* - * int __atomic_dec(volatile int* addr) - * - * My x86 asm is really rusty.. this is probably suboptimal - */ - -.text -.globl __atomic_dec -.type __atomic_dec, @function -.align 4 -__atomic_dec: - pushl %ebx - pushl %esi - movl 12(%esp), %ebx /* addr */ - -1: - movl (%ebx), %esi /* old = *addr */ - movl %esi, %edx - subl $1, %edx /* new = old - 1 */ - - pushl %ebx - pushl %edx - pushl %esi - call __atomic_cmpxchg - addl $12, %esp - test %eax, %eax - jnz 1b - - movl %esi, %eax /* return old */ - popl %esi - popl %ebx - ret - - -.text -/* int __atomic_inc(volatile int* addr) */ -.globl __atomic_inc -.type __atomic_inc, @function -.align 4 -__atomic_inc: - pushl %ebx - pushl %esi - movl 12(%esp), %ebx /* addr */ - -1: - movl (%ebx), %esi /* old = *addr */ - movl %esi, %edx - addl $1, %edx /* new = old + 1 */ - - pushl %ebx - pushl %edx - pushl %esi - call __atomic_cmpxchg - addl $12, %esp - test %eax, %eax - jnz 1b - - movl %esi, %eax /* return old */ - popl %esi - popl %ebx - ret - diff --git a/libc/arch-x86/bionic/clone.S b/libc/arch-x86/bionic/clone.S index 3b50cc3d3..b9b0957f6 100644 --- a/libc/arch-x86/bionic/clone.S +++ b/libc/arch-x86/bionic/clone.S @@ -20,8 +20,7 @@ __pthread_clone: movl %eax, -12(%ecx) movl 24(%esp), %eax movl %eax, -8(%ecx) - lea (%ecx), %eax - movl %eax, -4(%ecx) + movl %ecx, -4(%ecx) movl $__NR_clone, %eax int $0x80 @@ -52,4 +51,4 @@ __pthread_clone: /* XXX: TODO: Add __bionic_clone here * See bionic/bionic_clone.c and arch-arm/bionic/clone.S * for more details... - */
\ No newline at end of file + */ diff --git a/libc/arch-x86/bionic/crtbegin_dynamic.S b/libc/arch-x86/bionic/crtbegin_dynamic.S index 88e7e6a0a..9ba0d2f6c 100644 --- a/libc/arch-x86/bionic/crtbegin_dynamic.S +++ b/libc/arch-x86/bionic/crtbegin_dynamic.S @@ -66,14 +66,7 @@ _start: 1: .long __PREINIT_ARRAY__ .long __INIT_ARRAY__ .long __FINI_ARRAY__ - .long __CTOR_LIST__ - -# the .ctors section contains a list of pointers to "constructor" -# functions that need to be called in order during C library initialization, -# just before the program is being run. This is a C++ requirement -# -# the last entry shall be 0, and is defined in crtend.S -# + .section .preinit_array, "aw" .globl __PREINIT_ARRAY__ __PREINIT_ARRAY__: @@ -83,15 +76,62 @@ __PREINIT_ARRAY__: .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 .ctors, "aw" - .globl __CTOR_LIST__ -__CTOR_LIST__: - .long -1 + .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/libc/arch-x86/bionic/crtbegin_so.S b/libc/arch-x86/bionic/crtbegin_so.S index d879feff0..99662fe16 100644 --- a/libc/arch-x86/bionic/crtbegin_so.S +++ b/libc/arch-x86/bionic/crtbegin_so.S @@ -1,18 +1,30 @@ -# This function is to be called when the shared library -# is unloaded through dlclose() -_on_dlclose: - lea __dso_handle, %eax - call __cxa_finalize - ret - -/* we put the _init() function here in case the user files for the shared - * libs want to drop things into .init section. - * We then will call our ctors from crtend_so.o */ -.section .init -.align 4 -.type _init, @function -.globl _init -_init: +/* + * 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 @@ -20,6 +32,7 @@ _init: .globl __INIT_ARRAY__ __INIT_ARRAY__: .long -1 + .long frame_dummy .section .fini_array, "aw" .align 4 @@ -27,13 +40,72 @@ __INIT_ARRAY__: .globl __FINI_ARRAY__ __FINI_ARRAY__: .long -1 - .long _on_dlclose + .long __do_global_dtors_aux -.section .ctors, "aw" -.align 4 -.type __CTOR_LIST__, @object -.globl __CTOR_LIST__ -__CTOR_LIST__: - .long -1 + .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.S" +#include "__dso_handle_so.S" +#include "atexit.S" +#include "__stack_chk_fail_local.S" diff --git a/libc/arch-x86/bionic/crtbegin_static.S b/libc/arch-x86/bionic/crtbegin_static.S index 3f8446ec7..8e7033017 100644 --- a/libc/arch-x86/bionic/crtbegin_static.S +++ b/libc/arch-x86/bionic/crtbegin_static.S @@ -65,7 +65,6 @@ _start: 1: .long __PREINIT_ARRAY__ .long __INIT_ARRAY__ .long __FINI_ARRAY__ - .long __CTOR_LIST__ .section .preinit_array, "aw" .globl __PREINIT_ARRAY__ @@ -76,15 +75,62 @@ __PREINIT_ARRAY__: .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 .ctors, "aw" - .globl __CTOR_LIST__ -__CTOR_LIST__: - .long -1 + .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/libc/arch-x86/bionic/crtend.S b/libc/arch-x86/bionic/crtend.S index 7f5fb6660..68447e7db 100644 --- a/libc/arch-x86/bionic/crtend.S +++ b/libc/arch-x86/bionic/crtend.S @@ -1,4 +1,3 @@ - .section .preinit_array, "aw" .long 0 @@ -8,6 +7,9 @@ .section .fini_array, "aw" .long 0 - .section .ctors, "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/libc/arch-x86/bionic/crtend_so.S b/libc/arch-x86/bionic/crtend_so.S index 7fb228083..63e58b970 100644 --- a/libc/arch-x86/bionic/crtend_so.S +++ b/libc/arch-x86/bionic/crtend_so.S @@ -1,47 +1,12 @@ -.text -.align 4 -.type __bionic_call_ctors, @function - -/* - * The CTORS_LIST is marked by -1 (start) and 0 (end). - * We mark the end of the .ctors section with the __CTOR_END__ section so - * that we can just iterate backwards from it until we hit -1 and execute - * all the function pointers. This seems to be the way to do it for SVR4 - * derived systems. - */ -__bionic_call_ctors: - pushl %esi - mov $__CTOR_END__, %esi - -0: - /* now grab the next function pointer and check if its -1. If not, - * call it, otherwise we're done. We use %esi since it's callee saved. - */ - subl $4, %esi - mov (%esi), %eax - cmp $0xffffffff, %eax - je 1f - call *%eax - jmp 0b - -1: - /* we're done */ - popl %esi - ret - -.section .init -.align 4 - call __bionic_call_ctors - ret - -.section .ctors, "aw", @progbits -.align 4 -.type __CTOR_END__, @object -__CTOR_END__: - .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 |