• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
28 
29 /* This file contains dummy references to libgcc.a functions to force the
30  * dynamic linker to copy their definition into the final libc.so binary.
31  *
32  * They are required to ensure backwards binary compatibility with
33  * Android 1.5, 1.6 and even 3.0  system images. Some applications built
34  * using the NDK require them to be here.
35  *
36  * Now, for a more elaborate description of the issue:
37  *
38  * libgcc.a is a compiler-specific library containing various helper
39  * functions used to implement certain operations that are not necessarily
40  * supported by the target CPU. For example, integer division doesn't have a
41  * corresponding CPU instruction on ARMv5, and is instead implemented in the
42  * compiler-generated machine code as a call to an __idiv helper function.
43  *
44  * Normally, one has to place libgcc.a in the link command used to generate
45  * target binaries (shared libraries and executables) after all objects and
46  * static libraries, but before dependent shared libraries, i.e. something
47  * like:
48  *         gcc <options> -o libfoo.so  foo.a libgcc.a -lc -lm
49  *
50  * This ensures that any helper function needed by the code in foo.a is copied
51  * into the final libfoo.so. Unfortunately, the Android build system has been
52  * using this instead:
53  *
54  *         gcc <options> -o libfoo.so foo.a -lc -lm libgcc.a
55  *
56  * The problem with this is that if one helper function needed by foo.a has
57  * already been copied into libc.so or libm.so, then nothing will be copied
58  * into libfoo.so. Instead, a symbol import definition will be added to it
59  * so libfoo.so can directly call the one in libc.so at runtime.
60  *
61  * When changing toolchains for 2.0, the set of helper functions copied to
62  * libc.so changed, which resulted in some native shared libraries generated
63  * with the NDK to fail to load properly.
64  *
65  * The NDK has been fixed after 1.6_r1 to use the correct link command, so
66  * any native shared library generated with it should now be safe from that
67  * problem. On the other hand, existing shared libraries distributed with
68  * applications that were generated with a previous version of the NDK
69  * still need all 1.5/1.6 helper functions in libc.so and libn.so
70  *
71  * After 3.2, the toolchain was updated again, adding __aeabi_f2uiz to the
72  * list of requirements. Technically, this is due to mis-linked NDK libraries
73  * but it is easier to add a single function here than asking several app
74  * developers to fix their build.
75  *
76  * Final note: some of the functions below should really be in libm.so to
77  *             completely reflect the state of 1.5/1.6 system images. However,
78  *             since libm.so depends on libc.so, it's easier to put all of
79  *             these in libc.so instead, since the dynamic linker will always
80  *             search in libc.so before libm.so for dependencies.
81  */
82 
83 #define   COMPAT_FUNCTIONS_LIST \
84     XX(__adddf3)             \
85     XX(__addsf3)             \
86     XX(__aeabi_cdcmpeq)      \
87     XX(__aeabi_cdcmple)      \
88     XX(__aeabi_cdrcmple)     \
89     XX(__aeabi_d2f)          \
90     XX(__aeabi_d2iz)         \
91     XX(__aeabi_dadd)         \
92     XX(__aeabi_dcmpeq)       \
93     XX(__aeabi_dcmpge)       \
94     XX(__aeabi_dcmpgt)       \
95     XX(__aeabi_dcmple)       \
96     XX(__aeabi_dcmplt)       \
97     XX(__aeabi_dcmpun)       \
98     XX(__aeabi_ddiv)         \
99     XX(__aeabi_dmul)         \
100     XX(__aeabi_drsub)        \
101     XX(__aeabi_dsub)         \
102     XX(__aeabi_f2d)          \
103     XX(__aeabi_f2iz)         \
104     XX(__aeabi_f2uiz)        \
105     XX(__aeabi_fadd)         \
106     XX(__aeabi_fcmpun)       \
107     XX(__aeabi_fdiv)         \
108     XX(__aeabi_fmul)         \
109     XX(__aeabi_frsub)        \
110     XX(__aeabi_fsub)         \
111     XX(__aeabi_i2d)          \
112     XX(__aeabi_i2f)          \
113     XX(__aeabi_l2d)          \
114     XX(__aeabi_l2f)          \
115     XX(__aeabi_lmul)         \
116     XX(__aeabi_ui2d)         \
117     XX(__aeabi_ui2f)         \
118     XX(__aeabi_ul2d)         \
119     XX(__aeabi_ul2f)         \
120     XX(__cmpdf2)             \
121     XX(__divdf3)             \
122     XX(__divsf3)             \
123     XX(__eqdf2)             \
124     XX(__extendsfdf2)        \
125     XX(__fixdfsi)            \
126     XX(__fixsfsi)            \
127     XX(__floatdidf)          \
128     XX(__floatdisf)          \
129     XX(__floatsidf)          \
130     XX(__floatsisf)          \
131     XX(__floatundidf)        \
132     XX(__floatundisf)        \
133     XX(__floatunsidf)        \
134     XX(__floatunsisf)        \
135     XX(__gedf2)              \
136     XX(__gtdf2)              \
137     XX(__ledf2)              \
138     XX(__ltdf2)              \
139     XX(__muldf3)             \
140     XX(__muldi3)             \
141     XX(__mulsf3)             \
142     XX(__nedf2)              \
143     XX(__subdf3)             \
144     XX(__subsf3)             \
145     XX(__truncdfsf2)         \
146     XX(__unorddf2)           \
147     XX(__unordsf2)           \
148 
149 #define  XX(f)    extern void f(void);
150 COMPAT_FUNCTIONS_LIST
151 #undef XX
152 
__bionic_libgcc_compat_hooks(void)153 void  __bionic_libgcc_compat_hooks(void)
154 {
155 #define XX(f)    f();
156 COMPAT_FUNCTIONS_LIST
157 #undef XX
158 }
159