blob: 177244b70fc028f2e7cd9d1932b55f7ae79b8146 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001# 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' Turner3a654b12009-06-03 19:32:37 +020032# this is the small startup code that is first run when
David 'Digit' Turner6a9b8882010-06-18 14:47:22 -070033# any executable that is dynamically-linked with Bionic
David 'Digit' Turner3a654b12009-06-03 19:32:37 +020034# runs.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035#
David 'Digit' Turner3a654b12009-06-03 19:32:37 +020036# it's purpose is to call __libc_init with appropriate
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080037# arguments, which are:
38#
39# - the address of the raw data block setup by the Linux
40# kernel ELF loader
41#
David 'Digit' Turner3a654b12009-06-03 19:32:37 +020042# - address of an "onexit" function, not used on any
43# platform supported by Bionic
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044#
45# - address of the "main" function of the program. We
46# can't hard-code it in the adr pseudo instruction
47# so we use a tiny trampoline that will get relocated
48# by the dynamic linker before this code runs
49#
David 'Digit' Turner3a654b12009-06-03 19:32:37 +020050# - address of the constructor list
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051#
52_start:
53 mov %esp, %eax
Jack Rencb082042012-03-21 17:48:13 +080054 # before push arguments, align the stack to a 16 byte boundary
55 andl $~15, %esp
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080056 mov $1f, %edx
57 pushl %edx
58 mov $0f, %edx
59 pushl %edx
60 mov $0, %edx
61 pushl %edx
62 pushl %eax
63 call __libc_init
64
650:
66 jmp main
67
681: .long __PREINIT_ARRAY__
69 .long __INIT_ARRAY__
70 .long __FINI_ARRAY__
Bruce Beare48e1fea2011-01-27 10:23:16 -080071
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080072 .section .preinit_array, "aw"
73 .globl __PREINIT_ARRAY__
74__PREINIT_ARRAY__:
75 .long -1
76
77 .section .init_array, "aw"
78 .globl __INIT_ARRAY__
79__INIT_ARRAY__:
80 .long -1
Mark D Horndc3bc872011-04-26 14:05:30 -070081 .long frame_dummy
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080082
83 .section .fini_array, "aw"
84 .globl __FINI_ARRAY__
85__FINI_ARRAY__:
86 .long -1
Mark D Horndc3bc872011-04-26 14:05:30 -070087 .long __do_global_dtors_aux
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080088
Mark D Horndc3bc872011-04-26 14:05:30 -070089 .section .eh_frame,"a",@progbits
90 .align 4
91 .type __EH_FRAME_BEGIN__, @object
92__EH_FRAME_BEGIN__:
93 .text
94 .p2align 4,,15
95 .type __do_global_dtors_aux, @function
96__do_global_dtors_aux:
97 pushl %ebp
98 movl %esp, %ebp
99 subl $24, %esp
100 cmpb $0, completed.4454
101 jne .L4
102 movl $__deregister_frame_info_bases, %eax
103 testl %eax, %eax
104 je .L3
105 movl $__EH_FRAME_BEGIN__, (%esp)
106 call __deregister_frame_info_bases
107.L3:
108 movb $1, completed.4454
109.L4:
110 leave
111 ret
112 .text
113 .p2align 4,,15
114 .type frame_dummy, @function
115frame_dummy:
116 pushl %ebp
117 movl $__register_frame_info_bases, %eax
118 movl %esp, %ebp
119 subl $24, %esp
120 testl %eax, %eax
121 je .L7
122 movl %ebx, 12(%esp)
123 movl $0, 8(%esp)
124 movl $object.4466, 4(%esp)
125 movl $__EH_FRAME_BEGIN__, (%esp)
126 call __register_frame_info_bases
127.L7:
128 leave
129 ret
130 .local completed.4454
131 .comm completed.4454,1,1
132 .local object.4466
133 .comm object.4466,24,4
134 .weak __register_frame_info_bases
135 .weak __deregister_frame_info_bases
Bruce Bearee0b48442011-05-03 21:04:40 -0700136
David 'Digit' Turner6a9b8882010-06-18 14:47:22 -0700137#include "__dso_handle.S"
Bruce Beare39640842011-06-20 10:29:50 -0700138#include "atexit.S"
Bruce Bearee0b48442011-05-03 21:04:40 -0700139#include "__stack_chk_fail_local.S"