1 LOCAL_PATH:= $(call my-dir)
3 include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/syscalls.mk
5 # Define the common source files for all the libc instances
6 # =========================================================
7 libc_common_src_files := \
8 $(syscall_src) \
9 unistd/abort.c \
10 unistd/alarm.c \
11 unistd/brk.c \
12 unistd/creat.c \
13 unistd/daemon.c \
14 unistd/exec.c \
15 unistd/fcntl.c \
16 unistd/fnmatch.c \
17 unistd/ftime.c \
18 unistd/ftok.c \
19 unistd/getcwd.c \
20 unistd/getdtablesize.c \
21 unistd/gethostname.c \
22 unistd/getopt_long.c \
23 unistd/getpgrp.c \
24 unistd/getpriority.c \
25 unistd/getpt.c \
26 unistd/initgroups.c \
27 unistd/isatty.c \
28 unistd/issetugid.c \
29 unistd/killpg.c \
30 unistd/lseek64.c \
31 unistd/mmap.c \
32 unistd/nice.c \
33 unistd/open.c \
34 unistd/openat.c \
35 unistd/opendir.c \
36 unistd/pathconf.c \
37 unistd/perror.c \
38 unistd/popen.c \
39 unistd/pread.c \
40 unistd/pselect.c \
41 unistd/ptsname.c \
42 unistd/ptsname_r.c \
43 unistd/pwrite.c \
44 unistd/raise.c \
45 unistd/reboot.c \
46 unistd/recv.c \
47 unistd/sbrk.c \
48 unistd/send.c \
49 unistd/setegid.c \
50 unistd/seteuid.c \
51 unistd/setpgrp.c \
52 unistd/sigblock.c \
53 unistd/siginterrupt.c \
54 unistd/siglist.c \
55 unistd/signal.c \
56 unistd/signame.c \
57 unistd/sigsetmask.c \
58 unistd/sigsuspend.c \
59 unistd/sigwait.c \
60 unistd/sleep.c \
61 unistd/statfs.c \
62 unistd/strsignal.c \
63 unistd/sysconf.c \
64 unistd/syslog.c \
65 unistd/system.c \
66 unistd/tcgetpgrp.c \
67 unistd/tcsetpgrp.c \
68 unistd/time.c \
69 unistd/umount.c \
70 unistd/unlockpt.c \
71 unistd/usleep.c \
72 unistd/wait.c \
73 stdio/asprintf.c \
74 stdio/clrerr.c \
75 stdio/fclose.c \
76 stdio/fdopen.c \
77 stdio/feof.c \
78 stdio/ferror.c \
79 stdio/fflush.c \
80 stdio/fgetc.c \
81 stdio/fgetln.c \
82 stdio/fgetpos.c \
83 stdio/fgets.c \
84 stdio/fileno.c \
85 stdio/findfp.c \
86 stdio/flags.c \
87 stdio/flockfile.c \
88 stdio/fopen.c \
89 stdio/fprintf.c \
90 stdio/fpurge.c \
91 stdio/fputc.c \
92 stdio/fputs.c \
93 stdio/fread.c \
94 stdio/freopen.c \
95 stdio/fscanf.c \
96 stdio/fseek.c \
97 stdio/fsetpos.c \
98 stdio/ftell.c \
99 stdio/funopen.c \
100 stdio/fvwrite.c \
101 stdio/fwalk.c \
102 stdio/fwrite.c \
103 stdio/getc.c \
104 stdio/getchar.c \
105 stdio/gets.c \
106 stdio/makebuf.c \
107 stdio/mktemp.c \
108 stdio/printf.c \
109 stdio/putc.c \
110 stdio/putchar.c \
111 stdio/puts.c \
112 stdio/putw.c \
113 stdio/refill.c \
114 stdio/remove.c \
115 stdio/rewind.c \
116 stdio/rget.c \
117 stdio/scanf.c \
118 stdio/setbuf.c \
119 stdio/setbuffer.c \
120 stdio/setvbuf.c \
121 stdio/snprintf.c\
122 stdio/sprintf.c \
123 stdio/sscanf.c \
124 stdio/stdio.c \
125 stdio/tempnam.c \
126 stdio/tmpfile.c \
127 stdio/tmpnam.c \
128 stdio/ungetc.c \
129 stdio/vasprintf.c \
130 stdio/vfprintf.c \
131 stdio/vfscanf.c \
132 stdio/vprintf.c \
133 stdio/vsnprintf.c \
134 stdio/vsprintf.c \
135 stdio/vscanf.c \
136 stdio/vsscanf.c \
137 stdio/wbuf.c \
138 stdio/wsetup.c \
139 stdlib/_rand48.c \
140 stdlib/assert.c \
141 stdlib/atexit.c \
142 stdlib/atoi.c \
143 stdlib/atol.c \
144 stdlib/atoll.c \
145 stdlib/bsearch.c \
146 stdlib/ctype_.c \
147 stdlib/div.c \
148 stdlib/exit.c \
149 stdlib/getenv.c \
150 stdlib/jrand48.c \
151 stdlib/ldiv.c \
152 stdlib/lldiv.c \
153 stdlib/locale.c \
154 stdlib/lrand48.c \
155 stdlib/mrand48.c \
156 stdlib/nrand48.c \
157 stdlib/putenv.c \
158 stdlib/qsort.c \
159 stdlib/seed48.c \
160 stdlib/setenv.c \
161 stdlib/setjmperr.c \
162 stdlib/srand48.c \
163 stdlib/strntoimax.c \
164 stdlib/strntoumax.c \
165 stdlib/strtod.c \
166 stdlib/strtoimax.c \
167 stdlib/strtol.c \
168 stdlib/strtoll.c \
169 stdlib/strtoul.c \
170 stdlib/strtoull.c \
171 stdlib/strtoumax.c \
172 stdlib/tolower_.c \
173 stdlib/toupper_.c \
174 stdlib/wchar.c \
175 string/bcopy.c \
176 string/index.c \
177 string/memccpy.c \
178 string/memchr.c \
179 string/memmem.c \
180 string/memrchr.c \
181 string/memswap.c \
182 string/strcasecmp.c \
183 string/strcasestr.c \
184 string/strcat.c \
185 string/strchr.c \
186 string/strcmp.c \
187 string/strcoll.c \
188 string/strcpy.c \
189 string/strcspn.c \
190 string/strdup.c \
191 string/strerror.c \
192 string/strerror_r.c \
193 string/strlcat.c \
194 string/strlcpy.c \
195 string/strncat.c \
196 string/strncmp.c \
197 string/strncpy.c \
198 string/strndup.c \
199 string/strnlen.c \
200 string/strpbrk.c \
201 string/strrchr.c \
202 string/strsep.c \
203 string/strspn.c \
204 string/strstr.c \
205 string/strtok.c \
206 string/strtotimeval.c \
207 string/strxfrm.c \
208 inet/bindresvport.c \
209 inet/inet_addr.c \
210 inet/inet_aton.c \
211 inet/inet_ntoa.c \
212 inet/inet_ntop.c \
213 inet/inet_pton.c \
214 tzcode/asctime.c \
215 tzcode/difftime.c \
216 tzcode/localtime.c \
217 tzcode/strftime.c \
218 tzcode/strptime.c \
219 bionic/__errno.c \
220 bionic/__set_errno.c \
221 bionic/_rand48.c \
222 bionic/arc4random.c \
223 bionic/basename.c \
224 bionic/basename_r.c \
225 bionic/clearenv.c \
226 bionic/dirname.c \
227 bionic/dirname_r.c \
228 bionic/drand48.c \
229 bionic/erand48.c \
230 bionic/err.c \
231 bionic/fdprintf.c \
232 bionic/fork.c \
233 bionic/fts.c \
234 bionic/if_nametoindex.c \
235 bionic/if_indextoname.c \
236 bionic/ioctl.c \
237 bionic/ldexp.c \
238 bionic/libc_init_common.c \
239 bionic/logd_write.c \
240 bionic/md5.c \
241 bionic/pututline.c \
242 bionic/realpath.c \
243 bionic/semaphore.c \
244 bionic/sha1.c \
245 bionic/ssp.c \
246 bionic/stubs.c \
247 bionic/system_properties.c \
248 bionic/time64.c \
249 bionic/thread_atexit.c \
250 bionic/utime.c \
251 bionic/utmp.c \
252 netbsd/gethnamaddr.c \
253 netbsd/isc/ev_timers.c \
254 netbsd/isc/ev_streams.c \
255 netbsd/inet/nsap_addr.c \
256 netbsd/resolv/__dn_comp.c \
257 netbsd/resolv/__res_close.c \
258 netbsd/resolv/__res_send.c \
259 netbsd/resolv/herror.c \
260 netbsd/resolv/res_comp.c \
261 netbsd/resolv/res_data.c \
262 netbsd/resolv/res_debug.c \
263 netbsd/resolv/res_init.c \
264 netbsd/resolv/res_mkquery.c \
265 netbsd/resolv/res_query.c \
266 netbsd/resolv/res_send.c \
267 netbsd/resolv/res_state.c \
268 netbsd/resolv/res_cache.c \
269 netbsd/net/nsdispatch.c \
270 netbsd/net/getaddrinfo.c \
271 netbsd/net/getnameinfo.c \
272 netbsd/net/getservbyname.c \
273 netbsd/net/getservent.c \
274 netbsd/net/base64.c \
275 netbsd/net/getservbyport.c \
276 netbsd/nameser/ns_name.c \
277 netbsd/nameser/ns_parse.c \
278 netbsd/nameser/ns_ttl.c \
279 netbsd/nameser/ns_netint.c \
280 netbsd/nameser/ns_print.c \
281 netbsd/nameser/ns_samedomain.c \
282 regex/regcomp.c \
283 regex/regerror.c \
284 regex/regexec.c \
285 regex/regfree.c \
287 # Architecture specific source files go here
288 # =========================================================
289 ifeq ($(TARGET_ARCH),arm)
290 libc_common_src_files += \
291 bionic/eabi.c \
292 bionic/bionic_clone.c \
293 arch-arm/bionic/__get_pc.S \
294 arch-arm/bionic/__get_sp.S \
295 arch-arm/bionic/_exit_with_stack_teardown.S \
296 arch-arm/bionic/_setjmp.S \
297 arch-arm/bionic/atomics_arm.S \
298 arch-arm/bionic/clone.S \
299 arch-arm/bionic/ffs.S \
300 arch-arm/bionic/kill.S \
301 arch-arm/bionic/libgcc_compat.c \
302 arch-arm/bionic/tkill.S \
303 arch-arm/bionic/memcmp.S \
304 arch-arm/bionic/memcmp16.S \
305 arch-arm/bionic/memcpy.S \
306 arch-arm/bionic/memset.S \
307 arch-arm/bionic/setjmp.S \
308 arch-arm/bionic/sigsetjmp.S \
309 arch-arm/bionic/strlen.c.arm \
310 arch-arm/bionic/syscall.S \
311 string/memmove.c.arm \
312 unistd/socketcalls.c
314 # These files need to be arm so that gdbserver
315 # can set breakpoints in them without messing
316 # up any thumb code.
317 libc_common_src_files += \
318 bionic/pthread.c.arm \
319 bionic/pthread-timers.c.arm \
320 bionic/ptrace.c.arm
322 # these are used by the static and dynamic versions of the libc
323 # respectively
324 libc_arch_static_src_files := \
325 arch-arm/bionic/exidx_static.c
327 libc_arch_dynamic_src_files := \
328 arch-arm/bionic/exidx_dynamic.c
329 else # !arm
331 ifeq ($(TARGET_ARCH),x86)
332 libc_common_src_files += \
333 arch-x86/bionic/__get_sp.S \
334 arch-x86/bionic/__get_tls.c \
335 arch-x86/bionic/__set_tls.c \
336 arch-x86/bionic/atomics_x86.S \
337 arch-x86/bionic/clone.S \
338 arch-x86/bionic/_exit_with_stack_teardown.S \
339 arch-x86/bionic/setjmp.S \
340 arch-x86/bionic/_setjmp.S \
341 arch-x86/bionic/vfork.S \
342 arch-x86/string/bzero.S \
343 arch-x86/string/memset.S \
344 arch-x86/string/memcmp.S \
345 arch-x86/string/memcpy.S \
346 arch-x86/string/strlen.S \
347 string/memmove.c \
348 bionic/pthread.c \
349 bionic/pthread-timers.c \
350 bionic/ptrace.c
352 # this is needed for static versions of libc
353 libc_arch_static_src_files := \
354 arch-x86/bionic/dl_iterate_phdr_static.c
356 libc_arch_dynamic_src_files :=
357 else # !x86
359 ifeq ($(TARGET_ARCH),sh)
360 libc_common_src_files += \
361 arch-sh/bionic/__get_pc.S \
362 arch-sh/bionic/__get_sp.S \
363 arch-sh/bionic/_exit_with_stack_teardown.S \
364 arch-sh/bionic/_setjmp.S \
365 arch-sh/bionic/atomics_sh.c \
366 arch-sh/bionic/atomic_cmpxchg.S \
367 arch-sh/bionic/clone.S \
368 arch-sh/bionic/pipe.S \
369 arch-sh/bionic/memcpy.S \
370 arch-sh/bionic/memset.S \
371 arch-sh/bionic/bzero.S \
372 arch-sh/bionic/setjmp.S \
373 arch-sh/bionic/sigsetjmp.S \
374 arch-sh/bionic/syscall.S \
375 arch-sh/bionic/memmove.S \
376 arch-sh/bionic/__set_tls.c \
377 arch-sh/bionic/__get_tls.c \
378 arch-sh/bionic/ffs.S \
379 string/memcmp.c \
380 string/strlen.c \
381 bionic/eabi.c \
382 bionic/pthread.c \
383 bionic/pthread-timers.c \
384 bionic/ptrace.c \
385 unistd/socketcalls.c
386 endif # sh
388 endif # !x86
389 endif # !arm
391 # Define some common cflags
392 # ========================================================
393 libc_common_cflags := \
394 -DWITH_ERRLIST \
395 -DANDROID_CHANGES \
396 -DUSE_LOCKS \
397 -DREALLOC_ZERO_BYTES_FREES \
398 -D_LIBC=1 \
399 -DSOFTFLOAT \
400 -DFLOATING_POINT \
401 -DNEED_PSELECT=1 \
402 -DINET6 \
403 -I$(LOCAL_PATH)/private \
404 -DUSE_DL_PREFIX \
405 -DPOSIX_MISTAKE
407 ifeq ($(strip $(DEBUG_BIONIC_LIBC)),true)
408 libc_common_cflags += -DDEBUG
409 endif
411 ifeq ($(TARGET_ARCH),arm)
412 libc_common_cflags += -fstrict-aliasing
413 libc_crt_target_cflags := -mthumb-interwork
414 #
415 # Define HAVE_ARM_TLS_REGISTER macro to indicate to the C library
416 # that it should access the hardware TLS register directly in
417 # private/bionic_tls.h
418 #
419 # The value must match your kernel configuration
420 #
421 ifeq ($(ARCH_ARM_HAVE_TLS_REGISTER),true)
422 libc_common_cflags += -DHAVE_ARM_TLS_REGISTER
423 endif
424 else # !arm
425 ifeq ($(TARGET_ARCH),x86)
426 libc_crt_target_cflags := -m32
427 endif # x86
428 endif # !arm
430 # Define some common includes
431 # ========================================================
432 libc_common_c_includes := \
433 $(LOCAL_PATH)/stdlib \
434 $(LOCAL_PATH)/string \
435 $(LOCAL_PATH)/stdio
438 # Define the libc run-time (crt) support object files that must be built,
439 # which are needed to build all other objects (shared/static libs and
440 # executables)
441 # ==========================================================================
443 ifeq ($(TARGET_ARCH),x86)
444 # we only need begin_so/end_so for x86, since it needs an appropriate .init
445 # section in the shared library with a function to call all the entries in
446 # .ctors section. ARM uses init_array, and does not need the function.
447 GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o
448 $(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin_so.S
449 @mkdir -p $(dir $@)
450 $(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
451 ALL_GENERATED_SOURCES += $(GEN)
453 GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_so.o
454 $(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtend_so.S
455 @mkdir -p $(dir $@)
456 $(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
457 ALL_GENERATED_SOURCES += $(GEN)
458 endif # TARGET_ARCH == x86
461 GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
462 $(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin_static.S
463 @mkdir -p $(dir $@)
464 $(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
465 ALL_GENERATED_SOURCES += $(GEN)
467 GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
468 $(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin_dynamic.S
469 @mkdir -p $(dir $@)
470 $(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
471 ALL_GENERATED_SOURCES += $(GEN)
474 # We rename crtend.o to crtend_android.o to avoid a
475 # name clash between gcc and bionic.
476 GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
477 $(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtend.S
478 @mkdir -p $(dir $@)
479 $(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
480 ALL_GENERATED_SOURCES += $(GEN)
483 # To enable malloc leak check for statically linked programs, add
484 # "WITH_MALLOC_CHECK_LIBC_A := true" to buildspec.mk
485 WITH_MALLOC_CHECK_LIBC_A := $(strip $(WITH_MALLOC_CHECK_LIBC_A))
487 # ========================================================
488 # libc_common.a
489 # ========================================================
490 include $(CLEAR_VARS)
492 LOCAL_SRC_FILES := $(libc_common_src_files)
493 LOCAL_CFLAGS := $(libc_common_cflags)
494 LOCAL_C_INCLUDES := $(libc_common_c_includes)
495 LOCAL_MODULE := libc_common
496 LOCAL_SYSTEM_SHARED_LIBRARIES :=
498 include $(BUILD_STATIC_LIBRARY)
501 # ========================================================
502 # libc_nomalloc.a
503 # ========================================================
504 #
505 # This is a version of the static C library that does not
506 # include malloc. It's useful in situations when calling
507 # the user wants to provide their own malloc implementation,
508 # or wants to explicitly disallow the use of the use of malloc,
509 # like the dynamic loader.
511 include $(CLEAR_VARS)
513 LOCAL_SRC_FILES := \
514 $(libc_arch_static_src_files) \
515 bionic/libc_init_static.c
517 LOCAL_C_INCLUDES := $(libc_common_c_includes)
518 LOCAL_CFLAGS := $(libc_common_cflags)
520 LOCAL_MODULE := libc_nomalloc
521 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
522 LOCAL_SYSTEM_SHARED_LIBRARIES :=
524 include $(BUILD_STATIC_LIBRARY)
527 # ========================================================
528 # libc.a
529 # ========================================================
530 include $(CLEAR_VARS)
532 LOCAL_SRC_FILES := \
533 $(libc_arch_static_src_files) \
534 bionic/dlmalloc.c \
535 bionic/malloc_debug_common.c \
536 bionic/libc_init_static.c
538 LOCAL_CFLAGS := $(libc_common_cflags) \
539 -DLIBC_STATIC
540 LOCAL_C_INCLUDES := $(libc_common_c_includes)
541 LOCAL_MODULE := libc
542 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
543 LOCAL_SYSTEM_SHARED_LIBRARIES :=
545 include $(BUILD_STATIC_LIBRARY)
548 # ========================================================
549 # libc.so
550 # ========================================================
551 include $(CLEAR_VARS)
553 LOCAL_CFLAGS := $(libc_common_cflags)
554 LOCAL_C_INCLUDES := $(libc_common_c_includes)
556 LOCAL_SRC_FILES := \
557 $(libc_arch_dynamic_src_files) \
558 bionic/dlmalloc.c \
559 bionic/malloc_debug_common.c \
560 bionic/libc_init_dynamic.c
562 LOCAL_MODULE:= libc
564 # WARNING: The only library libc.so should depend on is libdl.so! If you add other libraries,
565 # make sure to add -Wl,--exclude-libs=libgcc.a to the LOCAL_LDFLAGS for those libraries. This
566 # ensures that symbols that are pulled into those new libraries from libgcc.a are not declared
567 # external; if that were the case, then libc would not pull those symbols from libgcc.a as it
568 # should, instead relying on the external symbols from the dependent libraries. That would
569 # create an "cloaked" dependency on libgcc.a in libc though the libraries, which is not what
570 # you wanted!
572 LOCAL_SHARED_LIBRARIES := libdl
573 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
574 LOCAL_SYSTEM_SHARED_LIBRARIES :=
576 include $(BUILD_SHARED_LIBRARY)
579 # For all builds, except for the -user build we will enable memory
580 # allocation checking (including memory leaks, buffer overwrites, etc.)
581 # Note that all these checks are also controlled by env. settings
582 # that can enable, or disable specific checks. Note also that some of
583 # the checks are available only in emulator and are implemeted in
584 # libc_malloc_qemu_instrumented.so.
585 ifneq ($(TARGET_BUILD_VARIANT),user)
587 # ========================================================
588 # libc_malloc_debug_leak.so
589 # ========================================================
590 include $(CLEAR_VARS)
592 LOCAL_CFLAGS := \
593 $(libc_common_cflags) \
594 -DMALLOC_LEAK_CHECK
596 LOCAL_C_INCLUDES := $(libc_common_c_includes)
598 LOCAL_SRC_FILES := \
599 bionic/malloc_debug_leak.c
601 LOCAL_MODULE:= libc_malloc_debug_leak
603 LOCAL_SHARED_LIBRARIES := libc
604 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
605 LOCAL_SYSTEM_SHARED_LIBRARIES :=
606 # Don't prelink
607 LOCAL_PRELINK_MODULE := false
608 # Don't install on release build
609 LOCAL_MODULE_TAGS := eng debug
611 include $(BUILD_SHARED_LIBRARY)
614 # ========================================================
615 # libc_malloc_debug_qemu.so
616 # ========================================================
617 include $(CLEAR_VARS)
619 LOCAL_CFLAGS := \
620 $(libc_common_cflags) \
621 -DMALLOC_QEMU_INSTRUMENT
623 LOCAL_C_INCLUDES := $(libc_common_c_includes)
625 LOCAL_SRC_FILES := \
626 bionic/malloc_debug_qemu.c
628 LOCAL_MODULE:= libc_malloc_debug_qemu
630 LOCAL_SHARED_LIBRARIES := libc
631 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
632 LOCAL_SYSTEM_SHARED_LIBRARIES :=
633 # Don't prelink
634 LOCAL_PRELINK_MODULE := false
635 # Don't install on release build
636 LOCAL_MODULE_TAGS := eng debug
638 include $(BUILD_SHARED_LIBRARY)
640 endif #!user
643 # ========================================================
644 include $(call all-makefiles-under,$(LOCAL_PATH))