| // Build musl libc from source to eventually use as the libc for host modules in the platform build. |
| // The list of sources to compile for each library is loaded from sources.bp, which is generated |
| // by generate_bp.py. |
| |
| package { |
| default_visibility: ["//visibility:private"], |
| default_applicable_licenses: ["musl_license"], |
| } |
| |
| license { |
| name: "musl_license", |
| visibility: [":__subpackages__"], |
| license_kinds: [ |
| "SPDX-license-identifier-MIT", |
| "SPDX-license-identifier-BSD", |
| ], |
| license_text: ["COPYRIGHT"], |
| } |
| |
| cc_library_headers { |
| name: "libc_musl_arch_headers", |
| host_supported: true, |
| device_supported: false, |
| system_shared_libs: [], |
| generated_headers: [ |
| "libc_musl_alltypes.h", |
| "libc_musl_syscall.h", |
| ], |
| export_generated_headers: [ |
| "libc_musl_alltypes.h", |
| "libc_musl_syscall.h", |
| ], |
| export_include_dirs: [ |
| "arch/generic", |
| ], |
| arch: { |
| arm: { |
| export_include_dirs: ["arch/arm"], |
| }, |
| arm64: { |
| export_include_dirs: ["arch/aarch64"], |
| }, |
| x86: { |
| export_include_dirs: ["arch/i386"], |
| }, |
| x86_64: { |
| export_include_dirs: ["arch/x86_64"], |
| }, |
| }, |
| } |
| |
| cc_library_headers { |
| name: "libc_musl_private_headers", |
| host_supported: true, |
| device_supported: false, |
| system_shared_libs: [], |
| generated_headers: [ |
| "libc_musl_version.h", |
| ], |
| export_generated_headers: [ |
| "libc_musl_version.h", |
| ], |
| export_include_dirs: [ |
| "src/include", |
| "src/internal", |
| ], |
| } |
| |
| cc_library_headers { |
| name: "libc_musl_public_headers", |
| host_supported: true, |
| device_supported: false, |
| system_shared_libs: [], |
| export_system_include_dirs: [ |
| "android/include", |
| "include", |
| ], |
| } |
| |
| cc_defaults { |
| name: "libc_musl_defaults", |
| host_supported: true, |
| device_supported: false, |
| system_shared_libs: [], |
| cflags: [ |
| // CFLAGS_C99FSE |
| "-nostdinc", |
| "-ffreestanding", |
| "-frounding-math", |
| "-Wa,--noexecstack", |
| |
| // CFLAGS_AUTO |
| //"-Os", |
| "-O0", |
| "-pipe", |
| "-fomit-frame-pointer", |
| "-fno-unwind-tables", |
| "-fno-asynchronous-unwind-tables", |
| "-ffunction-sections", |
| "-fdata-sections", |
| //"-w", |
| "-Wno-pointer-to-int-cast", |
| "-Werror=implicit-function-declaration", |
| "-Werror=implicit-int", |
| "-Werror=pointer-sign", |
| "-Werror=pointer-arith", |
| "-Werror=int-conversion", |
| "-Werror=incompatible-pointer-types", |
| "-Qunused-arguments", |
| "-Waddress", |
| "-Warray-bounds", |
| "-Wchar-subscripts", |
| "-Wduplicate-decl-specifier", |
| "-Winit-self", |
| "-Wreturn-type", |
| "-Wsequence-point", |
| "-Wstrict-aliasing", |
| "-Wunused-function", |
| "-Wunused-label", |
| "-Wunused-variable", |
| |
| // CFLAGS_ALL |
| "-D_XOPEN_SOURCE=700", |
| |
| // undefine NDEBUG from global flags, musl defines it locally |
| "-UNDEBUG", |
| |
| // disable warnings: |
| "-Wno-bitwise-op-parentheses", |
| "-Wno-dangling-else", |
| "-Wno-ignored-attributes", |
| "-Wno-logical-op-parentheses", |
| "-Wno-missing-braces", |
| "-Wno-missing-field-initializers", |
| "-Wno-parentheses", |
| "-Wno-shift-op-parentheses", |
| "-Wno-string-plus-int", |
| "-Wno-unused-parameter", |
| ], |
| |
| ldflags: [ |
| "-Wl,--sort-section,alignment", |
| "-Wl,--sort-common", |
| "-Wl,--gc-sections", |
| "-Wl,--hash-style=both", |
| "-Wl,--no-undefined", |
| // Can't use --exclude-libs=ALL, that excludes the static libraries |
| // used for building subparts of libc_musl. |
| //"-Wl,--exclude-libs=ALL", |
| "-Wl,--exclude-libs=libgcc.a", |
| "-Wl,--exclude-libs=libgcc_stripped.a", |
| "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", |
| "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", |
| "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", |
| "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", |
| ], |
| |
| asflags: ["-Wno-unused-command-line-argument"], |
| |
| header_libs: [ |
| // The order here is very important, private headers like src/include/features.h override |
| // public headers like include/features.h, and arch headers like arch/x86_64/ksigaction.h |
| // override private headers like src/internal/ksigaction.h. |
| "libc_musl_arch_headers", |
| "libc_musl_private_headers", |
| "libc_musl_public_headers", |
| ], |
| |
| stl: "none", |
| c_std: "c99", |
| sanitize: { |
| never: true, |
| }, |
| target: { |
| darwin: { |
| enabled: false, |
| }, |
| bionic: { |
| enabled: false, |
| }, |
| }, |
| } |
| |
| // |
| // The main musl libc library |
| // |
| |
| cc_library { |
| name: "libc_musl", |
| visibility: ["//visibility:public"], |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_sources", |
| ], |
| whole_static_libs: [ |
| "libc_musl_opt", |
| "libc_musl_opt_nossp", |
| "libc_musl_nossp", |
| ], |
| shared: { |
| whole_static_libs: ["libc_musl_ldso"], |
| }, |
| multilib: { |
| lib32: { |
| whole_static_libs: ["libc_musl_compat32"], |
| }, |
| }, |
| ldflags: [ |
| "-Wl,-e,_dlstart", |
| "-nostdlib", |
| ], |
| dynamic_list: "dynamic.list", |
| export_header_lib_headers: [ |
| "libc_musl_arch_headers", |
| "libc_musl_public_headers", |
| "libc_llndk_headers", |
| ], |
| header_libs: [ |
| "libc_llndk_headers", |
| ], |
| } |
| |
| // Musl sources that are compiled with -O3 |
| cc_library_static { |
| name: "libc_musl_opt", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_opt_sources", |
| ], |
| cflags: ["-O3"], |
| } |
| |
| // Musl sources that are compiled with -O3 and -fno-stack-protector |
| cc_library_static { |
| name: "libc_musl_opt_nossp", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_opt_nossp_sources", |
| ], |
| cflags: [ |
| "-O3", |
| "-fno-stack-protector", |
| ], |
| } |
| |
| // Musl sources that are compiled with -fno-stack-protector |
| cc_library_static { |
| name: "libc_musl_nossp", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_nossp_sources", |
| ], |
| cflags: ["-fno-stack-protector"], |
| } |
| |
| // Musl sources for 32-bit architectures |
| cc_library_static { |
| name: "libc_musl_compat32", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_compat32_sources", |
| ], |
| } |
| |
| // Musl sources for the dynamic linker. |
| cc_library_static { |
| name: "libc_musl_ldso", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_ldso_sources", |
| ], |
| cflags: [ |
| "-fno-stack-protector", |
| "-DLIBC_SONAME=libc_musl.so", |
| ], |
| } |
| |
| // An attempt to compile the dynamic linker as a standalone library separate from libc_musl.so. |
| // Not used yet. |
| cc_library_shared { |
| name: "musl_linker", |
| defaults: [ |
| "libc_musl_defaults", |
| ], |
| nocrt: true, |
| static_libs: [ |
| "libc_musl_ldso", |
| "libc_musl", |
| ], |
| ldflags: [ |
| "-Wl,-e,_dlstart", |
| "-nostdlib", |
| "-Wl,--exclude-libs=libc_musl.a", |
| ], |
| } |
| |
| // Convert the linker (which is actually libc_musl.so) into a .s file for embedding in crtbegin. |
| cc_genrule { |
| name: "musl_linker_asm", |
| host_supported: true, |
| device_supported: false, |
| tools: ["extract_linker"], |
| cmd: "$(location) -s $(out) $(in)", |
| srcs: [":libc_musl"], |
| out: ["linker.s"], |
| target: { |
| darwin: { |
| enabled: false, |
| }, |
| bionic: { |
| enabled: false, |
| }, |
| }, |
| } |
| |
| // Convert the linker (which is actually libc_musl.so) into a linker script for embedding in |
| // crtbegin. |
| cc_genrule { |
| name: "musl_linker_script", |
| visibility: ["//visibility:public"], |
| host_supported: true, |
| device_supported: false, |
| tools: ["extract_linker"], |
| cmd: "$(location) -T $(out) $(in)", |
| srcs: [":libc_musl"], |
| out: ["linker.script"], |
| target: { |
| darwin: { |
| enabled: false, |
| }, |
| bionic: { |
| enabled: false, |
| }, |
| }, |
| } |
| |
| // |
| // The musl CRT objects |
| // |
| |
| cc_object { |
| name: "libc_musl_crt1", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_crt1_sources", |
| ], |
| } |
| |
| cc_object { |
| name: "libc_musl_crti", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_crti_sources", |
| ], |
| } |
| |
| cc_object { |
| name: "libc_musl_crtn", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_crtn_sources", |
| ], |
| } |
| |
| cc_object { |
| name: "libc_musl_rcrt1", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_rcrt1_sources", |
| ], |
| } |
| |
| cc_object { |
| name: "libc_musl_Scrt1", |
| defaults: [ |
| "libc_musl_defaults", |
| "libc_musl_Scrt1_sources", |
| ], |
| } |
| |
| // |
| // The custom CRT objects for use in the platform build. |
| // Embeds the linker into crtbegin_dynamic. |
| // |
| |
| cc_object { |
| name: "libc_musl_crtbegin_dynamic", |
| defaults: ["libc_musl_defaults"], |
| visibility: ["//visibility:public"], |
| objs: [ |
| "libc_musl_crt1", |
| "libc_musl_crti", |
| "clang_rt.crtbegin", |
| ], |
| srcs: [ |
| ":musl_linker_asm", |
| "android/ldso_trampoline.cpp", |
| ], |
| cflags: [ |
| // These are required to make sure the C code in ldso_trampoline.c |
| // doesn't have any dependencies on libc. |
| "-fno-stack-protector", |
| "-ftrivial-auto-var-init=uninitialized", |
| ], |
| } |
| |
| cc_object { |
| name: "libc_musl_crtbegin_static", |
| defaults: ["libc_musl_defaults"], |
| visibility: ["//visibility:public"], |
| objs: [ |
| "libc_musl_Scrt1", |
| "libc_musl_crti", |
| "clang_rt.crtbegin", |
| ], |
| } |
| |
| cc_object { |
| name: "libc_musl_crtend", |
| defaults: ["libc_musl_defaults"], |
| visibility: ["//visibility:public"], |
| objs: [ |
| "clang_rt.crtend", |
| "libc_musl_crtn", |
| ], |
| } |
| |
| cc_object { |
| name: "libc_musl_crtbegin_so", |
| defaults: ["libc_musl_defaults"], |
| visibility: ["//visibility:public"], |
| objs: [ |
| "libc_musl_crti", |
| "clang_rt.crtbegin", |
| ], |
| } |
| |
| cc_object { |
| name: "libc_musl_crtend_so", |
| defaults: ["libc_musl_defaults"], |
| visibility: ["//visibility:public"], |
| objs: [ |
| "clang_rt.crtend", |
| "libc_musl_crtn", |
| ], |
| } |
| |
| // |
| // Tests for the embedded linker trampoline |
| // |
| |
| cc_test_host { |
| name: "libc_musl_ldso_trampoline_test", |
| srcs: ["android/ldso_trampoline_test.cpp"], |
| stl: "libc++", |
| target: { |
| darwin: { |
| enabled: false, |
| }, |
| }, |
| } |
| |
| // |
| // Generated headers |
| // |
| |
| genrule { |
| name: "libc_musl_version.h", |
| srcs: ["VERSION"], |
| out: ["version.h"], |
| cmd: "printf '#define VERSION \"%s\"\n' \"$$(cat $(location VERSION))\" > $(out)", |
| } |
| |
| // libc_musl_arch_alltypes.h is split out of libc_musl_alltypes.h to ensure the arch-specific |
| // alltypes.h.in ends up before the generic alltypes.h.in in the output. |
| cc_genrule { |
| name: "libc_musl_arch_alltypes.h", |
| host_supported: true, |
| device_supported: false, |
| arch: { |
| arm: { |
| srcs: ["arch/arm/bits/alltypes.h.in"], |
| }, |
| arm64: { |
| srcs: ["arch/aarch64/bits/alltypes.h.in"], |
| }, |
| x86: { |
| srcs: ["arch/i386/bits/alltypes.h.in"], |
| }, |
| x86_64: { |
| srcs: ["arch/x86_64/bits/alltypes.h.in"], |
| }, |
| }, |
| tool_files: ["tools/mkalltypes.sed"], |
| out: ["bits/alltypes.h"], |
| cmd: "sed -f $(location tools/mkalltypes.sed) $(in) > $(out)", |
| } |
| |
| cc_genrule { |
| name: "libc_musl_alltypes.h", |
| host_supported: true, |
| device_supported: false, |
| srcs: [ |
| "include/alltypes.h.in", |
| ":libc_musl_arch_alltypes.h", |
| ], |
| tool_files: ["tools/mkalltypes.sed"], |
| out: ["bits/alltypes.h"], |
| cmd: "( " + |
| "cat $(location :libc_musl_arch_alltypes.h) && " + |
| "sed -f $(location tools/mkalltypes.sed) $(location include/alltypes.h.in) " + |
| ") > $(out)", |
| } |
| |
| cc_genrule { |
| name: "libc_musl_syscall.h", |
| host_supported: true, |
| device_supported: false, |
| arch: { |
| arm: { |
| srcs: ["arch/arm/bits/syscall.h.in"], |
| }, |
| arm64: { |
| srcs: ["arch/aarch64/bits/syscall.h.in"], |
| }, |
| x86: { |
| srcs: ["arch/i386/bits/syscall.h.in"], |
| }, |
| x86_64: { |
| srcs: ["arch/x86_64/bits/syscall.h.in"], |
| }, |
| }, |
| out: ["bits/syscall.h"], |
| cmd: "cp $(in) $(out) && sed -n -e s/__NR_/SYS_/p < $(in) >> $(out)", |
| } |
| |
| build=["sources.bp"] |