1import("//base/startup/init/begetd.gni") 2import("//build/config/clang/clang.gni") 3import("//build/ohos.gni") 4import("//third_party/FreeBSD/FreeBSD.gni") 5import("//third_party/optimized-routines/optimized-routines.gni") 6import("musl_src.gni") 7template("musl_libs") { 8 no_default_deps = true 9 10 forward_variables_from(invoker, [ "*" ]) 11 12 _libs_path_prefix = "." 13 _libs_out_dir = "usr/lib/${musl_target_triple}" 14 15 dfx_deps = [ "//base/hiviewdfx/faultloggerd/interfaces/innerkits/signal_handler:dfxsignalhandler" ] 16 porting_deps = [ 17 "//third_party/musl:create_alltypes_h", 18 "//third_party/musl:create_porting_src", 19 "//third_party/musl:create_syscall_h", 20 "//third_party/musl:create_version_h", 21 ] 22 23 group(target_name) { 24 deps = [ 25 ":soft_create_linker", 26 ":soft_libc_musl_shared", 27 ":soft_libc_musl_static", 28 ":soft_musl_crt_libs", 29 ] 30 } 31 32 group("soft_shared_libs") { 33 deps = [ 34 ":musl_headers", 35 ":soft_libc_musl_shared", 36 ":soft_libcrypt", 37 ":soft_libdl", 38 ":soft_libm", 39 ":soft_libpthread", 40 ":soft_libresolv", 41 ":soft_librt", 42 ":soft_libutil", 43 ":soft_libxnet", 44 ":soft_musl_crt_libs", 45 ] 46 } 47 48 group("soft_static_libs") { 49 deps = [ 50 ":musl_headers", 51 ":soft_libc_musl_static", 52 ":soft_libcrypt", 53 ":soft_libdl", 54 ":soft_libm", 55 ":soft_libpthread", 56 ":soft_libresolv", 57 ":soft_librt", 58 ":soft_libutil", 59 ":soft_libxnet", 60 ":soft_musl_crt_libs", 61 ] 62 } 63 64 group("soft_musl_crt_libs") { 65 deps = [ ":soft_musl_crt_install_action" ] 66 } 67 68 # part of default_compiler_configs from build/config/BUILDCONFIG.gn 69 musl_inherited_configs = [ 70 "//build/config/compiler:afdo", 71 "//build/config/compiler:afdo_optimize_size", 72 "//build/config/compiler:compiler", 73 "//build/config/compiler:compiler_arm_fpu", 74 "//build/config/compiler:compiler_arm_thumb", 75 "//build/config/compiler:chromium_code", 76 "//build/config/compiler:default_include_dirs", 77 "//build/config/compiler:default_optimization", 78 "//build/config/compiler:default_stack_frames", 79 "//build/config/compiler:default_symbols", 80 "//build/config/compiler:export_dynamic", 81 "//build/config/compiler:no_exceptions", 82 "//build/config/compiler:no_rtti", 83 "//build/config/compiler:runtime_library", 84 "//build/config/compiler:thin_archive", 85 "//build/config/sanitizers:default_sanitizer_flags", 86 ] 87 88 config("soft_musl_config") { 89 configs = [ 90 "//build/config/compiler:compiler_cpu_abi", 91 "//build/config/coverage:default_coverage", 92 ] 93 94 include_dirs = [ 95 "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}", 96 "${target_out_dir}/${musl_ported_dir}/arch/generic", 97 "${target_out_dir}/${musl_ported_dir}/src/internal", 98 "${target_out_dir}/${musl_ported_dir}/src/include", 99 "${target_out_dir}/${musl_ported_dir}/include", 100 "${target_out_dir}/${musl_inc_out_dir}", 101 ] 102 103 cflags_basic = [ 104 "--target=${musl_target_triple}", 105 "-Wall", 106 "-Wl,-z,relro,-z,now,-z,noexecstack", 107 ] 108 109 if (musl_arch == "arm") { 110 cflags_basic += [ "-mtp=cp15" ] 111 } else if (musl_arch == "aarch64") { 112 } 113 114 cflags_auto = [ 115 "-D_XOPEN_SOURCE=700", 116 "-g", 117 "-pipe", 118 "-fno-omit-frame-pointer", 119 "-funwind-tables", 120 "-fasynchronous-unwind-tables", 121 "-ffunction-sections", 122 "-fdata-sections", 123 "-Werror=implicit-function-declaration", 124 "-Werror=implicit-int", 125 "-Werror=pointer-sign", 126 "-Werror=pointer-arith", 127 "-Qunused-arguments", 128 "-Wno-int-conversion", 129 ] 130 131 if (!is_asan) { 132 cflags_auto += [ 133 "-DHOOK_ENABLE", 134 "-DOHOS_SOCKET_HOOK_ENABLE", 135 ] 136 } 137 138 if (use_pthread_cancel) { 139 cflags_auto += [ "-DFEATURE_PTHREAD_CANCEL" ] 140 } 141 142 cflags_auto += [ "-DRESERVE_SIGNAL_STACK" ] 143 cflags_auto += [ "-DDFX_SIGNAL_LIBC" ] 144 145 cflags_c99fse = [ 146 "-std=c99", 147 "-nostdinc", 148 "-Wa,--noexecstack", 149 ] 150 151 cflags_all = cflags_basic + cflags_c99fse + cflags_auto 152 153 cflags = cflags_all 154 155 defines = [ "BROKEN_VFP_ASM" ] 156 defines += [ "FEATURE_ATEXIT_CB_PROTECT" ] 157 if (is_standard_system) { 158 defines += [ 159 "OHOS_DNS_PROXY_BY_NETSYS=1", 160 "OHOS_PERMISSION_INTERNET=1", 161 "OHOS_DISABLE_IPV6=0", 162 ] 163 } 164 165 if (!is_standard_system && defined(enable_musl_log)) { 166 if (enable_musl_log) { 167 defines += [ "ENABLE_MUSL_LOG" ] 168 } 169 } 170 171 dynamic_list = 172 rebase_path("${target_out_dir}/${musl_ported_dir}/dynamic.list") 173 174 ldflags = cflags_all 175 ldflags += [ 176 "--target=${musl_target_triple}", 177 "-fuse-ld=lld", 178 "-Wl,--sort-section,alignment", 179 "-Wl,--sort-common", 180 "-Wl,--gc-sections", 181 "-Wl,--hash-style=both", 182 "-Wl,--no-undefined", 183 "-Wl,--exclude-libs=ALL", 184 "-Wl,--dynamic-list=${dynamic_list}", 185 ] 186 asmflags = cflags 187 } 188 189 config("soft_hook") { 190 defines = [] 191 configs = [ "//build/config/coverage:default_coverage" ] 192 193 if (is_posix) { 194 configs += [ "//build/config/posix:runtime_library" ] 195 } 196 197 cflags_cc = [] 198 199 defines = [ 200 "__GNU_SOURCE=1", # Necessary for clone(). 201 "CHROMIUM_CXX_TWEAK_INLINES", # Saves binary size. 202 ] 203 204 defines += [ 205 "__MUSL__", 206 "_LIBCPP_HAS_MUSL_LIBC", 207 "__BUILD_LINUX_WITH_CLANG", 208 ] 209 210 if (!is_asan) { 211 defines += [ 212 "HOOK_ENABLE", 213 "OHOS_SOCKET_HOOK_ENABLE", 214 ] 215 } 216 ldflags = [ "-nostdlib" ] 217 218 libs = [] 219 220 if (is_component_build) { 221 defines += [ "COMPONENT_BUILD" ] 222 } 223 } 224 225 config("soft_jemalloc") { 226 configs = [ "//build/config/coverage:default_coverage" ] 227 228 include_dirs = [ 229 "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}", 230 "${target_out_dir}/${musl_ported_dir}/arch/generic", 231 "${target_out_dir}/${musl_ported_dir}/src/internal", 232 "${target_out_dir}/${musl_ported_dir}/src/include", 233 "${target_out_dir}/${musl_ported_dir}/include", 234 "${target_out_dir}/${musl_inc_out_dir}", 235 "${clang_base_path}/lib/clang/${clang_version}/include", 236 ] 237 238 cflags = [ 239 "--target=${musl_target_triple}", 240 "-D_GNU_SOURCE", 241 "-D_REENTRANT", 242 "-Wall", 243 "-Wshorten-64-to-32", 244 "-Wsign-compare", 245 "-Wundef", 246 "-Wno-format-zero-length", 247 "-pipe", 248 "-g3", 249 "-fvisibility=hidden", 250 "-O3", 251 "-funroll-loops", 252 "-funwind-tables", 253 254 # The following flags are for avoiding errors when compiling. 255 "-Wno-unused-parameter", 256 "-Wno-unused-function", 257 "-Wno-missing-field-initializers", 258 259 "-U_FORTIFY_SOURCE", 260 261 "-DOHOS_ENABLE_TCACHE", # For jemalloc 5.X 262 "-DJEMALLOC_TCACHE", # For jemalloc 4.X 263 "-DOHOS_LG_TCACHE_MAXCLASS_DEFAULT=16", 264 "-DOHOS_NUM_ARENAS=2", # For jemalloc 5.X 265 "-DOHOS_MAX_ARENAS=2", # For jemalloc 4.X 266 "-DOHOS_TCACHE_NSLOTS_SMALL_MAX=8", 267 "-DOHOS_TCACHE_NSLOTS_LARGE=16", 268 ] 269 270 if (is_debug || musl_secure_level > 1) { 271 cflags += [ "-DOHOS_TCACHE_NSLOTS_RANDOM" ] 272 } 273 274 if (musl_arch == "arm") { 275 cflags += [ 276 "-march=armv7-a", 277 "-DOHOS_LG_CHUNK_DEFAULT=19", # For jemalloc 4.X 278 ] 279 } else if (musl_arch == "aarch64") { 280 cflags += [ 281 "-march=armv8", 282 "-DOHOS_LG_CHUNK_DEFAULT=19", # For jemalloc 4.X 283 ] 284 } else if (musl_arch == "x86_64") { 285 cflags += [ "-march=x86-64" ] 286 } 287 288 include_dirs += [ 289 "//third_party", 290 "//third_party/musl/src/include/", 291 "${musl_malloc_plugin}/include/", 292 "${musl_malloc_plugin}/include/jemalloc/internal", 293 "${musl_malloc_plugin}/include/jemalloc", 294 ] 295 } 296 297 source_set("soft_musl_crt") { 298 sources = [ 299 "${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/crti.s", 300 "${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/crtn.s", 301 "${target_out_dir}/${musl_ported_dir}/crt/Scrt1.c", 302 "${target_out_dir}/${musl_ported_dir}/crt/crt1.c", 303 "${target_out_dir}/${musl_ported_dir}/crt/crtplus.c", 304 "${target_out_dir}/${musl_ported_dir}/crt/rcrt1.c", 305 ] 306 307 defines = [ "CRT" ] 308 309 configs -= musl_inherited_configs 310 configs += [ ":soft_musl_config" ] 311 cflags = [ 312 "-fPIC", 313 "-ffreestanding", 314 "-fno-stack-protector", 315 ] 316 317 deps = porting_deps 318 319 asmflags = cflags 320 } 321 322 source_set("soft_musl_src") { 323 sources_orig = [] 324 sources = [] 325 326 sources_orig = musl_src_arch_file + musl_src_file 327 sources_orig -= musl_src_filterout 328 sources_orig -= [ 329 "src/string/mempcpy.c", 330 "src/string/memset.c", 331 "src/env/__init_tls.c", 332 "src/env/__libc_start_main.c", 333 "src/env/__stack_chk_fail.c", 334 "src/stdlib/qsort.c", 335 "src/stdlib/qsort_nr.c", 336 ] 337 338 sources += [ 339 "$FREEBSD_DIR/contrib/tcp_wrappers/strcasecmp.c", 340 "$FREEBSD_DIR/lib/libc/stdlib/qsort.c", 341 ] 342 343 if (musl_arch == "arm") { 344 sources_orig -= [ 345 "src/thread/${musl_arch}/__set_thread_area.c", 346 "src/string/arm/memcpy.S", 347 "src/string/memchr.c", 348 "src/string/strcmp.c", 349 "src/string/strlen.c", 350 "src/math/sincosf.c", 351 "src/math/expf.c", 352 "src/math/exp2f.c", 353 "src/math/exp2l.c", 354 "src/math/exp2.c", 355 "src/math/log.c", 356 "src/math/logl.c", 357 "src/math/log2.c", 358 "src/math/log2f.c", 359 "src/math/log2l.c", 360 "src/math/logf.c", 361 "src/math/log_data.c", 362 "src/math/logf_data.c", 363 "src/math/log2_data.c", 364 "src/math/log2f_data.c", 365 "src/math/exp2f_data.c", 366 "src/math/pow.c", 367 "src/math/powf.c", 368 "src/math/powl.c", 369 "src/math/sinf.c", 370 "src/math/cosf.c", 371 ] 372 } else if (musl_arch == "aarch64") { 373 sources_orig -= [ 374 "src/thread/${musl_arch}/__set_thread_area.s", 375 "src/string/memcpy.c", 376 "src/string/memmove.c", 377 "src/string/memchr.c", 378 "src/string/memcmp.c", 379 "src/string/strcpy.c", 380 "src/string/strcmp.c", 381 "src/string/strlen.c", 382 "src/string/stpcpy.c", 383 "src/string/strchr.c", 384 "src/string/strrchr.c", 385 "src/string/strnlen.c", 386 "src/string/strncmp.c", 387 "src/math/sincosf.c", 388 "src/math/sinf.c", 389 "src/math/cosf.c", 390 "src/math/cos.c", 391 "src/math/exp.c", 392 "src/math/exp2.c", 393 "src/math/exp2f.c", 394 "src/math/expf.c", 395 "src/math/log.c", 396 "src/math/log10.c", 397 "src/math/log2.c", 398 "src/math/log2f.c", 399 "src/math/logb.c", 400 "src/math/logf.c", 401 "src/math/sin.c", 402 "src/math/sincos.c", 403 "src/math/pow.c", 404 "src/math/powf.c", 405 ] 406 } else if (musl_arch == "x86_64") { 407 sources_orig -= [ "src/thread/${musl_arch}/__set_thread_area.s" ] 408 } 409 410 defines = [] 411 if (musl_arch == "arm") { 412 defines += [ "MUSL_ARM_ARCH" ] 413 } 414 if (musl_arch == "aarch64") { 415 defines += [ "MUSL_AARCH64_ARCH" ] 416 } 417 if (musl_arch == "x86_64") { 418 defines += [ "MUSL_X86_64_ARCH" ] 419 } 420 if (musl_secure_level > 0) { 421 defines += [ "MALLOC_FREELIST_HARDENED" ] 422 } 423 if (musl_secure_level > 1) { 424 defines += [ "MALLOC_FREELIST_QUARANTINE" ] 425 } 426 if (musl_secure_level > 2) { 427 defines += [ "MALLOC_RED_ZONE" ] 428 } 429 if (is_debug || musl_secure_level >= 3) { 430 defines += [ "MALLOC_SECURE_ALL" ] 431 } 432 433 if (musl_iterate_and_stats_api) { 434 defines += [ "MUSL_ITERATE_AND_STATS_API" ] 435 } 436 437 foreach(s, sources_orig) { 438 sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] 439 } 440 if (musl_arch == "arm") { 441 sources += [ 442 "$OPTRTDIR/math/cosf.c", 443 "$OPTRTDIR/math/exp2.c", 444 "$OPTRTDIR/math/exp2f.c", 445 "$OPTRTDIR/math/exp2f_data.c", 446 "$OPTRTDIR/math/expf.c", 447 "$OPTRTDIR/math/log.c", 448 "$OPTRTDIR/math/log2.c", 449 "$OPTRTDIR/math/log2_data.c", 450 "$OPTRTDIR/math/log2f.c", 451 "$OPTRTDIR/math/log2f_data.c", 452 "$OPTRTDIR/math/log_data.c", 453 "$OPTRTDIR/math/logf.c", 454 "$OPTRTDIR/math/logf_data.c", 455 "$OPTRTDIR/math/pow.c", 456 "$OPTRTDIR/math/powf.c", 457 "$OPTRTDIR/math/sincosf.c", 458 "$OPTRTDIR/math/sincosf_data.c", 459 "$OPTRTDIR/math/sinf.c", 460 "$OPTRTDIR/string/arm/memchr.S", 461 "$OPTRTDIR/string/arm/memcpy.S", 462 "$OPTRTDIR/string/arm/memset.S", 463 "$OPTRTDIR/string/arm/strcmp.S", 464 "$OPTRTDIR/string/arm/strlen-armv6t2.S", 465 ] 466 467 sources += added_freebsd_files 468 asmflags = [ 469 "-D__memcpy_arm = memcpy", 470 "-D__memchr_arm = memchr", 471 "-D__memset_arm = memset", 472 "-D__strcmp_arm = strcmp", 473 "-D__strlen_armv6t2 = strlen", 474 ] 475 } else if (musl_arch == "aarch64") { 476 if (defined(ARM_FEATURE_SVE)) { 477 sources += [ 478 "$OPTRTDIR/string/aarch64/memchr-sve.S", 479 "$OPTRTDIR/string/aarch64/memcmp-sve.S", 480 "$OPTRTDIR/string/aarch64/memcpy.S", 481 "$OPTRTDIR/string/aarch64/memset.S", 482 "$OPTRTDIR/string/aarch64/stpcpy-sve.S", 483 "$OPTRTDIR/string/aarch64/strchr-sve.S", 484 "$OPTRTDIR/string/aarch64/strchrnul-sve.S", 485 "$OPTRTDIR/string/aarch64/strcmp-sve.S", 486 "$OPTRTDIR/string/aarch64/strcpy-sve.S", 487 "$OPTRTDIR/string/aarch64/strlen-sve.S", 488 "$OPTRTDIR/string/aarch64/strncmp-sve.S", 489 "$OPTRTDIR/string/aarch64/strnlen-sve.S", 490 "$OPTRTDIR/string/aarch64/strrchr-sve.S", 491 ] 492 asmflags = [ 493 "-D__memcpy_aarch64 = memcpy", 494 "-D__memset_aarch64 = memset", 495 "-D__memcmp_aarch64_sve = memcmp", 496 "-D__memchr_aarch64_sve = memchr", 497 "-D__strcmp_aarch64_sve = strcmp", 498 "-D__strlen_aarch64_sve = strlen", 499 "-D__strcpy_aarch64_sve = strcpy", 500 "-D__stpcpy_aarch64_sve = stpcpy", 501 "-D__strchr_aarch64_sve = strchr", 502 "-D__strrchr_aarch64_sve = strrchr", 503 "-D__strchrnul_aarch64_sve = strchrnul", 504 "-D__strnlen_aarch64_sve = strnlen", 505 "-D__strncmp_aarch64_sve = strncmp", 506 ] 507 } else if (defined(ARM_FEATURE_MTE)) { 508 sources += [ 509 "$OPTRTDIR/string/aarch64/memchr-mte.S", 510 "$OPTRTDIR/string/aarch64/memcmp.S", 511 "$OPTRTDIR/string/aarch64/memcpy.S", 512 "$OPTRTDIR/string/aarch64/memset.S", 513 "$OPTRTDIR/string/aarch64/stpcpy-mte.S", 514 "$OPTRTDIR/string/aarch64/strchr-mte.S", 515 "$OPTRTDIR/string/aarch64/strchrnul-mte.S", 516 "$OPTRTDIR/string/aarch64/strcmp-mte.S", 517 "$OPTRTDIR/string/aarch64/strcpy-mte.S", 518 "$OPTRTDIR/string/aarch64/strlen-mte.S", 519 "$OPTRTDIR/string/aarch64/strncmp-mte.S", 520 "$OPTRTDIR/string/aarch64/strnlen.S", 521 "$OPTRTDIR/string/aarch64/strrchr-mte.S", 522 ] 523 asmflags = [ 524 "-D__memcpy_aarch64 = memcpy", 525 "-D__memset_aarch64 = memset", 526 "-D__memcmp_aarch64 = memcmp", 527 "-D__memchr_aarch64_mte = memchr", 528 "-D__strcmp_aarch64_mte = strcmp", 529 "-D__strlen_aarch64_mte = strlen", 530 "-D__strcpy_aarch64_mte = strcpy", 531 "-D__stpcpy_aarch64_mte = stpcpy", 532 "-D__strchr_aarch64_mte = strchr", 533 "-D__strrchr_aarch64_mte = strrchr", 534 "-D__strchrnul_aarch64_mte = strchrnul", 535 "-D__strnlen_aarch64 = strnlen", 536 "-D__strncmp_aarch64_mte = strncmp", 537 ] 538 } else { 539 sources += [ 540 "$OPTRTDIR/string/aarch64/memchr.S", 541 "$OPTRTDIR/string/aarch64/memcmp.S", 542 "$OPTRTDIR/string/aarch64/memcpy.S", 543 "$OPTRTDIR/string/aarch64/memset.S", 544 "$OPTRTDIR/string/aarch64/stpcpy.S", 545 "$OPTRTDIR/string/aarch64/strchr.S", 546 "$OPTRTDIR/string/aarch64/strchrnul.S", 547 "$OPTRTDIR/string/aarch64/strcmp.S", 548 "$OPTRTDIR/string/aarch64/strcpy.S", 549 "$OPTRTDIR/string/aarch64/strlen.S", 550 "$OPTRTDIR/string/aarch64/strncmp.S", 551 "$OPTRTDIR/string/aarch64/strnlen.S", 552 "$OPTRTDIR/string/aarch64/strrchr.S", 553 ] 554 sources += added_freebsd_files 555 asmflags = [ 556 "-D__memmove_aarch64 = memmove", 557 "-D__memcpy_aarch64 = memcpy", 558 "-D__memchr_aarch64 = memchr", 559 "-D__memset_aarch64 = memset", 560 "-D__memcmp_aarch64 = memcmp", 561 "-D__strcmp_aarch64 = strcmp", 562 "-D__strlen_aarch64 = strlen", 563 "-D__strcpy_aarch64 = strcpy", 564 "-D__stpcpy_aarch64 = stpcpy", 565 "-D__strchr_aarch64 = strchr", 566 "-D__strrchr_aarch64 = strrchr", 567 "-D__strchrnul_aarch64 = strchrnul", 568 "-D__strnlen_aarch64 = strnlen", 569 "-D__strncmp_aarch64 = strncmp", 570 ] 571 } 572 } 573 574 cflags = [ 575 "-O3", 576 "-fPIC", 577 "-ffreestanding", 578 "-fstack-protector-strong", 579 ] 580 581 if (!(use_libfuzzer || is_mac || is_asan || use_clang_coverage)) { 582 cflags += [ "-flto" ] 583 } 584 585 if (use_jemalloc) { 586 defines += [ "USE_JEMALLOC" ] 587 if (use_jemalloc_dfx_intf) { 588 defines += [ "USE_JEMALLOC_DFX_INTF" ] 589 } 590 if (use_jemalloc_recycle_func) { 591 defines += [ "USE_JEMALLOC_RECYCLE_FUNC" ] 592 } 593 include_dirs = [ "${musl_malloc_plugin}/include/jemalloc" ] 594 } 595 596 if (!defined(include_dirs)) { 597 if (musl_arch == "aarch64") { 598 include_dirs = [ "//third_party/FreeBSD/lib/libc/aarch64" ] 599 } 600 if (musl_arch == "arm") { 601 include_dirs = [ "//third_party/FreeBSD/lib/libc/arm" ] 602 } 603 } else { 604 if (musl_arch == "aarch64") { 605 include_dirs += [ "//third_party/FreeBSD/lib/libc/aarch64" ] 606 } 607 if (musl_arch == "arm") { 608 include_dirs += [ "//third_party/FreeBSD/lib/libc/arm" ] 609 } 610 } 611 612 configs -= musl_inherited_configs 613 configs += [ ":soft_musl_config" ] 614 615 if (!defined(defines)) { 616 defines = [] 617 } 618 if (musl_target_os == "linux" && product_path != "" && 619 product_path != rebase_path("//productdefine/common/products")) { 620 _product_config = read_file("${product_path}/config.json", "json") 621 if (defined(_product_config.device_stack_size)) { 622 defines += [ "TARGET_STACK_SIZE=${_product_config.device_stack_size}" ] 623 } 624 if (defined(_product_config.device_guard_size)) { 625 defines += [ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ] 626 } 627 } 628 629 deps = porting_deps 630 631 if (!startup_init_with_param_base) { 632 defines += [ "OHOS_ENABLE_PARAMETER" ] 633 deps += [ "//base/startup/init/services/param/base:parameterbase" ] 634 } 635 } 636 637 source_set("soft_musl_src_optimize") { 638 sources = [] 639 sources_orig = [] 640 641 if (musl_arch == "aarch64") { 642 sources_orig += [ 643 "src/math/cos.c", 644 "src/math/exp.c", 645 "src/math/exp2.c", 646 "src/math/exp2f.c", 647 "src/math/expf.c", 648 "src/math/log.c", 649 "src/math/log10.c", 650 "src/math/log2.c", 651 "src/math/log2f.c", 652 "src/math/logb.c", 653 "src/math/logf.c", 654 "src/math/sin.c", 655 "src/math/sincos.c", 656 "src/math/pow.c", 657 "src/math/powf.c", 658 ] 659 } 660 661 foreach(s, sources_orig) { 662 sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] 663 } 664 665 if (musl_arch == "aarch64") { 666 sources += [ 667 "$OPTRTDIR/math/cosf.c", 668 "$OPTRTDIR/math/sincosf.c", 669 "$OPTRTDIR/math/sincosf_data.c", 670 "$OPTRTDIR/math/sinf.c", 671 ] 672 } 673 674 configs -= musl_inherited_configs 675 configs += [ ":soft_musl_config" ] 676 cflags = [ 677 "-mllvm", 678 "-instcombine-max-iterations=0", 679 "-ffp-contract=fast", 680 "-O3", 681 "-fPIC", 682 "-fstack-protector-strong", 683 ] 684 685 deps = porting_deps 686 } 687 688 source_set("soft_musl_src_nossp") { 689 sources = [] 690 sources_orig = [ 691 "src/string/mempcpy.c", 692 "src/env/__init_tls.c", 693 "src/env/__libc_start_main.c", 694 "src/env/__stack_chk_fail.c", 695 ] 696 697 defines = [] 698 if (musl_iterate_and_stats_api) { 699 defines += [ "MUSL_ITERATE_AND_STATS_API" ] 700 } 701 702 if (musl_arch == "arm") { 703 sources_orig += [ "src/thread/${musl_arch}/__set_thread_area.c" ] 704 } else if (musl_arch == "aarch64") { 705 sources_orig += [ "src/thread/${musl_arch}/__set_thread_area.s" ] 706 } else if (musl_arch == "x86_64") { 707 sources_orig += [ 708 "src/thread/${musl_arch}/__set_thread_area.s", 709 "src/string/memset.c", 710 ] 711 } 712 713 foreach(s, sources_orig) { 714 sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] 715 } 716 717 configs -= musl_inherited_configs 718 configs += [ ":soft_musl_config" ] 719 cflags = [ 720 "-O3", 721 "-fPIC", 722 "-ffreestanding", 723 "-fno-stack-protector", 724 ] 725 726 deps = porting_deps 727 } 728 729 source_set("soft_musl_ldso") { 730 sources = [] 731 sources_orig = musl_src_ldso 732 733 foreach(s, sources_orig) { 734 sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] 735 } 736 737 configs -= musl_inherited_configs 738 configs += [ ":soft_musl_config" ] 739 cflags = [ 740 "-fPIC", 741 "-ffreestanding", 742 "-fno-stack-protector", 743 "-O3", 744 ] 745 if (is_asan) { 746 defines = [ 747 "NSLIST_DEFAULT_SIZE=1600", 748 "DSOLIST_DEFAULT_SIZE=1600", 749 "INHERIT_DEFAULT_SIZE=1600", 750 ] 751 } else { 752 defines = [ 753 "HANDLE_RANDOMIZATION", 754 "LOAD_ORDER_RANDOMIZATION", 755 ] 756 } 757 758 deps = porting_deps 759 if (!startup_init_with_param_base) { 760 defines += [ "OHOS_ENABLE_PARAMETER" ] 761 deps += [ "//base/startup/init/services/param/base:parameterbase" ] 762 } 763 764 if (musl_unit_test_flag) { 765 defines += [ 766 "UNIT_TEST_STATIC", 767 "DL_NOMMU_SUPPORT=1", 768 ] 769 } 770 } 771 772 source_set("soft_musl_hook") { 773 sources = [ 774 "./porting/linux/user/src/hook/malloc_common.c", 775 "./porting/linux/user/src/hook/memory_trace.c", 776 "./porting/linux/user/src/hook/musl_preinit.c", 777 "./porting/linux/user/src/hook/musl_preinit_common.c", 778 "./porting/linux/user/src/hook/musl_socket_preinit.c", 779 "./porting/linux/user/src/hook/musl_socket_preinit_common.c", 780 "./porting/linux/user/src/hook/socket_common.c", 781 ] 782 783 deps = [ 784 "//third_party/musl:create_alltypes_h", 785 "//third_party/musl:create_porting_src", 786 "//third_party/musl:create_syscall_h", 787 "//third_party/musl:create_version_h", 788 "//third_party/musl:musl_copy_inc_bits", 789 "//third_party/musl:musl_copy_inc_fortify", 790 "//third_party/musl:musl_copy_inc_root", 791 "//third_party/musl:musl_copy_inc_sys", 792 ] 793 if (!startup_init_with_param_base) { 794 defines = [ "OHOS_ENABLE_PARAMETER" ] 795 deps += [ "//base/startup/init/services/param/base:parameterbase" ] 796 } 797 798 if (musl_unit_test_flag) { 799 defines += [ "UNIT_TEST_STATIC" ] 800 } 801 if (use_jemalloc) { 802 defines += [ "USE_JEMALLOC" ] 803 if (use_jemalloc_dfx_intf) { 804 defines += [ "USE_JEMALLOC_DFX_INTF" ] 805 } 806 if (use_jemalloc_recycle_func) { 807 defines += [ "USE_JEMALLOC_RECYCLE_FUNC" ] 808 } 809 include_dirs = [ "${musl_malloc_plugin}/include/jemalloc" ] 810 } 811 812 configs -= musl_inherited_configs 813 814 configs += [ 815 "//build/config/compiler:compiler", 816 ":soft_hook", 817 ] 818 819 cflags = [ 820 "-mllvm", 821 "--instcombine-max-iterations=0", 822 "-ffp-contract=fast", 823 "-O3", 824 "-Wno-int-conversion", 825 ] 826 } 827 828 source_set("soft_musl_jemalloc") { 829 sources = [ "${musl_malloc_plugin}/src/static.c" ] 830 831 deps = [ 832 "//third_party/musl:create_alltypes_h", 833 "//third_party/musl:create_porting_src", 834 "//third_party/musl:create_syscall_h", 835 "//third_party/musl:create_version_h", 836 "//third_party/musl:musl_copy_inc_bits", 837 "//third_party/musl:musl_copy_inc_root", 838 "//third_party/musl:musl_copy_inc_sys", 839 ] 840 841 configs -= musl_inherited_configs 842 843 configs += [ ":soft_jemalloc" ] 844 } 845 846 static_library("soft_libc_musl_static") { 847 output_name = "libc" 848 complete_static_lib = true 849 850 configs -= musl_inherited_configs 851 852 output_dir = "${target_out_dir}/${_libs_out_dir}" 853 deps = [ 854 ":soft_musl_hook", 855 ":soft_musl_ldso", 856 ":soft_musl_src", 857 ":soft_musl_src_nossp", 858 ":soft_musl_src_optimize", 859 ] 860 deps += dfx_deps 861 if (!startup_init_with_param_base) { 862 deps += [ "//base/startup/init/services/param/base:parameterbase" ] 863 } 864 if (use_jemalloc) { 865 deps += [ ":soft_musl_jemalloc" ] 866 } 867 } 868 869 static_library("soft_libm") { 870 complete_static_lib = true 871 configs -= musl_inherited_configs 872 output_name = "libm" 873 output_dir = "${target_out_dir}/${_libs_out_dir}" 874 } 875 876 static_library("soft_librt") { 877 complete_static_lib = true 878 configs -= musl_inherited_configs 879 output_name = "librt" 880 output_dir = "${target_out_dir}/${_libs_out_dir}" 881 } 882 883 static_library("soft_libpthread") { 884 complete_static_lib = true 885 configs -= musl_inherited_configs 886 output_name = "libpthread" 887 output_dir = "${target_out_dir}/${_libs_out_dir}" 888 } 889 890 static_library("soft_libcrypt") { 891 complete_static_lib = true 892 configs -= musl_inherited_configs 893 output_name = "libcrypt" 894 output_dir = "${target_out_dir}/${_libs_out_dir}" 895 } 896 897 static_library("soft_libutil") { 898 complete_static_lib = true 899 configs -= musl_inherited_configs 900 output_name = "libutil" 901 output_dir = "${target_out_dir}/${_libs_out_dir}" 902 } 903 904 static_library("soft_libresolv") { 905 complete_static_lib = true 906 configs -= musl_inherited_configs 907 output_name = "libresolv" 908 output_dir = "${target_out_dir}/${_libs_out_dir}" 909 } 910 911 static_library("soft_libxnet") { 912 complete_static_lib = true 913 configs -= musl_inherited_configs 914 output_name = "libxnet" 915 output_dir = "${target_out_dir}/${_libs_out_dir}" 916 } 917 918 static_library("soft_libdl") { 919 complete_static_lib = true 920 configs -= musl_inherited_configs 921 output_name = "libdl" 922 output_dir = "${target_out_dir}/${_libs_out_dir}" 923 } 924 925 shared_library("soft_libc_musl_shared") { 926 output_dir = "${target_out_dir}/${_libs_out_dir}" 927 output_name = "libc" 928 output_extension = "so" 929 930 libclang_rt_path = rebase_path( 931 "${runtime_lib_path}/${musl_target_triple}/${_libs_path_prefix}") 932 933 musl_lib_path = rebase_path("${target_out_dir}/${_libs_out_dir}") 934 935 ldflags = [] 936 if (!musl_unit_test_flag) { 937 libc_map_path = 938 rebase_path("${target_out_dir}/${musl_ported_dir}/libc.map.txt") 939 ldflags += [ "-Wl,--version-script=${libc_map_path}" ] 940 } 941 942 ldflags += [ 943 "-nostdlib", 944 "-Wl,-e,_dlstart", 945 "-L${libclang_rt_path}", 946 "-lclang_rt.builtins", 947 "-lunwind", 948 "-L${musl_lib_path}", 949 "-ldl", 950 "-lpthread", 951 ] 952 953 configs -= musl_inherited_configs 954 configs -= [ "//build/config:default_libs" ] 955 configs += [ ":soft_musl_config" ] 956 957 deps = [ 958 ":soft_libdl", 959 ":soft_libpthread", 960 ":soft_musl_crt_install_action", 961 ":soft_musl_hook", 962 ":soft_musl_ldso", 963 ":soft_musl_src", 964 ":soft_musl_src_nossp", 965 ":soft_musl_src_optimize", 966 ] 967 deps += dfx_deps 968 if (!startup_init_with_param_base) { 969 deps += [ "//base/startup/init/services/param/base:parameterbase" ] 970 } 971 972 if (use_jemalloc) { 973 deps += [ ":soft_musl_jemalloc" ] 974 } 975 } 976 977 action_foreach("soft_musl_crt_install_action") { 978 redir = "${root_out_dir}/obj" 979 script = "${target_out_dir}/${musl_ported_dir}/scripts/install.py" 980 sources = [ 981 "${redir}/${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/soft_musl_crt/crti.o", 982 "${redir}/${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/soft_musl_crt/crtn.o", 983 "${redir}/${target_out_dir}/${musl_ported_dir}/crt/soft_musl_crt/Scrt1.o", 984 "${redir}/${target_out_dir}/${musl_ported_dir}/crt/soft_musl_crt/crt1.o", 985 "${redir}/${target_out_dir}/${musl_ported_dir}/crt/soft_musl_crt/rcrt1.o", 986 ] 987 988 outputs = [ "${root_build_dir}/obj/third_party/musl/${_libs_out_dir}/{{source_file_part}}" ] 989 990 ldpath = [] 991 if (is_mac) { 992 ldpath += [ "${clang_base_path}/bin/ld64.lld" ] 993 } else if (is_win) { 994 ldpath += [ "${clang_base_path}/bin/lld-link.exe" ] 995 } else { 996 ldpath += [ "${clang_base_path}/bin/ld.lld" ] 997 } 998 999 args = [ 1000 "--input", 1001 "{{source}}", 1002 ] 1003 args += [ "--output" ] + rebase_path(outputs, root_build_dir) 1004 args += [ "--ldpath" ] + rebase_path(ldpath, root_build_dir) 1005 args += [ "--crtplus" ] + rebase_path( 1006 [ "${redir}/${target_out_dir}/${musl_ported_dir}/crt/soft_musl_crt/crtplus.o" ], 1007 root_build_dir) 1008 1009 deps = [ ":soft_musl_crt" ] 1010 } 1011 1012 copy("soft_create_linker") { 1013 deps = [ ":soft_libc_musl_shared" ] 1014 1015 # _libc_shared_outputs = get_target_outputs(":soft_libc_musl_shared") 1016 _libc_shared_so = "${target_out_dir}/${_libs_out_dir}/libc.so" 1017 sources = [ _libc_shared_so ] 1018 if (is_asan) { 1019 asan = "-asan" 1020 } else { 1021 asan = "" 1022 } 1023 _muls_linker_so = "${root_out_dir}/common/common/libc/${_libs_path_prefix}/ld-musl-${musl_arch}${asan}.so.1" 1024 outputs = [ _muls_linker_so ] 1025 } 1026} 1027