blob: e1ff13d86828690c158756da1c254ef45bd06f41 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 */
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029/*
30 * libc_init_static.c
31 *
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020032 * This function is called for dynamic executables after the dynamic
33 * linker has loaded and initialized all dependent shared libraries.
34 *
35 * It takes the raw data block set up by the ELF loader
36 * in the kernel and parses it.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080037 *
38 * The arguments are:
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020039 * elfdata -- The ELF loader data block; usually from the stack.
40 * Basically a pointer to argc.
41 *
42 * onexit -- Function to call on exit, can be NULL.
43 *
44 * slingshot -- Address of the program's main function
45 *
46 * structors -- Table of constructor functions arrays that must
47 * be called before the slingshot.
48 *
49 * It is called from the assembly fragment found in
50 * arch-$ARCH/bionic/crtbegin_dynamic.S
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051 */
52
53/*
54 * Several Linux ABIs don't pass the onexit pointer, and the ones that
55 * do never use it. Therefore, unless USE_ONEXIT is defined, we just
56 * ignore the onexit pointer.
57 */
58/* #define USE_ONEXIT */
59
60#include <stddef.h>
61#include <stdio.h>
62#include <stdlib.h>
63#include <stdint.h>
64#include <elf.h>
65#include "pthread_internal.h"
66#include "atexit.h"
67#include "libc_init_common.h"
68
69extern void malloc_debug_init();
70
71__noreturn void __libc_init(uintptr_t *elfdata,
72 void (*onexit)(void),
73 int (*slingshot)(int, char**, char**),
74 structors_array_t const * const structors)
75{
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020076 /* NOTE: At this point, the dynamic linker has *already* called
77 * all initializers properly, so we ignore 'structors' to
78 * avoid calling them twice.
79 */
80
81 /* NOTE2: Is it worthwhile to use malloc_debug_init() in the case of
82 * of the non-debug shared C library ?
83 *
84 * The implementation in bionic/malloc_leak.c contains a lot
85 * of code which will turn to be unused, and we add a dispatch
86 * overhead to malloc() et al. that proved to be significant
87 * in the past (e.g. making boot sequence 5% slower)
88 */
89 __libc_init_common(elfdata, onexit, slingshot, NULL, malloc_debug_init);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080090}