1// Define the common source files for all the libc instances
2// =========================================================
3package {
4    default_applicable_licenses: ["bionic_libc_license"],
5}
6
7license {
8    name: "bionic_libc_license",
9    visibility: [":__subpackages__"],
10    license_kinds: [
11        "SPDX-license-identifier-Apache-2.0",
12        "SPDX-license-identifier-BSD",
13        "SPDX-license-identifier-ISC",
14        "SPDX-license-identifier-MIT",
15        "legacy_notice",
16        "legacy_unencumbered",
17    ],
18    license_text: [
19        "NOTICE",
20    ],
21}
22
23libc_common_src_files = [
24    "bionic/ether_aton.c",
25    "bionic/ether_ntoa.c",
26    "bionic/exit.cpp",
27    "bionic/fts.c",
28    "bionic/initgroups.c",
29    "bionic/isatty.c",
30    "bionic/sched_cpualloc.c",
31    "bionic/sched_cpucount.c",
32    "stdio/fmemopen.cpp",
33    "stdio/parsefloat.c",
34    "stdio/refill.c",
35    "stdio/stdio.cpp",
36    "stdio/stdio_ext.cpp",
37    "stdio/vfscanf.cpp",
38    "stdio/vfwscanf.c",
39]
40
41// off64_t/time64_t support on LP32.
42// ========================================================
43libc_common_src_files_32 = [
44    "bionic/legacy_32_bit_support.cpp",
45    "bionic/time64.c",
46]
47
48libc_common_flags = [
49    "-D_LIBC=1",
50    "-D__BIONIC_LP32_USE_STAT64",
51    "-Wall",
52    "-Wextra",
53    "-Wunused",
54    "-Wno-char-subscripts",
55    "-Wno-deprecated-declarations",
56    "-Wno-gcc-compat",
57    "-Wframe-larger-than=2048",
58
59    // Try to catch typical 32-bit assumptions that break with 64-bit pointers.
60    "-Werror=pointer-to-int-cast",
61    "-Werror=int-to-pointer-cast",
62    "-Werror=type-limits",
63    "-Werror",
64
65    // Clang's exit-time destructor registration hides __dso_handle, but
66    // __dso_handle needs to have default visibility on ARM32. See b/73485611.
67    "-Wexit-time-destructors",
68
69    // GWP-ASan requires platform TLS.
70    "-fno-emulated-tls",
71]
72
73// Define some common cflags
74// ========================================================
75cc_defaults {
76    name: "libc_defaults",
77    defaults: ["linux_bionic_supported"],
78    cflags: libc_common_flags,
79    asflags: libc_common_flags,
80    conlyflags: ["-std=gnu99"],
81    cppflags: [],
82    include_dirs: [
83        "bionic/libc/async_safe/include",
84        "bionic/libc/platform",
85        // For android_filesystem_config.h.
86        "system/core/libcutils/include",
87    ],
88
89    header_libs: [
90        "libc_headers",
91        "gwp_asan_headers",
92        "liblog_headers",  // needed by bionic/libc/async_safe/include
93    ],
94    export_header_lib_headers: [
95        "libc_headers",
96    ],
97
98    stl: "none",
99    system_shared_libs: [],
100    sanitize: {
101        address: false,
102        integer_overflow: false,
103        // TODO(b/132640749): Fix broken fuzzer support.
104        fuzzer: false,
105    },
106    ramdisk_available: true,
107    vendor_ramdisk_available: true,
108    recovery_available: true,
109    native_bridge_supported: true,
110
111    // lld complains about duplicate symbols in libcrt and libgcc. Suppress the
112    // warning since this is intended right now.
113    ldflags: ["-Wl,-z,muldefs"],
114
115    product_variables: {
116        malloc_zero_contents: {
117            cflags: ["-DSCUDO_ZERO_CONTENTS"],
118        },
119        malloc_pattern_fill_contents: {
120            cflags: ["-DSCUDO_PATTERN_FILL_CONTENTS"],
121        },
122        malloc_not_svelte: {
123            cflags: ["-DUSE_SCUDO"],
124        },
125    },
126}
127
128libc_scudo_product_variables = {
129    malloc_not_svelte: {
130        cflags: ["-DUSE_SCUDO"],
131        whole_static_libs: ["libscudo"],
132        exclude_static_libs: [
133            "libjemalloc5",
134            "libc_jemalloc_wrapper",
135        ],
136    },
137}
138
139// Defaults for native allocator libs/includes to make it
140// easier to change.
141// To disable scudo for the non-svelte config remove the line:
142//     product_variables: libc_scudo_product_variables,
143// in the cc_defaults below.
144// ========================================================
145cc_defaults {
146    name: "libc_native_allocator_defaults",
147
148    whole_static_libs: [
149        "libjemalloc5",
150        "libc_jemalloc_wrapper",
151    ],
152    header_libs: ["gwp_asan_headers"],
153    product_variables: libc_scudo_product_variables,
154}
155
156// Functions not implemented by jemalloc directly, or that need to
157// be modified for Android.
158cc_library_static {
159    name: "libc_jemalloc_wrapper",
160    defaults: ["libc_defaults"],
161    srcs: ["bionic/jemalloc_wrapper.cpp"],
162    cflags: ["-fvisibility=hidden"],
163
164    // Used to pull in the jemalloc include directory so that if the
165    // library is removed, the include directory is also removed.
166    static_libs: ["libjemalloc5"],
167}
168
169// ========================================================
170// libc_bootstrap.a - -fno-stack-protector and -ffreestanding
171// ========================================================
172//
173// Code that implements the stack protector (or that runs before TLS has been set up) needs to be
174// compiled with -fno-stack-protector, since it accesses the stack canary TLS slot. In the linker,
175// some of this code runs before ifunc resolvers have made string.h functions work, so compile with
176// -ffreestanding.
177
178cc_library_static {
179
180    srcs: [
181        "bionic/__libc_init_main_thread.cpp",
182        "bionic/__stack_chk_fail.cpp",
183        "bionic/bionic_call_ifunc_resolver.cpp",
184        "bionic/getauxval.cpp",
185    ],
186    arch: {
187        arm64: {
188            srcs: ["arch-arm64/bionic/__set_tls.c"],
189        },
190        x86: {
191            srcs: [
192                "arch-x86/bionic/__libc_init_sysinfo.cpp",
193                "arch-x86/bionic/__libc_int0x80.S",
194                "arch-x86/bionic/__set_tls.cpp",
195            ],
196        },
197        x86_64: {
198            srcs: ["arch-x86_64/bionic/__set_tls.c"],
199        },
200    },
201
202    defaults: ["libc_defaults"],
203    cflags: ["-fno-stack-protector", "-ffreestanding"],
204    name: "libc_bootstrap",
205}
206
207// libc_init_static.cpp and libc_init_dynamic.cpp need to be built without stack protector.
208// libc_init_static.cpp sets up TLS for static executables, and libc_init_dynamic.cpp initializes
209// the stack protector global variable.
210
211cc_library_static {
212    name: "libc_init_static",
213    defaults: ["libc_defaults"],
214    srcs: ["bionic/libc_init_static.cpp"],
215    cflags: [
216        "-fno-stack-protector",
217
218        // Compile libc_init_static.cpp with -ffreestanding, because some of its code is called
219        // from the linker before ifunc resolvers have made string.h functions available.
220        "-ffreestanding",
221    ],
222}
223
224cc_library_static {
225    name: "libc_init_dynamic",
226    defaults: ["libc_defaults"],
227    srcs: ["bionic/libc_init_dynamic.cpp"],
228    cflags: ["-fno-stack-protector"],
229}
230
231// ========================================================
232// libc_tzcode.a - upstream 'tzcode' code
233// ========================================================
234
235cc_library_static {
236
237    defaults: ["libc_defaults"],
238    srcs: [
239        "tzcode/**/*.c",
240        "tzcode/bionic.cpp",
241        "upstream-openbsd/lib/libc/time/wcsftime.c", // tzcode doesn't include wcsftime, so we use the OpenBSD one.
242    ],
243
244    cflags: [
245        "-Wno-unused-parameter",
246        // Don't use ridiculous amounts of stack.
247        "-DALL_STATE",
248        // Include tzsetwall, timelocal, timegm, time2posix, and posix2time.
249        "-DSTD_INSPIRED",
250        // Obviously, we want to be thread-safe.
251        "-DTHREAD_SAFE",
252        // The name of the tm_gmtoff field in our struct tm.
253        "-DTM_GMTOFF=tm_gmtoff",
254        // Where we store our tzdata.
255        "-DTZDIR=\"/system/usr/share/zoneinfo\"",
256        // Include `tzname`, `timezone`, and `daylight` globals.
257        "-DHAVE_POSIX_DECLS=0",
258        "-DUSG_COMPAT=1",
259        // Use the empty string (instead of "   ") as the timezone abbreviation
260        // fallback.
261        "-DWILDABBR=\"\"",
262        "-DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU",
263        "-Dlint",
264    ],
265
266    local_include_dirs: ["tzcode/"],
267    name: "libc_tzcode",
268}
269
270// ========================================================
271// libc_dns.a - modified NetBSD DNS code
272// ========================================================
273
274cc_library_static {
275
276    defaults: ["libc_defaults"],
277    srcs: [
278        "dns/**/*.c*",
279
280        "upstream-netbsd/lib/libc/isc/ev_streams.c",
281        "upstream-netbsd/lib/libc/isc/ev_timers.c",
282    ],
283
284    cflags: [
285        "-DANDROID_CHANGES",
286        "-DINET6",
287        "-Wno-unused-parameter",
288        "-include netbsd-compat.h",
289        "-Wframe-larger-than=66000",
290        "-include private/bsd_sys_param.h",
291    ],
292
293    local_include_dirs: [
294        "dns/include",
295        "private",
296        "upstream-netbsd/lib/libc/include",
297        "upstream-netbsd/android/include",
298    ],
299
300    name: "libc_dns",
301}
302
303// ========================================================
304// libc_freebsd.a - upstream FreeBSD C library code
305// ========================================================
306//
307// These files are built with the freebsd-compat.h header file
308// automatically included.
309
310cc_library_static {
311    defaults: ["libc_defaults"],
312    srcs: [
313        "upstream-freebsd/lib/libc/gen/ldexp.c",
314        "upstream-freebsd/lib/libc/stdlib/getopt_long.c",
315        "upstream-freebsd/lib/libc/stdlib/hcreate.c",
316        "upstream-freebsd/lib/libc/stdlib/hcreate_r.c",
317        "upstream-freebsd/lib/libc/stdlib/hdestroy_r.c",
318        "upstream-freebsd/lib/libc/stdlib/hsearch_r.c",
319        "upstream-freebsd/lib/libc/stdlib/qsort.c",
320        "upstream-freebsd/lib/libc/stdlib/quick_exit.c",
321        "upstream-freebsd/lib/libc/string/wcpcpy.c",
322        "upstream-freebsd/lib/libc/string/wcpncpy.c",
323        "upstream-freebsd/lib/libc/string/wcscasecmp.c",
324        "upstream-freebsd/lib/libc/string/wcscat.c",
325        "upstream-freebsd/lib/libc/string/wcschr.c",
326        "upstream-freebsd/lib/libc/string/wcscmp.c",
327        "upstream-freebsd/lib/libc/string/wcscpy.c",
328        "upstream-freebsd/lib/libc/string/wcscspn.c",
329        "upstream-freebsd/lib/libc/string/wcsdup.c",
330        "upstream-freebsd/lib/libc/string/wcslcat.c",
331        "upstream-freebsd/lib/libc/string/wcslen.c",
332        "upstream-freebsd/lib/libc/string/wcsncasecmp.c",
333        "upstream-freebsd/lib/libc/string/wcsncat.c",
334        "upstream-freebsd/lib/libc/string/wcsncmp.c",
335        "upstream-freebsd/lib/libc/string/wcsncpy.c",
336        "upstream-freebsd/lib/libc/string/wcsnlen.c",
337        "upstream-freebsd/lib/libc/string/wcspbrk.c",
338        "upstream-freebsd/lib/libc/string/wcsrchr.c",
339        "upstream-freebsd/lib/libc/string/wcsspn.c",
340        "upstream-freebsd/lib/libc/string/wcsstr.c",
341        "upstream-freebsd/lib/libc/string/wcstok.c",
342        "upstream-freebsd/lib/libc/string/wmemchr.c",
343        "upstream-freebsd/lib/libc/string/wmemcmp.c",
344        "upstream-freebsd/lib/libc/string/wmemcpy.c",
345        "upstream-freebsd/lib/libc/string/wmemmove.c",
346        "upstream-freebsd/lib/libc/string/wmemset.c",
347    ],
348    arch: {
349        arm64: {
350            exclude_srcs: [
351                "upstream-freebsd/lib/libc/string/wmemmove.c",
352            ],
353        },
354        x86: {
355            exclude_srcs: [
356                "upstream-freebsd/lib/libc/string/wcschr.c",
357                "upstream-freebsd/lib/libc/string/wcscmp.c",
358                "upstream-freebsd/lib/libc/string/wcslen.c",
359                "upstream-freebsd/lib/libc/string/wcsrchr.c",
360                "upstream-freebsd/lib/libc/string/wmemcmp.c",
361                "upstream-freebsd/lib/libc/string/wcscat.c",
362                "upstream-freebsd/lib/libc/string/wcscpy.c",
363                "upstream-freebsd/lib/libc/string/wmemcmp.c",
364                "upstream-freebsd/lib/libc/string/wmemset.c",
365            ],
366        },
367    },
368
369    cflags: [
370        "-Wno-sign-compare",
371        "-Wno-unused-parameter",
372        "-include freebsd-compat.h",
373    ],
374
375    local_include_dirs: [
376        "upstream-freebsd/android/include",
377    ],
378
379    name: "libc_freebsd",
380}
381
382cc_library_static {
383    defaults: ["libc_defaults"],
384    srcs: [
385        "upstream-freebsd/lib/libc/gen/glob.c",
386    ],
387
388    cflags: [
389        "-Wno-sign-compare",
390        "-include freebsd-compat.h",
391        "-Wframe-larger-than=66000",
392    ],
393
394    local_include_dirs: [
395        "upstream-freebsd/android/include",
396    ],
397
398    name: "libc_freebsd_large_stack",
399}
400
401// ========================================================
402// libc_netbsd.a - upstream NetBSD C library code
403// ========================================================
404//
405// These files are built with the netbsd-compat.h header file
406// automatically included.
407
408cc_library_static {
409
410    defaults: ["libc_defaults"],
411    srcs: [
412        "upstream-netbsd/common/lib/libc/stdlib/random.c",
413        "upstream-netbsd/lib/libc/gen/nice.c",
414        "upstream-netbsd/lib/libc/gen/psignal.c",
415        "upstream-netbsd/lib/libc/gen/utime.c",
416        "upstream-netbsd/lib/libc/inet/nsap_addr.c",
417        "upstream-netbsd/lib/libc/regex/regcomp.c",
418        "upstream-netbsd/lib/libc/regex/regerror.c",
419        "upstream-netbsd/lib/libc/regex/regexec.c",
420        "upstream-netbsd/lib/libc/regex/regfree.c",
421        "upstream-netbsd/lib/libc/stdlib/bsearch.c",
422        "upstream-netbsd/lib/libc/stdlib/drand48.c",
423        "upstream-netbsd/lib/libc/stdlib/erand48.c",
424        "upstream-netbsd/lib/libc/stdlib/jrand48.c",
425        "upstream-netbsd/lib/libc/stdlib/lcong48.c",
426        "upstream-netbsd/lib/libc/stdlib/lrand48.c",
427        "upstream-netbsd/lib/libc/stdlib/mrand48.c",
428        "upstream-netbsd/lib/libc/stdlib/nrand48.c",
429        "upstream-netbsd/lib/libc/stdlib/_rand48.c",
430        "upstream-netbsd/lib/libc/stdlib/rand_r.c",
431        "upstream-netbsd/lib/libc/stdlib/reallocarr.c",
432        "upstream-netbsd/lib/libc/stdlib/seed48.c",
433        "upstream-netbsd/lib/libc/stdlib/srand48.c",
434    ],
435    multilib: {
436        lib32: {
437            // LP32 cruft
438            srcs: ["upstream-netbsd/common/lib/libc/hash/sha1/sha1.c"],
439        },
440    },
441    cflags: [
442        "-Wno-sign-compare",
443        "-Wno-unused-parameter",
444        "-DPOSIX_MISTAKE",
445        "-include netbsd-compat.h",
446    ],
447
448    local_include_dirs: [
449        "upstream-netbsd/android/include",
450        "upstream-netbsd/lib/libc/include",
451    ],
452
453    name: "libc_netbsd",
454}
455
456// ========================================================
457// libc_openbsd_ndk.a - upstream OpenBSD C library code
458// that can be safely included in the libc_ndk.a (doesn't
459// contain any troublesome global data or constructors).
460// ========================================================
461//
462// These files are built with the openbsd-compat.h header file
463// automatically included.
464
465cc_library_static {
466    name: "libc_openbsd_ndk",
467    defaults: ["libc_defaults"],
468    srcs: [
469        "upstream-openbsd/lib/libc/gen/alarm.c",
470        "upstream-openbsd/lib/libc/gen/ctype_.c",
471        "upstream-openbsd/lib/libc/gen/daemon.c",
472        "upstream-openbsd/lib/libc/gen/err.c",
473        "upstream-openbsd/lib/libc/gen/errx.c",
474        "upstream-openbsd/lib/libc/gen/fnmatch.c",
475        "upstream-openbsd/lib/libc/gen/ftok.c",
476        "upstream-openbsd/lib/libc/gen/getprogname.c",
477        "upstream-openbsd/lib/libc/gen/setprogname.c",
478        "upstream-openbsd/lib/libc/gen/verr.c",
479        "upstream-openbsd/lib/libc/gen/verrx.c",
480        "upstream-openbsd/lib/libc/gen/vwarn.c",
481        "upstream-openbsd/lib/libc/gen/vwarnx.c",
482        "upstream-openbsd/lib/libc/gen/warn.c",
483        "upstream-openbsd/lib/libc/gen/warnx.c",
484        "upstream-openbsd/lib/libc/locale/btowc.c",
485        "upstream-openbsd/lib/libc/locale/mbrlen.c",
486        "upstream-openbsd/lib/libc/locale/mbstowcs.c",
487        "upstream-openbsd/lib/libc/locale/mbtowc.c",
488        "upstream-openbsd/lib/libc/locale/wcscoll.c",
489        "upstream-openbsd/lib/libc/locale/wcstoimax.c",
490        "upstream-openbsd/lib/libc/locale/wcstol.c",
491        "upstream-openbsd/lib/libc/locale/wcstoll.c",
492        "upstream-openbsd/lib/libc/locale/wcstombs.c",
493        "upstream-openbsd/lib/libc/locale/wcstoul.c",
494        "upstream-openbsd/lib/libc/locale/wcstoull.c",
495        "upstream-openbsd/lib/libc/locale/wcstoumax.c",
496        "upstream-openbsd/lib/libc/locale/wcsxfrm.c",
497        "upstream-openbsd/lib/libc/locale/wctob.c",
498        "upstream-openbsd/lib/libc/locale/wctomb.c",
499        "upstream-openbsd/lib/libc/net/base64.c",
500        "upstream-openbsd/lib/libc/net/htonl.c",
501        "upstream-openbsd/lib/libc/net/htons.c",
502        "upstream-openbsd/lib/libc/net/inet_lnaof.c",
503        "upstream-openbsd/lib/libc/net/inet_makeaddr.c",
504        "upstream-openbsd/lib/libc/net/inet_netof.c",
505        "upstream-openbsd/lib/libc/net/inet_ntoa.c",
506        "upstream-openbsd/lib/libc/net/inet_ntop.c",
507        "upstream-openbsd/lib/libc/net/inet_pton.c",
508        "upstream-openbsd/lib/libc/net/ntohl.c",
509        "upstream-openbsd/lib/libc/net/ntohs.c",
510        "upstream-openbsd/lib/libc/net/res_random.c",
511        "upstream-openbsd/lib/libc/stdio/fgetln.c",
512        "upstream-openbsd/lib/libc/stdio/fgetwc.c",
513        "upstream-openbsd/lib/libc/stdio/fgetws.c",
514        "upstream-openbsd/lib/libc/stdio/flags.c",
515        "upstream-openbsd/lib/libc/stdio/fpurge.c",
516        "upstream-openbsd/lib/libc/stdio/fputwc.c",
517        "upstream-openbsd/lib/libc/stdio/fputws.c",
518        "upstream-openbsd/lib/libc/stdio/fvwrite.c",
519        "upstream-openbsd/lib/libc/stdio/fwide.c",
520        "upstream-openbsd/lib/libc/stdio/getdelim.c",
521        "upstream-openbsd/lib/libc/stdio/gets.c",
522        "upstream-openbsd/lib/libc/stdio/makebuf.c",
523        "upstream-openbsd/lib/libc/stdio/mktemp.c",
524        "upstream-openbsd/lib/libc/stdio/open_memstream.c",
525        "upstream-openbsd/lib/libc/stdio/open_wmemstream.c",
526        "upstream-openbsd/lib/libc/stdio/rget.c",
527        "upstream-openbsd/lib/libc/stdio/setvbuf.c",
528        "upstream-openbsd/lib/libc/stdio/ungetc.c",
529        "upstream-openbsd/lib/libc/stdio/ungetwc.c",
530        "upstream-openbsd/lib/libc/stdio/vasprintf.c",
531        "upstream-openbsd/lib/libc/stdio/vdprintf.c",
532        "upstream-openbsd/lib/libc/stdio/vsscanf.c",
533        "upstream-openbsd/lib/libc/stdio/vswprintf.c",
534        "upstream-openbsd/lib/libc/stdio/vswscanf.c",
535        "upstream-openbsd/lib/libc/stdio/wbuf.c",
536        "upstream-openbsd/lib/libc/stdio/wsetup.c",
537        "upstream-openbsd/lib/libc/stdlib/abs.c",
538        "upstream-openbsd/lib/libc/stdlib/div.c",
539        "upstream-openbsd/lib/libc/stdlib/getenv.c",
540        "upstream-openbsd/lib/libc/stdlib/getsubopt.c",
541        "upstream-openbsd/lib/libc/stdlib/insque.c",
542        "upstream-openbsd/lib/libc/stdlib/imaxabs.c",
543        "upstream-openbsd/lib/libc/stdlib/imaxdiv.c",
544        "upstream-openbsd/lib/libc/stdlib/labs.c",
545        "upstream-openbsd/lib/libc/stdlib/ldiv.c",
546        "upstream-openbsd/lib/libc/stdlib/llabs.c",
547        "upstream-openbsd/lib/libc/stdlib/lldiv.c",
548        "upstream-openbsd/lib/libc/stdlib/lsearch.c",
549        "upstream-openbsd/lib/libc/stdlib/recallocarray.c",
550        "upstream-openbsd/lib/libc/stdlib/remque.c",
551        "upstream-openbsd/lib/libc/stdlib/setenv.c",
552        "upstream-openbsd/lib/libc/stdlib/tfind.c",
553        "upstream-openbsd/lib/libc/stdlib/tsearch.c",
554        "upstream-openbsd/lib/libc/string/memccpy.c",
555        "upstream-openbsd/lib/libc/string/strcasecmp.c",
556        "upstream-openbsd/lib/libc/string/strcasestr.c",
557        "upstream-openbsd/lib/libc/string/strcoll.c",
558        "upstream-openbsd/lib/libc/string/strcspn.c",
559        "upstream-openbsd/lib/libc/string/strdup.c",
560        "upstream-openbsd/lib/libc/string/strndup.c",
561        "upstream-openbsd/lib/libc/string/strpbrk.c",
562        "upstream-openbsd/lib/libc/string/strsep.c",
563        "upstream-openbsd/lib/libc/string/strspn.c",
564        "upstream-openbsd/lib/libc/string/strtok.c",
565        "upstream-openbsd/lib/libc/string/strxfrm.c",
566        "upstream-openbsd/lib/libc/string/wcslcpy.c",
567        "upstream-openbsd/lib/libc/string/wcswidth.c",
568    ],
569
570    cflags: [
571        "-Wno-sign-compare",
572        "-Wno-unused-parameter",
573        "-include openbsd-compat.h",
574    ],
575
576    local_include_dirs: [
577        "private",
578        "stdio",
579        "upstream-openbsd/android/include",
580        "upstream-openbsd/lib/libc/include",
581        "upstream-openbsd/lib/libc/gdtoa/",
582    ],
583}
584
585cc_library_static {
586    name: "libc_openbsd_large_stack",
587    defaults: ["libc_defaults"],
588    srcs: [
589        "stdio/vfprintf.cpp",
590        "stdio/vfwprintf.cpp",
591        "upstream-openbsd/lib/libc/string/memmem.c",
592        "upstream-openbsd/lib/libc/string/strstr.c",
593    ],
594    cflags: [
595        "-include openbsd-compat.h",
596        "-Wno-sign-compare",
597        "-Wframe-larger-than=5000",
598    ],
599
600    local_include_dirs: [
601        "private",
602        "upstream-openbsd/android/include/",
603        "upstream-openbsd/lib/libc/include/",
604        "upstream-openbsd/lib/libc/gdtoa/",
605        "upstream-openbsd/lib/libc/stdio/",
606    ],
607}
608
609// ========================================================
610// libc_openbsd.a - upstream OpenBSD C library code
611// ========================================================
612//
613// These files are built with the openbsd-compat.h header file
614// automatically included.
615cc_library_static {
616    defaults: ["libc_defaults"],
617    srcs: [
618        // These two depend on getentropy, which isn't in libc_ndk.a.
619        "upstream-openbsd/lib/libc/crypt/arc4random.c",
620        "upstream-openbsd/lib/libc/crypt/arc4random_uniform.c",
621
622        // May be overriden by per-arch optimized versions
623        "upstream-openbsd/lib/libc/string/memchr.c",
624        "upstream-openbsd/lib/libc/string/memrchr.c",
625        "upstream-openbsd/lib/libc/string/stpcpy.c",
626        "upstream-openbsd/lib/libc/string/stpncpy.c",
627        "upstream-openbsd/lib/libc/string/strcat.c",
628        "upstream-openbsd/lib/libc/string/strcpy.c",
629        "upstream-openbsd/lib/libc/string/strlcat.c",
630        "upstream-openbsd/lib/libc/string/strlcpy.c",
631        "upstream-openbsd/lib/libc/string/strncat.c",
632        "upstream-openbsd/lib/libc/string/strncmp.c",
633        "upstream-openbsd/lib/libc/string/strncpy.c",
634    ],
635
636    arch: {
637        arm: {
638            exclude_srcs: [
639                "upstream-openbsd/lib/libc/string/strcpy.c",
640                "upstream-openbsd/lib/libc/string/stpcpy.c",
641                "upstream-openbsd/lib/libc/string/strcat.c",
642            ],
643        },
644        arm64: {
645            exclude_srcs: [
646                "upstream-openbsd/lib/libc/string/memchr.c",
647                "upstream-openbsd/lib/libc/string/memrchr.c",
648                "upstream-openbsd/lib/libc/string/stpcpy.c",
649                "upstream-openbsd/lib/libc/string/strcpy.c",
650                "upstream-openbsd/lib/libc/string/strncmp.c",
651            ],
652        },
653        x86: {
654            exclude_srcs: [
655                "upstream-openbsd/lib/libc/string/memchr.c",
656                "upstream-openbsd/lib/libc/string/memrchr.c",
657                "upstream-openbsd/lib/libc/string/stpcpy.c",
658                "upstream-openbsd/lib/libc/string/stpncpy.c",
659                "upstream-openbsd/lib/libc/string/strcat.c",
660                "upstream-openbsd/lib/libc/string/strcpy.c",
661                "upstream-openbsd/lib/libc/string/strncmp.c",
662                "upstream-openbsd/lib/libc/string/strncpy.c",
663                "upstream-openbsd/lib/libc/string/strlcat.c",
664                "upstream-openbsd/lib/libc/string/strlcpy.c",
665                "upstream-openbsd/lib/libc/string/strncat.c",
666            ],
667        },
668
669        x86_64: {
670            exclude_srcs: [
671                "upstream-openbsd/lib/libc/string/stpcpy.c",
672                "upstream-openbsd/lib/libc/string/stpncpy.c",
673                "upstream-openbsd/lib/libc/string/strcat.c",
674                "upstream-openbsd/lib/libc/string/strcpy.c",
675                "upstream-openbsd/lib/libc/string/strncat.c",
676                "upstream-openbsd/lib/libc/string/strncmp.c",
677                "upstream-openbsd/lib/libc/string/strncpy.c",
678            ],
679        },
680    },
681
682    cflags: [
683        "-Wno-sign-compare",
684        "-Wno-unused-parameter",
685        "-include openbsd-compat.h",
686    ],
687
688    local_include_dirs: [
689        "private",
690        "upstream-openbsd/android/include",
691    ],
692
693    name: "libc_openbsd",
694}
695
696// ========================================================
697// libc_gdtoa.a - upstream OpenBSD C library gdtoa code
698// ========================================================
699//
700// These files are built with the openbsd-compat.h header file
701// automatically included.
702
703cc_library_static {
704    defaults: ["libc_defaults"],
705    srcs: [
706        "upstream-openbsd/android/gdtoa_support.cpp",
707        "upstream-openbsd/lib/libc/gdtoa/dmisc.c",
708        "upstream-openbsd/lib/libc/gdtoa/dtoa.c",
709        "upstream-openbsd/lib/libc/gdtoa/gdtoa.c",
710        "upstream-openbsd/lib/libc/gdtoa/gethex.c",
711        "upstream-openbsd/lib/libc/gdtoa/gmisc.c",
712        "upstream-openbsd/lib/libc/gdtoa/hd_init.c",
713        "upstream-openbsd/lib/libc/gdtoa/hdtoa.c",
714        "upstream-openbsd/lib/libc/gdtoa/hexnan.c",
715        "upstream-openbsd/lib/libc/gdtoa/ldtoa.c",
716        "upstream-openbsd/lib/libc/gdtoa/misc.c",
717        "upstream-openbsd/lib/libc/gdtoa/smisc.c",
718        "upstream-openbsd/lib/libc/gdtoa/strtod.c",
719        "upstream-openbsd/lib/libc/gdtoa/strtodg.c",
720        "upstream-openbsd/lib/libc/gdtoa/strtof.c",
721        "upstream-openbsd/lib/libc/gdtoa/strtord.c",
722        "upstream-openbsd/lib/libc/gdtoa/sum.c",
723        "upstream-openbsd/lib/libc/gdtoa/ulp.c",
724    ],
725    multilib: {
726        lib64: {
727            srcs: ["upstream-openbsd/lib/libc/gdtoa/strtorQ.c"],
728        },
729    },
730
731    cflags: [
732        "-Wno-sign-compare",
733        "-include openbsd-compat.h",
734    ],
735
736    local_include_dirs: [
737        "private",
738        "upstream-openbsd/android/include",
739        "upstream-openbsd/lib/libc/include",
740    ],
741
742    name: "libc_gdtoa",
743}
744
745// ========================================================
746// libc_fortify.a - container for our FORITFY
747// implementation details
748// ========================================================
749cc_library_static {
750    defaults: ["libc_defaults"],
751    srcs: ["bionic/fortify.cpp"],
752
753    name: "libc_fortify",
754
755    // Disable FORTIFY for the compilation of these, so we don't end up having
756    // FORTIFY silently call itself.
757    cflags: [
758        "-U_FORTIFY_SOURCE",
759        "-D__BIONIC_DECLARE_FORTIFY_HELPERS",
760    ],
761
762    arch: {
763        arm: {
764            cflags: [
765                "-DNO___MEMCPY_CHK",
766                "-DRENAME___STRCAT_CHK",
767                "-DRENAME___STRCPY_CHK",
768            ],
769            srcs: [
770                "arch-arm/generic/bionic/__memcpy_chk.S",
771
772                "arch-arm/cortex-a15/bionic/__strcat_chk.S",
773                "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
774
775                "arch-arm/cortex-a7/bionic/__strcat_chk.S",
776                "arch-arm/cortex-a7/bionic/__strcpy_chk.S",
777
778                "arch-arm/cortex-a9/bionic/__strcat_chk.S",
779                "arch-arm/cortex-a9/bionic/__strcpy_chk.S",
780
781                "arch-arm/krait/bionic/__strcat_chk.S",
782                "arch-arm/krait/bionic/__strcpy_chk.S",
783
784                "arch-arm/cortex-a53/bionic/__strcat_chk.S",
785                "arch-arm/cortex-a53/bionic/__strcpy_chk.S",
786
787                "arch-arm/cortex-a55/bionic/__strcat_chk.S",
788                "arch-arm/cortex-a55/bionic/__strcpy_chk.S",
789            ],
790        },
791        arm64: {
792            cflags: ["-DNO___MEMCPY_CHK"],
793            srcs: [
794                "arch-arm64/generic/bionic/__memcpy_chk.S",
795            ],
796        },
797    },
798}
799
800// ========================================================
801// libc_bionic.a - home-grown C library code
802// ========================================================
803
804cc_library_static {
805    defaults: ["libc_defaults"],
806    srcs: [
807        // These require getauxval, which isn't available on older platforms.
808        "bionic/sysconf.cpp",
809        "bionic/vdso.cpp",
810        "bionic/setjmp_cookie.cpp",
811
812        // The following must not be statically linked into libc_ndk.a, because
813        // debuggerd will look for the abort message in libc.so's copy.
814        "bionic/android_set_abort_message.cpp",
815
816        "bionic/strchr.cpp",
817        "bionic/strchrnul.cpp",
818        "bionic/strnlen.c",
819        "bionic/strrchr.cpp",
820    ],
821
822    arch: {
823        arm: {
824            asflags: libc_common_flags + ["-mno-restrict-it"],
825            srcs: [
826                "arch-arm/generic/bionic/memcmp.S",
827                "arch-arm/generic/bionic/memmove.S",
828                "arch-arm/generic/bionic/memset.S",
829                "arch-arm/generic/bionic/stpcpy.c",
830                "arch-arm/generic/bionic/strcat.c",
831                "arch-arm/generic/bionic/strcmp.S",
832                "arch-arm/generic/bionic/strcpy.S",
833                "arch-arm/generic/bionic/strlen.c",
834
835                "arch-arm/bionic/__aeabi_read_tp.S",
836                "arch-arm/bionic/__bionic_clone.S",
837                "arch-arm/bionic/__restore.S",
838                "arch-arm/bionic/_exit_with_stack_teardown.S",
839                "arch-arm/bionic/atomics_arm.c",
840                "arch-arm/bionic/bpabi.c",
841                "arch-arm/bionic/libcrt_compat.c",
842                "arch-arm/bionic/popcount_tab.c",
843                "arch-arm/bionic/setjmp.S",
844                "arch-arm/bionic/syscall.S",
845                "arch-arm/bionic/vfork.S",
846
847                "arch-arm/cortex-a15/bionic/memcpy.S",
848                "arch-arm/cortex-a15/bionic/memmove.S",
849                "arch-arm/cortex-a15/bionic/memset.S",
850                "arch-arm/cortex-a15/bionic/stpcpy.S",
851                "arch-arm/cortex-a15/bionic/strcat.S",
852                "arch-arm/cortex-a15/bionic/strcmp.S",
853                "arch-arm/cortex-a15/bionic/strcpy.S",
854                "arch-arm/cortex-a15/bionic/strlen.S",
855
856                "arch-arm/cortex-a7/bionic/memcpy.S",
857                "arch-arm/cortex-a7/bionic/memset.S",
858
859                "arch-arm/cortex-a9/bionic/memcpy.S",
860                "arch-arm/cortex-a9/bionic/memset.S",
861                "arch-arm/cortex-a9/bionic/stpcpy.S",
862                "arch-arm/cortex-a9/bionic/strcat.S",
863                "arch-arm/cortex-a9/bionic/strcpy.S",
864                "arch-arm/cortex-a9/bionic/strlen.S",
865
866                "arch-arm/krait/bionic/memcpy.S",
867                "arch-arm/krait/bionic/memset.S",
868
869                "arch-arm/cortex-a53/bionic/memcpy.S",
870
871                "arch-arm/cortex-a55/bionic/memcpy.S",
872
873                "arch-arm/kryo/bionic/memcpy.S",
874            ],
875        },
876        arm64: {
877            srcs: [
878                "arch-arm64/generic/bionic/memcpy.S",
879                "arch-arm64/generic/bionic/memmove.S",
880                "arch-arm64/generic/bionic/memset.S",
881                "arch-arm64/generic/bionic/wmemmove.S",
882
883                "arch-arm64/bionic/__bionic_clone.S",
884                "arch-arm64/bionic/_exit_with_stack_teardown.S",
885                "arch-arm64/bionic/setjmp.S",
886                "arch-arm64/bionic/syscall.S",
887                "arch-arm64/bionic/vfork.S",
888            ],
889            exclude_srcs: [
890                "bionic/__memcpy_chk.cpp",
891                "bionic/strchr.cpp",
892                "bionic/strchrnul.cpp",
893                "bionic/strnlen.c",
894                "bionic/strrchr.cpp",
895            ],
896        },
897
898        x86: {
899            srcs: [
900                "arch-x86/generic/string/memcmp.S",
901                "arch-x86/generic/string/strcmp.S",
902                "arch-x86/generic/string/strncmp.S",
903                "arch-x86/generic/string/strcat.S",
904
905                "arch-x86/generic/string/strlcat.c",
906                "arch-x86/generic/string/strlcpy.c",
907                "arch-x86/generic/string/strncat.c",
908                "arch-x86/generic/string/wcscat.c",
909                "arch-x86/generic/string/wcscpy.c",
910                "arch-x86/generic/string/wmemcmp.c",
911                "arch-x86/generic/string/wmemset.c",
912
913                "arch-x86/atom/string/sse2-memchr-atom.S",
914                "arch-x86/atom/string/sse2-memrchr-atom.S",
915                "arch-x86/atom/string/sse2-strchr-atom.S",
916                "arch-x86/atom/string/sse2-strnlen-atom.S",
917                "arch-x86/atom/string/sse2-strrchr-atom.S",
918                "arch-x86/atom/string/sse2-wcschr-atom.S",
919                "arch-x86/atom/string/sse2-wcsrchr-atom.S",
920                "arch-x86/atom/string/sse2-wcslen-atom.S",
921                "arch-x86/atom/string/sse2-wcscmp-atom.S",
922                "arch-x86/silvermont/string/sse2-memmove-slm.S",
923                "arch-x86/silvermont/string/sse2-memset-slm.S",
924                "arch-x86/silvermont/string/sse2-stpcpy-slm.S",
925                "arch-x86/silvermont/string/sse2-stpncpy-slm.S",
926                "arch-x86/silvermont/string/sse2-strcpy-slm.S",
927                "arch-x86/silvermont/string/sse2-strlen-slm.S",
928                "arch-x86/silvermont/string/sse2-strncpy-slm.S",
929
930                "arch-x86/bionic/__bionic_clone.S",
931                "arch-x86/bionic/_exit_with_stack_teardown.S",
932                "arch-x86/bionic/libcrt_compat.c",
933                "arch-x86/bionic/__restore.S",
934                "arch-x86/bionic/setjmp.S",
935                "arch-x86/bionic/syscall.S",
936                "arch-x86/bionic/vfork.S",
937                "arch-x86/bionic/__x86.get_pc_thunk.S",
938
939                // ssse3 functions
940                "arch-x86/atom/string/ssse3-strcat-atom.S",
941                "arch-x86/atom/string/ssse3-strcmp-atom.S",
942                "arch-x86/atom/string/ssse3-strlcat-atom.S",
943                "arch-x86/atom/string/ssse3-strlcpy-atom.S",
944                "arch-x86/atom/string/ssse3-strncat-atom.S",
945                "arch-x86/atom/string/ssse3-strncmp-atom.S",
946                "arch-x86/atom/string/ssse3-wcscat-atom.S",
947                "arch-x86/atom/string/ssse3-wcscpy-atom.S",
948
949                // sse4 functions
950                "arch-x86/silvermont/string/sse4-memcmp-slm.S",
951                "arch-x86/silvermont/string/sse4-wmemcmp-slm.S",
952
953                // atom functions
954                "arch-x86/atom/string/sse2-memset-atom.S",
955                "arch-x86/atom/string/sse2-strlen-atom.S",
956                "arch-x86/atom/string/ssse3-memcmp-atom.S",
957                "arch-x86/atom/string/ssse3-memmove-atom.S",
958                "arch-x86/atom/string/ssse3-strcpy-atom.S",
959                "arch-x86/atom/string/ssse3-strncpy-atom.S",
960                "arch-x86/atom/string/ssse3-wmemcmp-atom.S",
961
962                // avx2 functions
963                "arch-x86/kabylake/string/avx2-wmemset-kbl.S",
964            ],
965
966            exclude_srcs: [
967                "bionic/strchr.cpp",
968                "bionic/strnlen.c",
969                "bionic/strrchr.cpp",
970            ],
971        },
972        x86_64: {
973            srcs: [
974                "arch-x86_64/string/sse2-memmove-slm.S",
975                "arch-x86_64/string/sse2-memset-slm.S",
976                "arch-x86_64/string/sse2-stpcpy-slm.S",
977                "arch-x86_64/string/sse2-stpncpy-slm.S",
978                "arch-x86_64/string/sse2-strcat-slm.S",
979                "arch-x86_64/string/sse2-strcpy-slm.S",
980                "arch-x86_64/string/sse2-strlen-slm.S",
981                "arch-x86_64/string/sse2-strncat-slm.S",
982                "arch-x86_64/string/sse2-strncpy-slm.S",
983                "arch-x86_64/string/sse4-memcmp-slm.S",
984                "arch-x86_64/string/ssse3-strcmp-slm.S",
985                "arch-x86_64/string/ssse3-strncmp-slm.S",
986                "arch-x86_64/string/avx2-wmemset-kbl.S",
987
988                "arch-x86_64/bionic/__bionic_clone.S",
989                "arch-x86_64/bionic/_exit_with_stack_teardown.S",
990                "arch-x86_64/bionic/__restore_rt.S",
991                "arch-x86_64/bionic/setjmp.S",
992                "arch-x86_64/bionic/syscall.S",
993                "arch-x86_64/bionic/vfork.S",
994            ],
995        },
996    },
997
998    cppflags: ["-Wold-style-cast"],
999    include_dirs: ["bionic/libstdc++/include"],
1000    name: "libc_bionic",
1001}
1002
1003genrule {
1004    name: "generated_android_ids",
1005    out: ["generated_android_ids.h"],
1006    srcs: [":android_filesystem_config_header"],
1007    tool_files: ["fs_config_generator.py"],
1008    cmd: "$(location fs_config_generator.py) aidarray $(in) > $(out)",
1009}
1010
1011// ========================================================
1012// libc_bionic_ndk.a- The portions of libc_bionic that can
1013// be safely used in libc_ndk.a (no troublesome global data
1014// or constructors).
1015// ========================================================
1016cc_library_static {
1017    defaults: ["libc_defaults"],
1018    srcs: [
1019        "bionic/NetdClientDispatch.cpp",
1020        "bionic/__bionic_get_shell_path.cpp",
1021        "bionic/__cmsg_nxthdr.cpp",
1022        "bionic/__errno.cpp",
1023        "bionic/__gnu_basename.cpp",
1024        "bionic/__libc_current_sigrtmax.cpp",
1025        "bionic/__libc_current_sigrtmin.cpp",
1026        "bionic/abort.cpp",
1027        "bionic/accept.cpp",
1028        "bionic/access.cpp",
1029        "bionic/arpa_inet.cpp",
1030        "bionic/assert.cpp",
1031        "bionic/atof.cpp",
1032        "bionic/bionic_allocator.cpp",
1033        "bionic/bionic_arc4random.cpp",
1034        "bionic/bionic_futex.cpp",
1035        "bionic/bionic_netlink.cpp",
1036        "bionic/bionic_time_conversions.cpp",
1037        "bionic/brk.cpp",
1038        "bionic/c16rtomb.cpp",
1039        "bionic/c32rtomb.cpp",
1040        "bionic/chmod.cpp",
1041        "bionic/chown.cpp",
1042        "bionic/clearenv.cpp",
1043        "bionic/clock.cpp",
1044        "bionic/clock_getcpuclockid.cpp",
1045        "bionic/clock_nanosleep.cpp",
1046        "bionic/clone.cpp",
1047        "bionic/ctype.cpp",
1048        "bionic/dirent.cpp",
1049        "bionic/dup.cpp",
1050        "bionic/environ.cpp",
1051        "bionic/error.cpp",
1052        "bionic/eventfd.cpp",
1053        "bionic/exec.cpp",
1054        "bionic/faccessat.cpp",
1055        "bionic/fchmod.cpp",
1056        "bionic/fchmodat.cpp",
1057        "bionic/fcntl.cpp",
1058        "bionic/fdsan.cpp",
1059        "bionic/fdtrack.cpp",
1060        "bionic/ffs.cpp",
1061        "bionic/fgetxattr.cpp",
1062        "bionic/flistxattr.cpp",
1063        "bionic/flockfile.cpp",
1064        "bionic/fpclassify.cpp",
1065        "bionic/fsetxattr.cpp",
1066        "bionic/ftruncate.cpp",
1067        "bionic/ftw.cpp",
1068        "bionic/futimens.cpp",
1069        "bionic/getcwd.cpp",
1070        "bionic/getdomainname.cpp",
1071        "bionic/getentropy.cpp",
1072        "bionic/gethostname.cpp",
1073        "bionic/getloadavg.cpp",
1074        "bionic/getpagesize.cpp",
1075        "bionic/getpgrp.cpp",
1076        "bionic/getpid.cpp",
1077        "bionic/getpriority.cpp",
1078        "bionic/gettid.cpp",
1079        "bionic/get_device_api_level.cpp",
1080        "bionic/grp_pwd.cpp",
1081        "bionic/grp_pwd_file.cpp",
1082        "bionic/heap_zero_init.cpp",
1083        "bionic/iconv.cpp",
1084        "bionic/icu_wrappers.cpp",
1085        "bionic/ifaddrs.cpp",
1086        "bionic/inotify_init.cpp",
1087        "bionic/ioctl.cpp",
1088        "bionic/killpg.cpp",
1089        "bionic/langinfo.cpp",
1090        "bionic/lchown.cpp",
1091        "bionic/lfs64_support.cpp",
1092        "bionic/libc_init_common.cpp",
1093        "bionic/libgen.cpp",
1094        "bionic/link.cpp",
1095        "bionic/locale.cpp",
1096        "bionic/lockf.cpp",
1097        "bionic/lstat.cpp",
1098        "bionic/mblen.cpp",
1099        "bionic/mbrtoc16.cpp",
1100        "bionic/mbrtoc32.cpp",
1101        "bionic/mempcpy.cpp",
1102        "bionic/mkdir.cpp",
1103        "bionic/mkfifo.cpp",
1104        "bionic/mknod.cpp",
1105        "bionic/mntent.cpp",
1106        "bionic/mremap.cpp",
1107        "bionic/net_if.cpp",
1108        "bionic/netdb.cpp",
1109        "bionic/netinet_in.cpp",
1110        "bionic/nl_types.cpp",
1111        "bionic/open.cpp",
1112        "bionic/pathconf.cpp",
1113        "bionic/pause.cpp",
1114        "bionic/pidfd.cpp",
1115        "bionic/pipe.cpp",
1116        "bionic/poll.cpp",
1117        "bionic/posix_fadvise.cpp",
1118        "bionic/posix_fallocate.cpp",
1119        "bionic/posix_madvise.cpp",
1120        "bionic/posix_timers.cpp",
1121        "bionic/ptrace.cpp",
1122        "bionic/pty.cpp",
1123        "bionic/raise.cpp",
1124        "bionic/rand.cpp",
1125        "bionic/readlink.cpp",
1126        "bionic/realpath.cpp",
1127        "bionic/reboot.cpp",
1128        "bionic/recv.cpp",
1129        "bionic/recvmsg.cpp",
1130        "bionic/rename.cpp",
1131        "bionic/rmdir.cpp",
1132        "bionic/scandir.cpp",
1133        "bionic/sched_getaffinity.cpp",
1134        "bionic/sched_getcpu.cpp",
1135        "bionic/semaphore.cpp",
1136        "bionic/send.cpp",
1137        "bionic/setegid.cpp",
1138        "bionic/seteuid.cpp",
1139        "bionic/setpgrp.cpp",
1140        "bionic/sigaction.cpp",
1141        "bionic/signal.cpp",
1142        "bionic/sigprocmask.cpp",
1143        "bionic/sleep.cpp",
1144        "bionic/socketpair.cpp",
1145        "bionic/spawn.cpp",
1146        "bionic/stat.cpp",
1147        "bionic/stdlib_l.cpp",
1148        "bionic/strerror.cpp",
1149        "bionic/string_l.cpp",
1150        "bionic/strings_l.cpp",
1151        "bionic/strsignal.cpp",
1152        "bionic/strtol.cpp",
1153        "bionic/strtold.cpp",
1154        "bionic/swab.cpp",
1155        "bionic/symlink.cpp",
1156        "bionic/sync_file_range.cpp",
1157        "bionic/sys_epoll.cpp",
1158        "bionic/sys_msg.cpp",
1159        "bionic/sys_sem.cpp",
1160        "bionic/sys_shm.cpp",
1161        "bionic/sys_signalfd.cpp",
1162        "bionic/sys_statfs.cpp",
1163        "bionic/sys_statvfs.cpp",
1164        "bionic/sys_time.cpp",
1165        "bionic/sysinfo.cpp",
1166        "bionic/syslog.cpp",
1167        "bionic/system.cpp",
1168        "bionic/system_property_api.cpp",
1169        "bionic/system_property_set.cpp",
1170        "bionic/tdestroy.cpp",
1171        "bionic/termios.cpp",
1172        "bionic/thread_private.cpp",
1173        "bionic/threads.cpp",
1174        "bionic/timespec_get.cpp",
1175        "bionic/tmpfile.cpp",
1176        "bionic/umount.cpp",
1177        "bionic/unlink.cpp",
1178        "bionic/usleep.cpp",
1179        "bionic/utmp.cpp",
1180        "bionic/wait.cpp",
1181        "bionic/wchar.cpp",
1182        "bionic/wchar_l.cpp",
1183        "bionic/wcstod.cpp",
1184        "bionic/wctype.cpp",
1185        "bionic/wcwidth.cpp",
1186        "bionic/wmempcpy.cpp",
1187
1188        // This contains a weak stub implementation of __find_icu_symbol for wctype.cpp,
1189        // which will be overridden by the actual one in libc.so.
1190        "bionic/icu_static.cpp",
1191    ],
1192
1193    multilib: {
1194        lib32: {
1195            // LP32 cruft
1196            srcs: ["bionic/mmap.cpp"],
1197        },
1198    },
1199    product_variables: {
1200        treble_linker_namespaces: {
1201            cflags: ["-DTREBLE_LINKER_NAMESPACES"],
1202        },
1203    },
1204    whole_static_libs: [
1205        "libc_bionic_systrace",
1206        "libsystemproperties",
1207    ],
1208    cppflags: ["-Wold-style-cast"],
1209    local_include_dirs: ["stdio"],
1210    include_dirs: ["bionic/libstdc++/include"],
1211    name: "libc_bionic_ndk",
1212    generated_headers: ["generated_android_ids"],
1213}
1214
1215// ========================================================
1216// libc_bionic_systrace.a
1217// ========================================================
1218
1219cc_library_static {
1220    name: "libc_bionic_systrace",
1221    defaults: ["libc_defaults"],
1222    srcs: [
1223        "bionic/bionic_systrace.cpp",
1224    ],
1225    apex_available: [
1226        "com.android.runtime",
1227    ],
1228}
1229
1230// ========================================================
1231// libc_pthread.a - pthreads parts that previously lived in
1232// libc_bionic.a. Relocated to their own library because
1233// they can't be included in libc_ndk.a (as the layout of
1234// pthread_t has changed over the years and has ABI
1235// compatibility issues).
1236// ========================================================
1237
1238cc_library_static {
1239    defaults: ["libc_defaults"],
1240    srcs: [
1241        "bionic/bionic_elf_tls.cpp",
1242        "bionic/pthread_atfork.cpp",
1243        "bionic/pthread_attr.cpp",
1244        "bionic/pthread_barrier.cpp",
1245        "bionic/pthread_cond.cpp",
1246        "bionic/pthread_create.cpp",
1247        "bionic/pthread_detach.cpp",
1248        "bionic/pthread_equal.cpp",
1249        "bionic/pthread_exit.cpp",
1250        "bionic/pthread_getcpuclockid.cpp",
1251        "bionic/pthread_getschedparam.cpp",
1252        "bionic/pthread_gettid_np.cpp",
1253        "bionic/pthread_internal.cpp",
1254        "bionic/pthread_join.cpp",
1255        "bionic/pthread_key.cpp",
1256        "bionic/pthread_kill.cpp",
1257        "bionic/pthread_mutex.cpp",
1258        "bionic/pthread_once.cpp",
1259        "bionic/pthread_rwlock.cpp",
1260        "bionic/pthread_sigqueue.cpp",
1261        "bionic/pthread_self.cpp",
1262        "bionic/pthread_setname_np.cpp",
1263        "bionic/pthread_setschedparam.cpp",
1264        "bionic/pthread_spinlock.cpp",
1265        "bionic/sys_thread_properties.cpp",
1266
1267        // The following implementations depend on pthread data or implementation,
1268        // so we can't include them in libc_ndk.a.
1269        "bionic/__cxa_thread_atexit_impl.cpp",
1270        "bionic/android_unsafe_frame_pointer_chase.cpp",
1271        "bionic/atexit.cpp",
1272        "bionic/fork.cpp",
1273    ],
1274
1275    cppflags: ["-Wold-style-cast"],
1276    include_dirs: ["bionic/libstdc++/include"],
1277    header_libs: ["bionic_libc_platform_headers"],
1278    name: "libc_pthread",
1279}
1280
1281// ========================================================
1282// libc_syscalls.a
1283// ========================================================
1284
1285genrule {
1286    name: "syscalls-arm.S",
1287    out: ["syscalls-arm.S"],
1288    srcs: ["SYSCALLS.TXT"],
1289    tool_files: [":bionic-gensyscalls"],
1290    cmd: "$(location :bionic-gensyscalls) arm $(in) > $(out)",
1291    bazel_module: {
1292        bp2build_available: true,
1293    }
1294}
1295
1296genrule {
1297    name: "syscalls-arm64.S",
1298    out: ["syscalls-arm64.S"],
1299    srcs: ["SYSCALLS.TXT"],
1300    tool_files: [":bionic-gensyscalls"],
1301    cmd: "$(location :bionic-gensyscalls) arm64 $(in) > $(out)",
1302    bazel_module: {
1303        bp2build_available: true,
1304    },
1305}
1306
1307genrule {
1308    name: "syscalls-x86.S",
1309    out: ["syscalls-x86.S"],
1310    srcs: ["SYSCALLS.TXT"],
1311    tool_files: [":bionic-gensyscalls"],
1312    cmd: "$(location :bionic-gensyscalls) x86 $(in) > $(out)",
1313    bazel_module: {
1314        bp2build_available: true,
1315    },
1316}
1317
1318genrule {
1319    name: "syscalls-x86_64.S",
1320    out: ["syscalls-x86_64.S"],
1321    srcs: ["SYSCALLS.TXT"],
1322    tool_files: [":bionic-gensyscalls"],
1323    cmd: "$(location :bionic-gensyscalls) x86_64 $(in) > $(out)",
1324    bazel_module: {
1325        bp2build_available: true,
1326    },
1327}
1328
1329cc_library_static {
1330    defaults: ["libc_defaults"],
1331    srcs: ["bionic/__set_errno.cpp"],
1332    arch: {
1333        arm: {
1334            srcs: [":syscalls-arm.S"],
1335        },
1336        arm64: {
1337            srcs: [":syscalls-arm64.S"],
1338        },
1339        x86: {
1340            srcs: [":syscalls-x86.S"],
1341        },
1342        x86_64: {
1343            srcs: [":syscalls-x86_64.S"],
1344        },
1345    },
1346    name: "libc_syscalls",
1347}
1348
1349// ========================================================
1350// libc_aeabi.a
1351// This is an LP32 ARM-only library that needs to be built with -fno-builtin
1352// to avoid infinite recursion. For the other architectures we just build an
1353// empty library to keep this makefile simple.
1354// ========================================================
1355
1356cc_library_static {
1357    defaults: ["libc_defaults"],
1358    arch: {
1359        arm: {
1360            srcs: ["arch-arm/bionic/__aeabi.c"],
1361        },
1362    },
1363    name: "libc_aeabi",
1364    cflags: ["-fno-builtin"],
1365}
1366
1367// ========================================================
1368// libc_ndk.a
1369// Compatibility library for the NDK. This library contains
1370// all the parts of libc that are safe to statically link.
1371// We can't safely statically link things that can only run
1372// on a certain version of the OS. Examples include
1373// anything that talks to netd (a large portion of the DNS
1374// code) and anything that is dependent on the layout of a
1375// data structure that has changed across releases (such as
1376// pthread_t).
1377// ========================================================
1378
1379cc_library_static {
1380    name: "libc_ndk",
1381    defaults: [
1382        "libc_defaults",
1383        "libc_native_allocator_defaults",
1384    ],
1385    ramdisk_available: false,
1386    vendor_ramdisk_available: false,
1387    srcs: libc_common_src_files + [
1388        "bionic/gwp_asan_wrappers.cpp",
1389        "bionic/heap_tagging.cpp",
1390        "bionic/malloc_common.cpp",
1391        "bionic/malloc_limit.cpp",
1392    ],
1393    multilib: {
1394        lib32: {
1395            srcs: libc_common_src_files_32,
1396        },
1397    },
1398    arch: {
1399        arm: {
1400            srcs: [
1401                "arch-arm/bionic/exidx_dynamic.c",
1402                "arch-common/bionic/crtbegin_so.c",
1403                "arch-arm/bionic/atexit_legacy.c",
1404                "arch-common/bionic/crtend_so.S",
1405            ],
1406            whole_static_libs: ["libc_aeabi"],
1407        },
1408    },
1409
1410    cflags: [
1411        "-fvisibility=hidden",
1412        "-DLIBC_STATIC",
1413    ],
1414
1415    whole_static_libs: [
1416        "gwp_asan",
1417        "libarm-optimized-routines-string",
1418        "libasync_safe",
1419        "libc_bionic_ndk",
1420        "libc_bootstrap",
1421        "libc_fortify",
1422        "libc_freebsd",
1423        "libc_freebsd_large_stack",
1424        "libc_gdtoa",
1425        "libc_netbsd",
1426        "libc_openbsd_large_stack",
1427        "libc_openbsd_ndk",
1428        "libc_syscalls",
1429        "libc_tzcode",
1430        "libm",
1431        "libstdc++",
1432    ],
1433}
1434
1435// ========================================================
1436// libc_nopthread.a
1437// ========================================================
1438cc_library_static {
1439    defaults: ["libc_defaults"],
1440    srcs: libc_common_src_files,
1441    multilib: {
1442        lib32: {
1443            srcs: libc_common_src_files_32,
1444        },
1445    },
1446    name: "libc_nopthread",
1447
1448    whole_static_libs: [
1449        "libarm-optimized-routines-string",
1450        "libasync_safe",
1451        "libc_bionic",
1452        "libc_bionic_ndk",
1453        "libc_bootstrap",
1454        "libc_dns",
1455        "libc_fortify",
1456        "libc_freebsd",
1457        "libc_freebsd_large_stack",
1458        "libc_gdtoa",
1459        "libc_netbsd",
1460        "libc_openbsd",
1461        "libc_openbsd_large_stack",
1462        "libc_openbsd_ndk",
1463        "libc_syscalls",
1464        "libc_tzcode",
1465        "libstdc++",
1466    ],
1467
1468    arch: {
1469        arm: {
1470            whole_static_libs: ["libc_aeabi"],
1471        },
1472    },
1473}
1474
1475// ========================================================
1476// libc_common.a
1477// ========================================================
1478
1479cc_library_static {
1480    defaults: ["libc_defaults"],
1481    name: "libc_common",
1482
1483    whole_static_libs: [
1484        "libc_nopthread",
1485        "libc_pthread",
1486    ],
1487}
1488
1489// ========================================================
1490// libc_static_dispatch.a
1491// ========================================================
1492cc_library_static {
1493    defaults: ["libc_defaults"],
1494    name: "libc_static_dispatch",
1495
1496    arch: {
1497        x86: {
1498            srcs: ["arch-x86/static_function_dispatch.S"],
1499        },
1500        arm: {
1501            srcs: ["arch-arm/static_function_dispatch.S"],
1502        },
1503        arm64: {
1504            srcs: ["arch-arm64/static_function_dispatch.S"],
1505        },
1506    },
1507}
1508
1509// ========================================================
1510// libc_dynamic_dispatch.a
1511// ========================================================
1512cc_library_static {
1513    defaults: ["libc_defaults"],
1514    name: "libc_dynamic_dispatch",
1515
1516    cflags: [
1517        "-ffreestanding",
1518        "-fno-stack-protector",
1519        "-fno-jump-tables",
1520    ],
1521    arch: {
1522        x86: {
1523            srcs: ["arch-x86/dynamic_function_dispatch.cpp"],
1524        },
1525        arm: {
1526            srcs: ["arch-arm/dynamic_function_dispatch.cpp"],
1527        },
1528        arm64: {
1529            srcs: ["arch-arm64/dynamic_function_dispatch.cpp"],
1530        },
1531    },
1532}
1533
1534// ========================================================
1535// libc_common_static.a For static binaries.
1536// ========================================================
1537cc_library_static {
1538    defaults: ["libc_defaults"],
1539    name: "libc_common_static",
1540
1541    whole_static_libs: [
1542        "libc_common",
1543        "libc_static_dispatch",
1544    ],
1545}
1546
1547// ========================================================
1548// libc_common_shared.a For shared libraries.
1549// ========================================================
1550cc_library_static {
1551    defaults: ["libc_defaults"],
1552    name: "libc_common_shared",
1553
1554    whole_static_libs: [
1555        "libc_common",
1556        "libc_dynamic_dispatch",
1557    ],
1558}
1559
1560// Versions of dl_iterate_phdr and similar APIs used to lookup unwinding information in a static
1561// executable.
1562cc_library_static {
1563    name: "libc_unwind_static",
1564    defaults: ["libc_defaults"],
1565    cflags: ["-DLIBC_STATIC"],
1566
1567    srcs: ["bionic/dl_iterate_phdr_static.cpp"],
1568    arch: {
1569        // arm32-specific dl_unwind_find_exidx and __gnu_Unwind_Find_exidx APIs
1570        arm: {
1571            srcs: ["arch-arm/bionic/exidx_static.c"],
1572        },
1573    },
1574}
1575
1576// ========================================================
1577// libc_nomalloc.a
1578// ========================================================
1579//
1580// This is a version of the static C library used by the dynamic linker that exclude malloc. It also
1581// excludes functions selected using ifunc's (e.g. for string.h). Link in either
1582// libc_static_dispatch or libc_dynamic_dispatch to provide those functions.
1583
1584cc_library_static {
1585    name: "libc_nomalloc",
1586    defaults: ["libc_defaults"],
1587
1588    whole_static_libs: [
1589        "libc_common",
1590        "libc_init_static",
1591        "libc_unwind_static",
1592    ],
1593}
1594
1595filegroup {
1596    name: "libc_sources_shared",
1597    srcs: [
1598        "arch-common/bionic/crtbegin_so.c",
1599        "arch-common/bionic/crtbrand.S",
1600        "bionic/gwp_asan_wrappers.cpp",
1601        "bionic/heap_tagging.cpp",
1602        "bionic/icu.cpp",
1603        "bionic/malloc_common.cpp",
1604        "bionic/malloc_common_dynamic.cpp",
1605        "bionic/android_profiling_dynamic.cpp",
1606        "bionic/malloc_heapprofd.cpp",
1607        "bionic/malloc_limit.cpp",
1608        "bionic/ndk_cruft.cpp",
1609        "bionic/ndk_cruft_data.cpp",
1610        "bionic/NetdClient.cpp",
1611        "arch-common/bionic/crtend_so.S",
1612    ],
1613    bazel_module: { bp2build_available: true },
1614}
1615
1616filegroup {
1617    name: "libc_sources_static",
1618    srcs: [
1619        "bionic/gwp_asan_wrappers.cpp",
1620        "bionic/heap_tagging.cpp",
1621        "bionic/malloc_common.cpp",
1622        "bionic/malloc_limit.cpp",
1623    ],
1624    bazel_module: { bp2build_available: true },
1625}
1626
1627filegroup {
1628    name: "libc_sources_shared_arm",
1629    srcs: [
1630        "arch-arm/bionic/exidx_dynamic.c",
1631        "arch-arm/bionic/atexit_legacy.c",
1632    ],
1633    bazel_module: { bp2build_available: true },
1634}
1635
1636// ========================================================
1637// libc.a + libc.so
1638// ========================================================
1639cc_library {
1640    defaults: [
1641        "libc_defaults",
1642        "libc_native_allocator_defaults",
1643    ],
1644    name: "libc",
1645    static_ndk_lib: true,
1646    product_variables: {
1647        platform_sdk_version: {
1648            asflags: ["-DPLATFORM_SDK_VERSION=%d"],
1649        },
1650    },
1651    static: {
1652        srcs: [ ":libc_sources_static" ],
1653        cflags: ["-DLIBC_STATIC"],
1654        whole_static_libs: [
1655            "gwp_asan",
1656            "libc_init_static",
1657            "libc_common_static",
1658            "libc_unwind_static",
1659        ],
1660    },
1661    shared: {
1662        srcs: [ ":libc_sources_shared" ],
1663        whole_static_libs: [
1664            "gwp_asan",
1665            "libc_init_dynamic",
1666            "libc_common_shared",
1667            "libunwind-exported",
1668        ],
1669    },
1670
1671    required: [
1672        "tzdata",
1673        "tz_version", // Version metadata for tzdata to help debugging.
1674    ],
1675
1676    // Do not pack libc.so relocations; see http://b/20645321 for details.
1677    pack_relocations: false,
1678
1679    // WARNING: The only libraries libc.so should depend on are libdl.so and ld-android.so!
1680    // If you add other libraries, make sure to add -Wl,--exclude-libs=libgcc.a to the
1681    // LOCAL_LDFLAGS for those libraries.  This ensures that symbols that are pulled into
1682    // those new libraries from libgcc.a are not declared external; if that were the case,
1683    // then libc would not pull those symbols from libgcc.a as it should, instead relying
1684    // on the external symbols from the dependent libraries.  That would create a "cloaked"
1685    // dependency on libgcc.a in libc though the libraries, which is not what you wanted!
1686
1687    shared_libs: [
1688        "ld-android",
1689        "libdl",
1690    ],
1691    static_libs: [
1692        "libdl_android",
1693    ],
1694
1695    nocrt: true,
1696
1697    arch: {
1698        arm: {
1699            // TODO: This is to work around b/24465209. Remove after root cause is fixed.
1700            pack_relocations: false,
1701            ldflags: ["-Wl,--hash-style=both"],
1702
1703            version_script: ":libc.arm.map",
1704            no_libcrt: true,
1705
1706            shared: {
1707                srcs: [":libc_sources_shared_arm"],
1708                // special for arm
1709                cflags: ["-DCRT_LEGACY_WORKAROUND"],
1710                // For backwards-compatibility, some arm32 builtins are exported from libc.so.
1711                static_libs: ["libclang_rt.builtins-arm-android-exported"],
1712            },
1713
1714            // Arm 32 bit does not produce complete exidx unwind information
1715            // so keep the .debug_frame which is relatively small and does
1716            // include needed unwind information.
1717            // See b/132992102 for details.
1718            strip: {
1719                keep_symbols_and_debug_frame: true,
1720            },
1721        },
1722        arm64: {
1723            version_script: ":libc.arm64.map",
1724
1725            // Leave the symbols in the shared library so that stack unwinders can produce
1726            // meaningful name resolution.
1727            strip: {
1728                keep_symbols: true,
1729            },
1730        },
1731        x86: {
1732            // TODO: This is to work around b/24465209. Remove after root cause is fixed.
1733            pack_relocations: false,
1734            ldflags: ["-Wl,--hash-style=both"],
1735
1736            version_script: ":libc.x86.map",
1737            no_libcrt: true,
1738
1739            shared: {
1740                // For backwards-compatibility, some x86 builtins are exported from libc.so.
1741                static_libs: ["libclang_rt.builtins-i686-android-exported"],
1742            },
1743
1744            // Leave the symbols in the shared library so that stack unwinders can produce
1745            // meaningful name resolution.
1746            strip: {
1747                keep_symbols: true,
1748            },
1749        },
1750        x86_64: {
1751            version_script: ":libc.x86_64.map",
1752
1753            // Leave the symbols in the shared library so that stack unwinders can produce
1754            // meaningful name resolution.
1755            strip: {
1756                keep_symbols: true,
1757            },
1758        },
1759    },
1760
1761    stubs: {
1762        symbol_file: "libc.map.txt",
1763        versions: [
1764            "29",
1765            "R",
1766            "current",
1767        ],
1768    },
1769    llndk: {
1770        symbol_file: "libc.map.txt",
1771        export_headers_as_system: true,
1772        export_preprocessed_headers: ["include"],
1773        export_llndk_headers: ["libc_llndk_headers"],
1774    },
1775    apex_available: [
1776        "//apex_available:platform",
1777        "com.android.runtime",
1778    ],
1779
1780    // Sorting bss symbols by size usually results in less dirty pages at run
1781    // time, because small symbols are grouped together.
1782    sort_bss_symbols_by_size: true,
1783
1784    lto: {
1785        never: true,
1786    },
1787}
1788
1789genrule {
1790    name: "libc.arm.map",
1791    out: ["libc.arm.map"],
1792    srcs: ["libc.map.txt"],
1793    tool_files: [":bionic-generate-version-script"],
1794    cmd: "$(location :bionic-generate-version-script) arm $(in) $(out)",
1795    bazel_module: { bp2build_available: true },
1796}
1797
1798genrule {
1799    name: "libc.arm64.map",
1800    out: ["libc.arm64.map"],
1801    srcs: ["libc.map.txt"],
1802    tool_files: [":bionic-generate-version-script"],
1803    cmd: "$(location :bionic-generate-version-script) arm64 $(in) $(out)",
1804    bazel_module: { bp2build_available: true },
1805}
1806
1807genrule {
1808    name: "libc.x86.map",
1809    out: ["libc.x86.map"],
1810    srcs: ["libc.map.txt"],
1811    tool_files: [":bionic-generate-version-script"],
1812    cmd: "$(location :bionic-generate-version-script) x86 $(in) $(out)",
1813    bazel_module: { bp2build_available: true },
1814}
1815
1816genrule {
1817    name: "libc.x86_64.map",
1818    out: ["libc.x86_64.map"],
1819    srcs: ["libc.map.txt"],
1820    tool_files: [":bionic-generate-version-script"],
1821    cmd: "$(location :bionic-generate-version-script) x86_64 $(in) $(out)",
1822    bazel_module: { bp2build_available: true },
1823}
1824
1825// Headers that only other parts of the platform can include.
1826cc_library_headers {
1827    name: "bionic_libc_platform_headers",
1828    defaults: ["linux_bionic_supported"],
1829    visibility: [
1830        "//art:__subpackages__",
1831        "//bionic:__subpackages__",
1832        "//frameworks:__subpackages__",
1833        "//device/generic/goldfish-opengl:__subpackages__",
1834        "//external/gwp_asan:__subpackages__",
1835        "//external/perfetto:__subpackages__",
1836        "//external/scudo:__subpackages__",
1837        "//system/core/debuggerd:__subpackages__",
1838        "//system/core/libcutils:__subpackages__",
1839        "//system/memory/libmemunreachable:__subpackages__",
1840        "//system/unwinding/libunwindstack:__subpackages__",
1841        "//tools/security/sanitizer-status:__subpackages__",
1842    ],
1843    vendor_available: true,
1844    product_available: true,
1845    ramdisk_available: true,
1846    vendor_ramdisk_available: true,
1847    recovery_available: true,
1848    native_bridge_supported: true,
1849    export_include_dirs: [
1850        "platform",
1851    ],
1852    system_shared_libs: [],
1853    stl: "none",
1854    sdk_version: "current",
1855
1856    min_sdk_version: "29",
1857    apex_available: [
1858        "//apex_available:platform",
1859        "//apex_available:anyapex",
1860    ],
1861    bazel_module: { bp2build_available: true },
1862}
1863
1864cc_library_headers {
1865    name: "libc_llndk_headers",
1866    visibility: ["//visibility:private"],
1867    llndk: {
1868        llndk_headers: true,
1869    },
1870    host_supported: true,
1871    vendor_available: true,
1872    product_available: true,
1873    ramdisk_available: true,
1874    vendor_ramdisk_available: true,
1875    recovery_available: true,
1876    native_bridge_supported: true,
1877    apex_available: [
1878        "//apex_available:platform",
1879        "//apex_available:anyapex",
1880    ],
1881    // used by most APEXes indirectly via libunwind_llvm
1882    min_sdk_version: "apex_inherit",
1883
1884    no_libcrt: true,
1885    stl: "none",
1886    system_shared_libs: [],
1887
1888    // The build system generally requires that any dependencies of a target
1889    // with an sdk_version must have a lower sdk_version. By setting sdk_version
1890    // to 1 we let targets with an sdk_version that need to depend on the libc
1891    // headers but cannot depend on libc itself due to circular dependencies
1892    // (such as libunwind_llvm) depend on the headers. Setting sdk_version to 1
1893    // is correct because the headers can support any sdk_version.
1894    sdk_version: "1",
1895
1896    export_system_include_dirs: [
1897        "kernel/uapi",
1898        "kernel/android/scsi",
1899        "kernel/android/uapi",
1900    ],
1901
1902    arch: {
1903        arm: {
1904            export_system_include_dirs: ["kernel/uapi/asm-arm"],
1905        },
1906        arm64: {
1907            export_system_include_dirs: ["kernel/uapi/asm-arm64"],
1908        },
1909        x86: {
1910            export_system_include_dirs: ["kernel/uapi/asm-x86"],
1911        },
1912        x86_64: {
1913            export_system_include_dirs: ["kernel/uapi/asm-x86"],
1914        },
1915    },
1916    bazel_module: { bp2build_available: true },
1917}
1918
1919cc_library_headers {
1920    name: "libc_headers",
1921    host_supported: true,
1922    native_bridge_supported: true,
1923    vendor_available: true,
1924    product_available: true,
1925    ramdisk_available: true,
1926    vendor_ramdisk_available: true,
1927    recovery_available: true,
1928    sdk_version: "1",
1929
1930    apex_available: [
1931        "//apex_available:platform",
1932        "//apex_available:anyapex",
1933    ],
1934    // used by most APEXes indirectly via libunwind_llvm
1935    min_sdk_version: "apex_inherit",
1936    visibility: [
1937        "//bionic:__subpackages__", // visible to bionic
1938        // ... and only to these places (b/152668052)
1939        "//external/arm-optimized-routines",
1940        "//external/gwp_asan",
1941        "//external/jemalloc_new",
1942        "//external/libunwind_llvm",
1943        "//external/scudo",
1944        "//system/core/property_service/libpropertyinfoparser",
1945        "//system/extras/toolchain-extras",
1946        // TODO(b/153662223): Clean up these users that needed visibility when
1947        // the implicit addition of system Bionic paths was removed.
1948        "//art/tools/cpp-define-generator",
1949        "//external/boringssl",
1950        "//external/minijail",
1951    ],
1952
1953    stl: "none",
1954    no_libcrt: true,
1955    system_shared_libs: [],
1956
1957    target: {
1958        android: {
1959            export_system_include_dirs: ["include"],
1960            header_libs: ["libc_llndk_headers"],
1961            export_header_lib_headers: ["libc_llndk_headers"],
1962        },
1963        linux_bionic: {
1964            export_system_include_dirs: ["include"],
1965            header_libs: ["libc_llndk_headers"],
1966            export_header_lib_headers: ["libc_llndk_headers"],
1967        },
1968    },
1969    bazel_module: { bp2build_available: true },
1970}
1971
1972// ========================================================
1973// libstdc++.so and libstdc++.a.
1974// ========================================================
1975
1976cc_library {
1977    defaults: ["libc_defaults"],
1978    include_dirs: ["bionic/libstdc++/include"],
1979    srcs: [
1980        "bionic/__cxa_guard.cpp",
1981        "bionic/__cxa_pure_virtual.cpp",
1982        "bionic/new.cpp",
1983    ],
1984    name: "libstdc++",
1985    static_ndk_lib: true,
1986    static_libs: ["libasync_safe"],
1987
1988    static: {
1989        system_shared_libs: [],
1990    },
1991    shared: {
1992        system_shared_libs: ["libc"],
1993    },
1994
1995    //TODO (dimitry): This is to work around b/24465209. Remove after root cause is fixed
1996    arch: {
1997        arm: {
1998            // TODO: This is to work around b/24465209. Remove after root cause is fixed.
1999            pack_relocations: false,
2000            ldflags: ["-Wl,--hash-style=both"],
2001            version_script: ":libstdc++.arm.map",
2002        },
2003        arm64: {
2004            version_script: ":libstdc++.arm64.map",
2005        },
2006        x86: {
2007            pack_relocations: false,
2008            ldflags: ["-Wl,--hash-style=both"],
2009            version_script: ":libstdc++.x86.map",
2010        },
2011        x86_64: {
2012            version_script: ":libstdc++.x86_64.map",
2013        },
2014    },
2015}
2016
2017genrule {
2018    name: "libstdc++.arm.map",
2019    out: ["libstdc++.arm.map"],
2020    srcs: ["libstdc++.map.txt"],
2021    tool_files: [":bionic-generate-version-script"],
2022    cmd: "$(location :bionic-generate-version-script) arm $(in) $(out)",
2023}
2024
2025genrule {
2026    name: "libstdc++.arm64.map",
2027    out: ["libstdc++.arm64.map"],
2028    srcs: ["libstdc++.map.txt"],
2029    tool_files: [":bionic-generate-version-script"],
2030    cmd: "$(location :bionic-generate-version-script) arm64 $(in) $(out)",
2031}
2032
2033genrule {
2034    name: "libstdc++.x86.map",
2035    out: ["libstdc++.x86.map"],
2036    srcs: ["libstdc++.map.txt"],
2037    tool_files: [":bionic-generate-version-script"],
2038    cmd: "$(location :bionic-generate-version-script) x86 $(in) $(out)",
2039}
2040
2041genrule {
2042    name: "libstdc++.x86_64.map",
2043    out: ["libstdc++.x86_64.map"],
2044    srcs: ["libstdc++.map.txt"],
2045    tool_files: [":bionic-generate-version-script"],
2046    cmd: "$(location :bionic-generate-version-script) x86_64 $(in) $(out)",
2047}
2048
2049// ========================================================
2050// crt object files.
2051// ========================================================
2052
2053cc_defaults {
2054    name: "crt_defaults",
2055    defaults: ["linux_bionic_supported"],
2056    vendor_available: true,
2057    product_available: true,
2058    ramdisk_available: true,
2059    vendor_ramdisk_available: true,
2060    recovery_available: true,
2061    native_bridge_supported: true,
2062    apex_available: [
2063        "//apex_available:platform",
2064        "//apex_available:anyapex",
2065    ],
2066    // Generate NDK variants of the CRT objects for every supported API level.
2067    min_sdk_version: "16",
2068    stl: "none",
2069    crt: true,
2070    cflags: [
2071        "-Wno-gcc-compat",
2072        "-Wall",
2073        "-Werror",
2074    ],
2075    sanitize: {
2076        never: true,
2077    },
2078}
2079
2080cc_defaults {
2081    name: "crt_so_defaults",
2082    defaults: ["crt_defaults"],
2083
2084    arch: {
2085        x86: {
2086            cflags: ["-fPIC"],
2087        },
2088        x86_64: {
2089            cflags: ["-fPIC"],
2090        },
2091    },
2092    stl: "none",
2093}
2094
2095cc_object {
2096    name: "crtbrand",
2097    // crtbrand.c needs <stdint.h> and a #define for the platform SDK version.
2098    local_include_dirs: [
2099        "include",
2100        "private", // crtbrand.S depends on private/bionic_asm_note.h
2101    ],
2102    product_variables: {
2103        platform_sdk_version: {
2104            asflags: ["-DPLATFORM_SDK_VERSION=%d"],
2105        },
2106    },
2107    srcs: ["arch-common/bionic/crtbrand.S"],
2108
2109    defaults: ["crt_so_defaults"],
2110
2111    bazel_module: { bp2build_available: true },
2112}
2113
2114cc_object {
2115    name: "crtbegin_so",
2116    local_include_dirs: ["include"],
2117    srcs: ["arch-common/bionic/crtbegin_so.c"],
2118
2119    defaults: ["crt_so_defaults"],
2120    objs: [
2121        "crtbrand",
2122    ],
2123
2124    bazel_module: { bp2build_available: true },
2125}
2126
2127cc_object {
2128    name: "crtend_so",
2129    local_include_dirs: [
2130        "include",
2131        "private",  // crtend_so.S depends on private/bionic_asm_arm64.h
2132    ],
2133    srcs: ["arch-common/bionic/crtend_so.S"],
2134
2135    defaults: ["crt_so_defaults"],
2136
2137    bazel_module: { bp2build_available: true },
2138}
2139
2140cc_object {
2141    name: "crtbegin_static",
2142
2143    local_include_dirs: [
2144        "include",
2145        "bionic", // crtbegin.c includes bionic/libc_init_common.h
2146    ],
2147
2148    srcs: ["arch-common/bionic/crtbegin.c"],
2149    objs: [
2150        "crtbrand",
2151    ],
2152    defaults: ["crt_defaults"],
2153    // When using libc.a, we're using the latest library regardless of target API level.
2154    min_sdk_version: "current",
2155
2156    bazel_module: { bp2build_available: true },
2157}
2158
2159cc_object {
2160    name: "crtbegin_dynamic",
2161
2162    local_include_dirs: [
2163        "include",
2164        "bionic", // crtbegin.c includes bionic/libc_init_common.h
2165    ],
2166    srcs: ["arch-common/bionic/crtbegin.c"],
2167    objs: [
2168        "crtbrand",
2169    ],
2170    target: {
2171        linux_bionic: {
2172            generated_sources: ["host_bionic_linker_asm"],
2173            objs: [
2174                "linker_wrapper",
2175            ],
2176        },
2177    },
2178    defaults: ["crt_defaults"],
2179
2180    bazel_module: { bp2build_available: true },
2181}
2182
2183cc_object {
2184    // We rename crtend.o to crtend_android.o to avoid a
2185    // name clash between gcc and bionic.
2186    name: "crtend_android",
2187    local_include_dirs: [
2188        "include",
2189        "private",  // crtend.S depends on private/bionic_asm_arm64.h
2190    ],
2191    srcs: ["arch-common/bionic/crtend.S"],
2192
2193    defaults: ["crt_defaults"],
2194
2195    bazel_module: { bp2build_available: true },
2196}
2197
2198cc_library_static {
2199    name: "note_memtag_heap_async",
2200    arch: {
2201      arm64: {
2202        srcs: ["arch-arm64/bionic/note_memtag_heap_async.S"],
2203      }
2204    },
2205    sdk_version: "minimum",
2206
2207    defaults: ["crt_defaults"],
2208}
2209
2210cc_library_static {
2211    name: "note_memtag_heap_sync",
2212    arch: {
2213      arm64: {
2214        srcs: ["arch-arm64/bionic/note_memtag_heap_sync.S"],
2215      }
2216    },
2217    sdk_version: "minimum",
2218
2219    defaults: ["crt_defaults"],
2220}
2221
2222// ========================================================
2223// NDK headers.
2224// ========================================================
2225
2226versioned_ndk_headers {
2227    name: "common_libc",
2228    from: "include",
2229    to: "",
2230    license: "NOTICE",
2231}
2232
2233ndk_headers {
2234    name: "libc_uapi",
2235    from: "kernel/uapi",
2236    to: "",
2237    srcs: [
2238        "kernel/uapi/asm-generic/**/*.h",
2239        "kernel/uapi/drm/**/*.h",
2240        "kernel/uapi/linux/**/*.h",
2241        "kernel/uapi/misc/**/*.h",
2242        "kernel/uapi/mtd/**/*.h",
2243        "kernel/uapi/rdma/**/*.h",
2244        "kernel/uapi/scsi/**/*.h",
2245        "kernel/uapi/sound/**/*.h",
2246        "kernel/uapi/video/**/*.h",
2247        "kernel/uapi/xen/**/*.h",
2248    ],
2249    license: "NOTICE",
2250}
2251
2252ndk_headers {
2253    name: "libc_kernel_android_uapi_linux",
2254    from: "kernel/android/uapi/linux",
2255    to: "linux",
2256    srcs: ["kernel/android/uapi/linux/**/*.h"],
2257    license: "NOTICE",
2258}
2259
2260ndk_headers {
2261    name: "libc_kernel_android_scsi",
2262    from: "kernel/android/scsi/scsi",
2263    to: "scsi",
2264    srcs: ["kernel/android/scsi/**/*.h"],
2265    license: "NOTICE",
2266}
2267
2268ndk_headers {
2269    name: "libc_asm_arm",
2270    from: "kernel/uapi/asm-arm",
2271    to: "arm-linux-androideabi",
2272    srcs: ["kernel/uapi/asm-arm/**/*.h"],
2273    license: "NOTICE",
2274}
2275
2276ndk_headers {
2277    name: "libc_asm_arm64",
2278    from: "kernel/uapi/asm-arm64",
2279    to: "aarch64-linux-android",
2280    srcs: ["kernel/uapi/asm-arm64/**/*.h"],
2281    license: "NOTICE",
2282}
2283
2284ndk_headers {
2285    name: "libc_asm_x86",
2286    from: "kernel/uapi/asm-x86",
2287    to: "i686-linux-android",
2288    srcs: ["kernel/uapi/asm-x86/**/*.h"],
2289    license: "NOTICE",
2290}
2291
2292ndk_headers {
2293    name: "libc_asm_x86_64",
2294    from: "kernel/uapi/asm-x86",
2295    to: "x86_64-linux-android",
2296    srcs: ["kernel/uapi/asm-x86/**/*.h"],
2297    license: "NOTICE",
2298}
2299
2300ndk_library {
2301    name: "libc",
2302    symbol_file: "libc.map.txt",
2303    first_version: "9",
2304}
2305
2306ndk_library {
2307    name: "libstdc++",
2308    symbol_file: "libstdc++.map.txt",
2309    first_version: "9",
2310}
2311
2312// Export these headers for toolbox to process
2313filegroup {
2314    name: "kernel_input_headers",
2315    srcs: [
2316        "kernel/uapi/linux/input.h",
2317        "kernel/uapi/linux/input-event-codes.h",
2318    ],
2319    bazel_module: { bp2build_available: true },
2320}
2321
2322// Generate a syscall name / number mapping. These objects are text files
2323// (thanks to the -dD -E flags) and not binary files. They will then be
2324// consumed by the genseccomp.py script and converted into C++ code.
2325cc_defaults {
2326    name: "libseccomp_gen_syscall_nrs_defaults",
2327    recovery_available: true,
2328    srcs: ["seccomp/gen_syscall_nrs.cpp"],
2329    cflags: [
2330        "-dD",
2331        "-E",
2332        "-Wall",
2333        "-Werror",
2334        "-nostdinc",
2335    ],
2336}
2337
2338cc_object {
2339    name: "libseccomp_gen_syscall_nrs_arm",
2340    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
2341    local_include_dirs: [
2342        "kernel/uapi/asm-arm",
2343        "kernel/uapi",
2344    ],
2345
2346    bazel_module: { bp2build_available: true },
2347}
2348
2349cc_object {
2350    name: "libseccomp_gen_syscall_nrs_arm64",
2351    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
2352    local_include_dirs: [
2353        "kernel/uapi/asm-arm64",
2354        "kernel/uapi",
2355    ],
2356
2357    bazel_module: { bp2build_available: true },
2358}
2359
2360cc_object {
2361    name: "libseccomp_gen_syscall_nrs_x86",
2362    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
2363    srcs: ["seccomp/gen_syscall_nrs_x86.cpp"],
2364    exclude_srcs: ["seccomp/gen_syscall_nrs.cpp"],
2365    local_include_dirs: [
2366        "kernel/uapi/asm-x86",
2367        "kernel/uapi",
2368    ],
2369
2370    bazel_module: { bp2build_available: true },
2371}
2372
2373cc_object {
2374    name: "libseccomp_gen_syscall_nrs_x86_64",
2375    defaults: ["libseccomp_gen_syscall_nrs_defaults"],
2376    srcs: ["seccomp/gen_syscall_nrs_x86_64.cpp"],
2377    exclude_srcs: ["seccomp/gen_syscall_nrs.cpp"],
2378    local_include_dirs: [
2379        "kernel/uapi/asm-x86",
2380        "kernel/uapi",
2381    ],
2382
2383    bazel_module: { bp2build_available: true },
2384}
2385
2386filegroup {
2387    name: "all_kernel_uapi_headers",
2388    srcs: ["kernel/uapi/**/*.h"],
2389    bazel_module: { bp2build_available: true },
2390}
2391
2392
2393cc_genrule {
2394    name: "func_to_syscall_nrs",
2395    recovery_available: true,
2396    cmd: "$(location genfunctosyscallnrs) --out-dir=$(genDir) $(in)",
2397
2398    tools: [ "genfunctosyscallnrs" ],
2399
2400    srcs: [
2401        "SYSCALLS.TXT",
2402        ":libseccomp_gen_syscall_nrs_arm",
2403        ":libseccomp_gen_syscall_nrs_arm64",
2404        ":libseccomp_gen_syscall_nrs_x86",
2405        ":libseccomp_gen_syscall_nrs_x86_64",
2406    ],
2407
2408    out: [
2409        "func_to_syscall_nrs.h",
2410    ],
2411}
2412
2413// SECCOMP_BLOCKLIST_APP_ZYGOTE.TXT = SECCOMP_BLOCKLIST_APP.txt - setresgid*
2414genrule {
2415    name: "generate_app_zygote_blocklist",
2416    out: ["SECCOMP_BLOCKLIST_APP_ZYGOTE.TXT"],
2417    srcs: ["SECCOMP_BLOCKLIST_APP.TXT"],
2418    cmd: "grep -v '^int[ \t]*setresgid' $(in) > $(out)",
2419}
2420
2421cc_genrule {
2422    name: "libseccomp_policy_app_zygote_sources",
2423    recovery_available: true,
2424    cmd: "$(location genseccomp) --out-dir=$(genDir) --name-modifier=app_zygote $(in)",
2425
2426    tools: [ "genseccomp" ],
2427
2428    srcs: [
2429        "SYSCALLS.TXT",
2430        "SECCOMP_ALLOWLIST_COMMON.TXT",
2431        "SECCOMP_ALLOWLIST_APP.TXT",
2432        "SECCOMP_BLOCKLIST_COMMON.TXT",
2433        "SECCOMP_PRIORITY.TXT",
2434        ":generate_app_zygote_blocklist",
2435        ":libseccomp_gen_syscall_nrs_arm",
2436        ":libseccomp_gen_syscall_nrs_arm64",
2437        ":libseccomp_gen_syscall_nrs_x86",
2438        ":libseccomp_gen_syscall_nrs_x86_64",
2439    ],
2440
2441    out: [
2442        "arm64_app_zygote_policy.cpp",
2443        "arm_app_zygote_policy.cpp",
2444        "x86_64_app_zygote_policy.cpp",
2445        "x86_app_zygote_policy.cpp",
2446    ],
2447}
2448
2449cc_genrule {
2450    name: "libseccomp_policy_app_sources",
2451    recovery_available: true,
2452    cmd: "$(location genseccomp) --out-dir=$(genDir) --name-modifier=app $(in)",
2453
2454    tools: [ "genseccomp" ],
2455
2456    srcs: [
2457        "SYSCALLS.TXT",
2458        "SECCOMP_ALLOWLIST_COMMON.TXT",
2459        "SECCOMP_ALLOWLIST_APP.TXT",
2460        "SECCOMP_BLOCKLIST_COMMON.TXT",
2461        "SECCOMP_BLOCKLIST_APP.TXT",
2462        "SECCOMP_PRIORITY.TXT",
2463        ":libseccomp_gen_syscall_nrs_arm",
2464        ":libseccomp_gen_syscall_nrs_arm64",
2465        ":libseccomp_gen_syscall_nrs_x86",
2466        ":libseccomp_gen_syscall_nrs_x86_64",
2467    ],
2468
2469    out: [
2470        "arm64_app_policy.cpp",
2471        "arm_app_policy.cpp",
2472        "x86_64_app_policy.cpp",
2473        "x86_app_policy.cpp",
2474    ],
2475}
2476
2477cc_genrule {
2478    name: "libseccomp_policy_system_sources",
2479    recovery_available: true,
2480    cmd: "$(location genseccomp) --out-dir=$(genDir) --name-modifier=system $(in)",
2481
2482    tools: [ "genseccomp" ],
2483
2484    srcs: [
2485        "SYSCALLS.TXT",
2486        "SECCOMP_ALLOWLIST_COMMON.TXT",
2487        "SECCOMP_ALLOWLIST_SYSTEM.TXT",
2488        "SECCOMP_BLOCKLIST_COMMON.TXT",
2489        "SECCOMP_PRIORITY.TXT",
2490        ":libseccomp_gen_syscall_nrs_arm",
2491        ":libseccomp_gen_syscall_nrs_arm64",
2492        ":libseccomp_gen_syscall_nrs_x86",
2493        ":libseccomp_gen_syscall_nrs_x86_64",
2494    ],
2495
2496    out: [
2497        "arm64_system_policy.cpp",
2498        "arm_system_policy.cpp",
2499        "x86_64_system_policy.cpp",
2500        "x86_system_policy.cpp",
2501    ],
2502}
2503
2504cc_library {
2505    name: "libseccomp_policy",
2506    recovery_available: true,
2507    generated_headers: ["func_to_syscall_nrs"],
2508    generated_sources: [
2509        "libseccomp_policy_app_sources",
2510        "libseccomp_policy_app_zygote_sources",
2511        "libseccomp_policy_system_sources",
2512    ],
2513
2514    srcs: [
2515        "seccomp/seccomp_policy.cpp",
2516    ],
2517
2518    export_include_dirs: ["seccomp/include"],
2519    cflags: [
2520        "-Wall",
2521        "-Werror",
2522    ],
2523    shared: {
2524        shared_libs: ["libbase"],
2525    },
2526    static: {
2527        static_libs: ["libbase"],
2528    },
2529}
2530
2531subdirs = [
2532    "bionic/scudo",
2533]
2534