The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | # bionic/arch-x86/bionic/crtbegin_dynamic.S |
| 2 | # |
| 3 | # Copyright 2006, The Android Open Source Project |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are met: |
| 7 | # * Redistributions of source code must retain the above copyright |
| 8 | # notice, this list of conditions and the following disclaimer. |
| 9 | # * Redistributions in binary form must reproduce the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer in the |
| 11 | # documentation and/or other materials provided with the distribution. |
| 12 | # * Neither the name of Google Inc. nor the names of its contributors may |
| 13 | # be used to endorse or promote products derived from this software |
| 14 | # without specific prior written permission. |
| 15 | # |
| 16 | # THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR |
| 17 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | # EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | |
| 27 | .text |
| 28 | .align 4 |
| 29 | .type _start, @function |
| 30 | .globl _start |
| 31 | |
David 'Digit' Turner | 3a654b1 | 2009-06-03 19:32:37 +0200 | [diff] [blame] | 32 | # this is the small startup code that is first run when |
Nick Kralevich | 83a73d1 | 2012-05-30 11:45:12 -0700 | [diff] [blame] | 33 | # any executable that is linked with Bionic runs. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 34 | # |
David 'Digit' Turner | 3a654b1 | 2009-06-03 19:32:37 +0200 | [diff] [blame] | 35 | # it's purpose is to call __libc_init with appropriate |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 36 | # arguments, which are: |
| 37 | # |
| 38 | # - the address of the raw data block setup by the Linux |
| 39 | # kernel ELF loader |
| 40 | # |
David 'Digit' Turner | 3a654b1 | 2009-06-03 19:32:37 +0200 | [diff] [blame] | 41 | # - address of an "onexit" function, not used on any |
| 42 | # platform supported by Bionic |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 43 | # |
| 44 | # - address of the "main" function of the program. We |
| 45 | # can't hard-code it in the adr pseudo instruction |
| 46 | # so we use a tiny trampoline that will get relocated |
| 47 | # by the dynamic linker before this code runs |
| 48 | # |
David 'Digit' Turner | 3a654b1 | 2009-06-03 19:32:37 +0200 | [diff] [blame] | 49 | # - address of the constructor list |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 50 | # |
| 51 | _start: |
| 52 | mov %esp, %eax |
Jack Ren | cb08204 | 2012-03-21 17:48:13 +0800 | [diff] [blame] | 53 | # before push arguments, align the stack to a 16 byte boundary |
| 54 | andl $~15, %esp |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 55 | mov $1f, %edx |
| 56 | pushl %edx |
| 57 | mov $0f, %edx |
| 58 | pushl %edx |
| 59 | mov $0, %edx |
| 60 | pushl %edx |
| 61 | pushl %eax |
| 62 | call __libc_init |
| 63 | |
| 64 | 0: |
| 65 | jmp main |
| 66 | |
| 67 | 1: .long __PREINIT_ARRAY__ |
| 68 | .long __INIT_ARRAY__ |
| 69 | .long __FINI_ARRAY__ |
Bruce Beare | 48e1fea | 2011-01-27 10:23:16 -0800 | [diff] [blame] | 70 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 71 | .section .preinit_array, "aw" |
| 72 | .globl __PREINIT_ARRAY__ |
| 73 | __PREINIT_ARRAY__: |
| 74 | .long -1 |
| 75 | |
| 76 | .section .init_array, "aw" |
| 77 | .globl __INIT_ARRAY__ |
| 78 | __INIT_ARRAY__: |
| 79 | .long -1 |
Mark D Horn | dc3bc87 | 2011-04-26 14:05:30 -0700 | [diff] [blame] | 80 | .long frame_dummy |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 | |
| 82 | .section .fini_array, "aw" |
| 83 | .globl __FINI_ARRAY__ |
| 84 | __FINI_ARRAY__: |
| 85 | .long -1 |
Mark D Horn | dc3bc87 | 2011-04-26 14:05:30 -0700 | [diff] [blame] | 86 | .long __do_global_dtors_aux |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 87 | |
Mark D Horn | dc3bc87 | 2011-04-26 14:05:30 -0700 | [diff] [blame] | 88 | .section .eh_frame,"a",@progbits |
| 89 | .align 4 |
| 90 | .type __EH_FRAME_BEGIN__, @object |
| 91 | __EH_FRAME_BEGIN__: |
| 92 | .text |
| 93 | .p2align 4,,15 |
| 94 | .type __do_global_dtors_aux, @function |
| 95 | __do_global_dtors_aux: |
| 96 | pushl %ebp |
| 97 | movl %esp, %ebp |
| 98 | subl $24, %esp |
| 99 | cmpb $0, completed.4454 |
| 100 | jne .L4 |
| 101 | movl $__deregister_frame_info_bases, %eax |
| 102 | testl %eax, %eax |
| 103 | je .L3 |
| 104 | movl $__EH_FRAME_BEGIN__, (%esp) |
| 105 | call __deregister_frame_info_bases |
| 106 | .L3: |
| 107 | movb $1, completed.4454 |
| 108 | .L4: |
| 109 | leave |
| 110 | ret |
| 111 | .text |
| 112 | .p2align 4,,15 |
| 113 | .type frame_dummy, @function |
| 114 | frame_dummy: |
| 115 | pushl %ebp |
| 116 | movl $__register_frame_info_bases, %eax |
| 117 | movl %esp, %ebp |
| 118 | subl $24, %esp |
| 119 | testl %eax, %eax |
| 120 | je .L7 |
| 121 | movl %ebx, 12(%esp) |
| 122 | movl $0, 8(%esp) |
| 123 | movl $object.4466, 4(%esp) |
| 124 | movl $__EH_FRAME_BEGIN__, (%esp) |
| 125 | call __register_frame_info_bases |
| 126 | .L7: |
| 127 | leave |
| 128 | ret |
| 129 | .local completed.4454 |
| 130 | .comm completed.4454,1,1 |
| 131 | .local object.4466 |
| 132 | .comm object.4466,24,4 |
| 133 | .weak __register_frame_info_bases |
| 134 | .weak __deregister_frame_info_bases |
Bruce Beare | e0b4844 | 2011-05-03 21:04:40 -0700 | [diff] [blame] | 135 | |
David 'Digit' Turner | 6a9b888 | 2010-06-18 14:47:22 -0700 | [diff] [blame] | 136 | #include "__dso_handle.S" |
Bruce Beare | 3964084 | 2011-06-20 10:29:50 -0700 | [diff] [blame] | 137 | #include "atexit.S" |
Bruce Beare | e0b4844 | 2011-05-03 21:04:40 -0700 | [diff] [blame] | 138 | #include "__stack_chk_fail_local.S" |