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