musl_template.gni 28.6 KB
Newer Older
C
cheng_jinsong 已提交
1
import("//base/startup/init/begetd.gni")
2
import("//build/config/clang/clang.gni")
W
weichaox 已提交
3
import("//build/ohos.gni")
Y
yinchuang 已提交
4
import("//third_party/FreeBSD/FreeBSD.gni")
F
fangting 已提交
5
import("//third_party/optimized-routines/optimized-routines.gni")
W
weichaox 已提交
6 7 8 9
import("musl_src.gni")
template("musl_libs") {
  no_default_deps = true

X
xxlight 已提交
10
  forward_variables_from(invoker, [ "*" ])
W
weichaox 已提交
11

X
xxlight 已提交
12 13
  _libs_path_prefix = "."
  _libs_out_dir = "usr/lib/${musl_target_triple}"
W
weichaox 已提交
14

Z
zengchunliang 已提交
15
  dfx_deps = [ "//base/hiviewdfx/faultloggerd/interfaces/innerkits/signal_handler:dfxsignalhandler" ]
W
weichaox 已提交
16 17 18 19 20 21 22 23 24
  porting_deps = [
    "//third_party/musl:create_alltypes_h",
    "//third_party/musl:create_porting_src",
    "//third_party/musl:create_syscall_h",
    "//third_party/musl:create_version_h",
  ]

  group(target_name) {
    deps = [
X
xxlight 已提交
25 26 27 28
      ":soft_create_linker",
      ":soft_libc_musl_shared",
      ":soft_libc_musl_static",
      ":soft_musl_crt_libs",
W
weichaox 已提交
29 30 31
    ]
  }

X
xxlight 已提交
32
  group("soft_shared_libs") {
W
weichaox 已提交
33 34
    deps = [
      ":musl_headers",
X
xxlight 已提交
35 36 37 38 39 40 41 42 43 44
      ":soft_libc_musl_shared",
      ":soft_libcrypt",
      ":soft_libdl",
      ":soft_libm",
      ":soft_libpthread",
      ":soft_libresolv",
      ":soft_librt",
      ":soft_libutil",
      ":soft_libxnet",
      ":soft_musl_crt_libs",
W
weichaox 已提交
45 46 47
    ]
  }

X
xxlight 已提交
48
  group("soft_static_libs") {
W
weichaox 已提交
49 50
    deps = [
      ":musl_headers",
X
xxlight 已提交
51 52 53 54 55 56 57 58 59 60
      ":soft_libc_musl_static",
      ":soft_libcrypt",
      ":soft_libdl",
      ":soft_libm",
      ":soft_libpthread",
      ":soft_libresolv",
      ":soft_librt",
      ":soft_libutil",
      ":soft_libxnet",
      ":soft_musl_crt_libs",
W
weichaox 已提交
61 62 63
    ]
  }

X
xxlight 已提交
64 65
  group("soft_musl_crt_libs") {
    deps = [ ":soft_musl_crt_install_action" ]
W
weichaox 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  }

  # part of default_compiler_configs from build/config/BUILDCONFIG.gn
  musl_inherited_configs = [
    "//build/config/compiler:afdo",
    "//build/config/compiler:afdo_optimize_size",
    "//build/config/compiler:compiler",
    "//build/config/compiler:compiler_arm_fpu",
    "//build/config/compiler:compiler_arm_thumb",
    "//build/config/compiler:chromium_code",
    "//build/config/compiler:default_include_dirs",
    "//build/config/compiler:default_optimization",
    "//build/config/compiler:default_stack_frames",
    "//build/config/compiler:default_symbols",
    "//build/config/compiler:export_dynamic",
    "//build/config/compiler:no_exceptions",
    "//build/config/compiler:no_rtti",
    "//build/config/compiler:runtime_library",
    "//build/config/compiler:thin_archive",
D
dhy308 已提交
85
    "//build/config/sanitizers:default_sanitizer_flags",
W
weichaox 已提交
86 87
  ]

X
xxlight 已提交
88
  config("soft_musl_config") {
89 90 91 92
    configs = [
      "//build/config/compiler:compiler_cpu_abi",
      "//build/config/coverage:default_coverage",
    ]
W
weichaox 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

    include_dirs = [
      "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}",
      "${target_out_dir}/${musl_ported_dir}/arch/generic",
      "${target_out_dir}/${musl_ported_dir}/src/internal",
      "${target_out_dir}/${musl_ported_dir}/src/include",
      "${target_out_dir}/${musl_ported_dir}/include",
      "${target_out_dir}/${musl_inc_out_dir}",
    ]

    cflags_basic = [
      "--target=${musl_target_triple}",
      "-Wall",
      "-Wl,-z,relro,-z,now,-z,noexecstack",
    ]

Z
zhuoli 已提交
109
    if (musl_arch == "arm") {
D
dhy308 已提交
110
      cflags_basic += [ "-mtp=cp15" ]
Z
zhuoli 已提交
111 112 113
    } else if (musl_arch == "aarch64") {
    }

W
weichaox 已提交
114 115
    cflags_auto = [
      "-D_XOPEN_SOURCE=700",
D
dhy308 已提交
116
      "-g",
W
weichaox 已提交
117
      "-pipe",
D
dhy308 已提交
118 119 120
      "-fno-omit-frame-pointer",
      "-funwind-tables",
      "-fasynchronous-unwind-tables",
W
weichaox 已提交
121 122 123 124 125 126 127
      "-ffunction-sections",
      "-fdata-sections",
      "-Werror=implicit-function-declaration",
      "-Werror=implicit-int",
      "-Werror=pointer-sign",
      "-Werror=pointer-arith",
      "-Qunused-arguments",
G
guzhihao4 已提交
128
      "-Wno-int-conversion",
W
weichaox 已提交
129 130
    ]

M
mucor 已提交
131
    if (!is_asan) {
L
liyufan123 已提交
132 133 134 135
      cflags_auto += [
        "-DHOOK_ENABLE",
        "-DOHOS_SOCKET_HOOK_ENABLE",
      ]
M
mucor 已提交
136 137
    }

138 139 140 141
    if (use_pthread_cancel) {
      cflags_auto += [ "-DFEATURE_PTHREAD_CANCEL" ]
    }

142
    cflags_auto += [ "-DRESERVE_SIGNAL_STACK" ]
Z
zengchunliang 已提交
143
    cflags_auto += [ "-DDFX_SIGNAL_LIBC" ]
144

W
weichaox 已提交
145 146 147 148 149 150 151 152 153 154
    cflags_c99fse = [
      "-std=c99",
      "-nostdinc",
      "-Wa,--noexecstack",
    ]

    cflags_all = cflags_basic + cflags_c99fse + cflags_auto

    cflags = cflags_all

X
xxlight 已提交
155
    defines = [ "BROKEN_VFP_ASM" ]
L
liuyaning 已提交
156
    defines += [ "FEATURE_ATEXIT_CB_PROTECT" ]
F
fangting 已提交
157
    if (is_standard_system) {
158 159 160
      defines += [
        "OHOS_DNS_PROXY_BY_NETSYS=1",
        "OHOS_PERMISSION_INTERNET=1",
F
fangting 已提交
161
        "STANDARD_SYSTEM",
162
      ]
W
weichaox 已提交
163 164
    }

165 166 167 168
    if (!is_standard_system && defined(enable_musl_log)) {
      if (enable_musl_log) {
        defines += [ "ENABLE_MUSL_LOG" ]
      }
G
ganlan 已提交
169 170
    }

W
weichaox 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    dynamic_list =
        rebase_path("${target_out_dir}/${musl_ported_dir}/dynamic.list")

    ldflags = cflags_all
    ldflags += [
      "--target=${musl_target_triple}",
      "-fuse-ld=lld",
      "-Wl,--sort-section,alignment",
      "-Wl,--sort-common",
      "-Wl,--gc-sections",
      "-Wl,--hash-style=both",
      "-Wl,--no-undefined",
      "-Wl,--exclude-libs=ALL",
      "-Wl,--dynamic-list=${dynamic_list}",
    ]
    asmflags = cflags
  }

X
xxlight 已提交
189
  config("soft_hook") {
chuxuezhe1111's avatar
chuxuezhe1111 已提交
190
    defines = []
191
    configs = [ "//build/config/coverage:default_coverage" ]
chuxuezhe1111's avatar
chuxuezhe1111 已提交
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208

    if (is_posix) {
      configs += [ "//build/config/posix:runtime_library" ]
    }

    cflags_cc = []

    defines = [
      "__GNU_SOURCE=1",  # Necessary for clone().
      "CHROMIUM_CXX_TWEAK_INLINES",  # Saves binary size.
    ]

    defines += [
      "__MUSL__",
      "_LIBCPP_HAS_MUSL_LIBC",
      "__BUILD_LINUX_WITH_CLANG",
    ]
M
mucor 已提交
209 210

    if (!is_asan) {
L
liyufan123 已提交
211 212 213 214
      defines += [
        "HOOK_ENABLE",
        "OHOS_SOCKET_HOOK_ENABLE",
      ]
M
mucor 已提交
215
    }
chuxuezhe1111's avatar
chuxuezhe1111 已提交
216 217 218 219 220 221 222 223 224
    ldflags = [ "-nostdlib" ]

    libs = []

    if (is_component_build) {
      defines += [ "COMPONENT_BUILD" ]
    }
  }

C
ChenJie 已提交
225
  config("soft_jemalloc") {
226
    configs = [ "//build/config/coverage:default_coverage" ]
C
ChenJie 已提交
227 228 229 230 231 232 233 234

    include_dirs = [
      "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}",
      "${target_out_dir}/${musl_ported_dir}/arch/generic",
      "${target_out_dir}/${musl_ported_dir}/src/internal",
      "${target_out_dir}/${musl_ported_dir}/src/include",
      "${target_out_dir}/${musl_ported_dir}/include",
      "${target_out_dir}/${musl_inc_out_dir}",
C
ChenJie 已提交
235
      "${clang_base_path}/lib/clang/${clang_version}/include",
C
ChenJie 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
    ]

    cflags = [
      "--target=${musl_target_triple}",
      "-D_GNU_SOURCE",
      "-D_REENTRANT",
      "-Wall",
      "-Wshorten-64-to-32",
      "-Wsign-compare",
      "-Wundef",
      "-Wno-format-zero-length",
      "-pipe",
      "-g3",
      "-fvisibility=hidden",
      "-O3",
      "-funroll-loops",
C
ChenJie 已提交
252
      "-funwind-tables",
C
ChenJie 已提交
253 254 255 256 257 258 259 260

      # The following flags are for avoiding errors when compiling.
      "-Wno-unused-parameter",
      "-Wno-unused-function",
      "-Wno-missing-field-initializers",

      "-U_FORTIFY_SOURCE",

W
wonghiu45 已提交
261 262
      "-DOHOS_ENABLE_TCACHE",  # For jemalloc 5.X
      "-DJEMALLOC_TCACHE",  # For jemalloc 4.X
陈杰 已提交
263
      "-DOHOS_LG_TCACHE_MAXCLASS_DEFAULT=16",
W
wonghiu45 已提交
264 265
      "-DOHOS_NUM_ARENAS=2",  # For jemalloc 5.X
      "-DOHOS_MAX_ARENAS=2",  # For jemalloc 4.X
陈杰 已提交
266 267
      "-DOHOS_TCACHE_NSLOTS_SMALL_MAX=8",
      "-DOHOS_TCACHE_NSLOTS_LARGE=16",
C
ChenJie 已提交
268 269
    ]

270 271 272 273
    if (is_debug || musl_secure_level > 1) {
      cflags += [ "-DOHOS_TCACHE_NSLOTS_RANDOM" ]
    }

C
ChenJie 已提交
274
    if (musl_arch == "arm") {
W
wonghiu45 已提交
275 276 277 278
      cflags += [
        "-march=armv7-a",
        "-DOHOS_LG_CHUNK_DEFAULT=19",  # For jemalloc 4.X
      ]
C
ChenJie 已提交
279
    } else if (musl_arch == "aarch64") {
W
wonghiu45 已提交
280 281 282 283
      cflags += [
        "-march=armv8",
        "-DOHOS_LG_CHUNK_DEFAULT=19",  # For jemalloc 4.X
      ]
陈杰 已提交
284 285
    } else if (musl_arch == "x86_64") {
      cflags += [ "-march=x86-64" ]
C
ChenJie 已提交
286 287 288 289 290
    }

    include_dirs += [
      "//third_party",
      "//third_party/musl/src/include/",
S
surencong 已提交
291 292 293
      "${musl_malloc_plugin}/include/",
      "${musl_malloc_plugin}/include/jemalloc/internal",
      "${musl_malloc_plugin}/include/jemalloc",
C
ChenJie 已提交
294 295 296
    ]
  }

X
xxlight 已提交
297
  source_set("soft_musl_crt") {
W
weichaox 已提交
298 299 300 301 302
    sources = [
      "${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/crti.s",
      "${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/crtn.s",
      "${target_out_dir}/${musl_ported_dir}/crt/Scrt1.c",
      "${target_out_dir}/${musl_ported_dir}/crt/crt1.c",
D
dhy308 已提交
303
      "${target_out_dir}/${musl_ported_dir}/crt/crtplus.c",
W
weichaox 已提交
304 305 306 307 308 309
      "${target_out_dir}/${musl_ported_dir}/crt/rcrt1.c",
    ]

    defines = [ "CRT" ]

    configs -= musl_inherited_configs
X
xxlight 已提交
310
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
311 312
    cflags = [
      "-fPIC",
313
      "-ffreestanding",
W
weichaox 已提交
314 315 316 317 318 319 320 321
      "-fno-stack-protector",
    ]

    deps = porting_deps

    asmflags = cflags
  }

X
xxlight 已提交
322
  source_set("soft_musl_src") {
W
weichaox 已提交
323 324 325 326 327 328 329 330 331 332 333
    sources_orig = []
    sources = []

    sources_orig = musl_src_arch_file + musl_src_file
    sources_orig -= musl_src_filterout
    sources_orig -= [
      "src/string/mempcpy.c",
      "src/string/memset.c",
      "src/env/__init_tls.c",
      "src/env/__libc_start_main.c",
      "src/env/__stack_chk_fail.c",
Y
yinchuang 已提交
334 335 336 337 338 339 340
      "src/stdlib/qsort.c",
      "src/stdlib/qsort_nr.c",
    ]

    sources += [
      "$FREEBSD_DIR/contrib/tcp_wrappers/strcasecmp.c",
      "$FREEBSD_DIR/lib/libc/stdlib/qsort.c",
W
weichaox 已提交
341 342
    ]

343
    if (musl_arch == "arm") {
D
dhy308 已提交
344 345 346 347 348
      sources_orig -= [
        "src/thread/${musl_arch}/__set_thread_area.c",
        "src/string/arm/memcpy.S",
        "src/string/memchr.c",
        "src/string/strcmp.c",
F
fangting 已提交
349
        "src/string/strlen.c",
F
fangting 已提交
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
        "src/math/sincosf.c",
        "src/math/expf.c",
        "src/math/exp2f.c",
        "src/math/exp2l.c",
        "src/math/exp2.c",
        "src/math/log.c",
        "src/math/logl.c",
        "src/math/log2.c",
        "src/math/log2f.c",
        "src/math/log2l.c",
        "src/math/logf.c",
        "src/math/log_data.c",
        "src/math/logf_data.c",
        "src/math/log2_data.c",
        "src/math/log2f_data.c",
        "src/math/exp2f_data.c",
        "src/math/pow.c",
        "src/math/powf.c",
        "src/math/powl.c",
369 370
        "src/math/sinf.c",
        "src/math/cosf.c",
F
fangting 已提交
371
      ]
Z
zhuoli 已提交
372
    } else if (musl_arch == "aarch64") {
F
fangting 已提交
373 374 375
      sources_orig -= [
        "src/thread/${musl_arch}/__set_thread_area.s",
        "src/string/memcpy.c",
Y
yinchuang 已提交
376
        "src/string/memmove.c",
F
fangting 已提交
377
        "src/string/memchr.c",
F
fangting 已提交
378
        "src/string/memcmp.c",
F
fangting 已提交
379 380 381
        "src/string/strcpy.c",
        "src/string/strcmp.c",
        "src/string/strlen.c",
F
fangting 已提交
382 383 384 385 386 387
        "src/string/stpcpy.c",
        "src/string/strchr.c",
        "src/string/strrchr.c",
        "src/string/strnlen.c",
        "src/string/strncmp.c",
        "src/math/sincosf.c",
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
        "src/math/sinf.c",
        "src/math/cosf.c",
        "src/math/cos.c",
        "src/math/exp.c",
        "src/math/exp2.c",
        "src/math/exp2f.c",
        "src/math/expf.c",
        "src/math/log.c",
        "src/math/log10.c",
        "src/math/log2.c",
        "src/math/log2f.c",
        "src/math/logb.c",
        "src/math/logf.c",
        "src/math/sin.c",
        "src/math/sincos.c",
        "src/math/pow.c",
        "src/math/powf.c",
F
fangting 已提交
405
      ]
W
wangjiahui 已提交
406 407
    } else if (musl_arch == "x86_64") {
      sources_orig -= [ "src/thread/${musl_arch}/__set_thread_area.s" ]
Z
zhuoli 已提交
408 409
    }

F
Far 已提交
410
    defines = []
Y
yinchuang 已提交
411 412 413 414 415 416 417 418 419
    if (musl_arch == "arm") {
      defines += [ "MUSL_ARM_ARCH" ]
    }
    if (musl_arch == "aarch64") {
      defines += [ "MUSL_AARCH64_ARCH" ]
    }
    if (musl_arch == "x86_64") {
      defines += [ "MUSL_X86_64_ARCH" ]
    }
F
Far 已提交
420 421 422
    if (musl_secure_level > 0) {
      defines += [ "MALLOC_FREELIST_HARDENED" ]
    }
423 424 425
    if (musl_secure_level > 1) {
      defines += [ "MALLOC_FREELIST_QUARANTINE" ]
    }
426 427 428
    if (musl_secure_level > 2) {
      defines += [ "MALLOC_RED_ZONE" ]
    }
429
    if (is_debug || musl_secure_level >= 3) {
F
Far 已提交
430
      defines += [ "MALLOC_SECURE_ALL" ]
W
weichaox 已提交
431 432
    }

433 434 435 436
    if (musl_iterate_and_stats_api) {
      defines += [ "MUSL_ITERATE_AND_STATS_API" ]
    }

W
weichaox 已提交
437 438 439
    foreach(s, sources_orig) {
      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
    }
F
fangting 已提交
440
    if (musl_arch == "arm") {
F
fangting 已提交
441
      sources += [
442
        "$OPTRTDIR/math/cosf.c",
F
fangting 已提交
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
        "$OPTRTDIR/math/exp2.c",
        "$OPTRTDIR/math/exp2f.c",
        "$OPTRTDIR/math/exp2f_data.c",
        "$OPTRTDIR/math/expf.c",
        "$OPTRTDIR/math/log.c",
        "$OPTRTDIR/math/log2.c",
        "$OPTRTDIR/math/log2_data.c",
        "$OPTRTDIR/math/log2f.c",
        "$OPTRTDIR/math/log2f_data.c",
        "$OPTRTDIR/math/log_data.c",
        "$OPTRTDIR/math/logf.c",
        "$OPTRTDIR/math/logf_data.c",
        "$OPTRTDIR/math/pow.c",
        "$OPTRTDIR/math/powf.c",
        "$OPTRTDIR/math/sincosf.c",
        "$OPTRTDIR/math/sincosf_data.c",
459
        "$OPTRTDIR/math/sinf.c",
F
fangting 已提交
460 461
        "$OPTRTDIR/string/arm/memchr.S",
        "$OPTRTDIR/string/arm/memcpy.S",
F
fangting 已提交
462
        "$OPTRTDIR/string/arm/memset.S",
F
fangting 已提交
463 464 465
        "$OPTRTDIR/string/arm/strcmp.S",
        "$OPTRTDIR/string/arm/strlen-armv6t2.S",
      ]
Y
yinchuang 已提交
466 467

      sources += added_freebsd_files
F
fangting 已提交
468 469 470
      asmflags = [
        "-D__memcpy_arm = memcpy",
        "-D__memchr_arm = memchr",
F
fangting 已提交
471
        "-D__memset_arm = memset",
F
fangting 已提交
472 473 474
        "-D__strcmp_arm = strcmp",
        "-D__strlen_armv6t2 = strlen",
      ]
F
fangting 已提交
475
    } else if (musl_arch == "aarch64") {
F
fangting 已提交
476 477 478
      if (defined(ARM_FEATURE_SVE)) {
        sources += [
          "$OPTRTDIR/string/aarch64/memchr-sve.S",
F
fangting 已提交
479
          "$OPTRTDIR/string/aarch64/memcmp-sve.S",
F
fangting 已提交
480
          "$OPTRTDIR/string/aarch64/memcpy.S",
F
fangting 已提交
481 482 483
          "$OPTRTDIR/string/aarch64/memset.S",
          "$OPTRTDIR/string/aarch64/stpcpy-sve.S",
          "$OPTRTDIR/string/aarch64/strchr-sve.S",
Y
yinchuang 已提交
484
          "$OPTRTDIR/string/aarch64/strchrnul-sve.S",
F
fangting 已提交
485 486 487
          "$OPTRTDIR/string/aarch64/strcmp-sve.S",
          "$OPTRTDIR/string/aarch64/strcpy-sve.S",
          "$OPTRTDIR/string/aarch64/strlen-sve.S",
F
fangting 已提交
488 489 490
          "$OPTRTDIR/string/aarch64/strncmp-sve.S",
          "$OPTRTDIR/string/aarch64/strnlen-sve.S",
          "$OPTRTDIR/string/aarch64/strrchr-sve.S",
F
fangting 已提交
491 492 493
        ]
        asmflags = [
          "-D__memcpy_aarch64 = memcpy",
F
fangting 已提交
494 495
          "-D__memset_aarch64 = memset",
          "-D__memcmp_aarch64_sve = memcmp",
F
fangting 已提交
496 497 498 499
          "-D__memchr_aarch64_sve = memchr",
          "-D__strcmp_aarch64_sve = strcmp",
          "-D__strlen_aarch64_sve = strlen",
          "-D__strcpy_aarch64_sve = strcpy",
F
fangting 已提交
500 501 502
          "-D__stpcpy_aarch64_sve = stpcpy",
          "-D__strchr_aarch64_sve = strchr",
          "-D__strrchr_aarch64_sve = strrchr",
Y
yinchuang 已提交
503
          "-D__strchrnul_aarch64_sve = strchrnul",
F
fangting 已提交
504 505
          "-D__strnlen_aarch64_sve = strnlen",
          "-D__strncmp_aarch64_sve = strncmp",
F
fangting 已提交
506 507 508 509
        ]
      } else if (defined(ARM_FEATURE_MTE)) {
        sources += [
          "$OPTRTDIR/string/aarch64/memchr-mte.S",
F
fangting 已提交
510
          "$OPTRTDIR/string/aarch64/memcmp.S",
F
fangting 已提交
511
          "$OPTRTDIR/string/aarch64/memcpy.S",
F
fangting 已提交
512 513 514
          "$OPTRTDIR/string/aarch64/memset.S",
          "$OPTRTDIR/string/aarch64/stpcpy-mte.S",
          "$OPTRTDIR/string/aarch64/strchr-mte.S",
Y
yinchuang 已提交
515
          "$OPTRTDIR/string/aarch64/strchrnul-mte.S",
F
fangting 已提交
516 517 518
          "$OPTRTDIR/string/aarch64/strcmp-mte.S",
          "$OPTRTDIR/string/aarch64/strcpy-mte.S",
          "$OPTRTDIR/string/aarch64/strlen-mte.S",
F
fangting 已提交
519 520 521
          "$OPTRTDIR/string/aarch64/strncmp-mte.S",
          "$OPTRTDIR/string/aarch64/strnlen.S",
          "$OPTRTDIR/string/aarch64/strrchr-mte.S",
F
fangting 已提交
522 523 524
        ]
        asmflags = [
          "-D__memcpy_aarch64 = memcpy",
F
fangting 已提交
525 526
          "-D__memset_aarch64 = memset",
          "-D__memcmp_aarch64 = memcmp",
F
fangting 已提交
527 528 529 530
          "-D__memchr_aarch64_mte = memchr",
          "-D__strcmp_aarch64_mte = strcmp",
          "-D__strlen_aarch64_mte = strlen",
          "-D__strcpy_aarch64_mte = strcpy",
F
fangting 已提交
531 532 533
          "-D__stpcpy_aarch64_mte = stpcpy",
          "-D__strchr_aarch64_mte = strchr",
          "-D__strrchr_aarch64_mte = strrchr",
Y
yinchuang 已提交
534
          "-D__strchrnul_aarch64_mte = strchrnul",
F
fangting 已提交
535 536
          "-D__strnlen_aarch64 = strnlen",
          "-D__strncmp_aarch64_mte = strncmp",
F
fangting 已提交
537 538 539 540
        ]
      } else {
        sources += [
          "$OPTRTDIR/string/aarch64/memchr.S",
F
fangting 已提交
541
          "$OPTRTDIR/string/aarch64/memcmp.S",
F
fangting 已提交
542
          "$OPTRTDIR/string/aarch64/memcpy.S",
F
fangting 已提交
543 544 545
          "$OPTRTDIR/string/aarch64/memset.S",
          "$OPTRTDIR/string/aarch64/stpcpy.S",
          "$OPTRTDIR/string/aarch64/strchr.S",
Y
yinchuang 已提交
546
          "$OPTRTDIR/string/aarch64/strchrnul.S",
F
fangting 已提交
547 548 549
          "$OPTRTDIR/string/aarch64/strcmp.S",
          "$OPTRTDIR/string/aarch64/strcpy.S",
          "$OPTRTDIR/string/aarch64/strlen.S",
F
fangting 已提交
550 551 552
          "$OPTRTDIR/string/aarch64/strncmp.S",
          "$OPTRTDIR/string/aarch64/strnlen.S",
          "$OPTRTDIR/string/aarch64/strrchr.S",
F
fangting 已提交
553
        ]
Y
yinchuang 已提交
554
        sources += added_freebsd_files
F
fangting 已提交
555
        asmflags = [
Y
yinchuang 已提交
556
          "-D__memmove_aarch64 = memmove",
F
fangting 已提交
557 558
          "-D__memcpy_aarch64 = memcpy",
          "-D__memchr_aarch64 = memchr",
F
fangting 已提交
559 560
          "-D__memset_aarch64 = memset",
          "-D__memcmp_aarch64 = memcmp",
F
fangting 已提交
561 562 563
          "-D__strcmp_aarch64 = strcmp",
          "-D__strlen_aarch64 = strlen",
          "-D__strcpy_aarch64 = strcpy",
F
fangting 已提交
564 565 566
          "-D__stpcpy_aarch64 = stpcpy",
          "-D__strchr_aarch64 = strchr",
          "-D__strrchr_aarch64 = strrchr",
Y
yinchuang 已提交
567
          "-D__strchrnul_aarch64 = strchrnul",
F
fangting 已提交
568 569
          "-D__strnlen_aarch64 = strnlen",
          "-D__strncmp_aarch64 = strncmp",
F
fangting 已提交
570 571
        ]
      }
F
fangting 已提交
572
    }
W
weichaox 已提交
573 574 575 576

    cflags = [
      "-O3",
      "-fPIC",
577
      "-ffreestanding",
W
weichaox 已提交
578
      "-fstack-protector-strong",
Y
yinchuang 已提交
579
      "-flto",
W
weichaox 已提交
580 581
    ]

C
ChenJie 已提交
582 583
    if (use_jemalloc) {
      defines += [ "USE_JEMALLOC" ]
C
ChenJie 已提交
584 585 586
      if (use_jemalloc_dfx_intf) {
        defines += [ "USE_JEMALLOC_DFX_INTF" ]
      }
L
lice 已提交
587 588 589
      if (use_jemalloc_recycle_func) {
        defines += [ "USE_JEMALLOC_RECYCLE_FUNC" ]
      }
S
surencong 已提交
590
      include_dirs = [ "${musl_malloc_plugin}/include/jemalloc" ]
C
ChenJie 已提交
591 592
    }

Y
yinchuang 已提交
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
    if (!defined(include_dirs)) {
      if (musl_arch == "aarch64") {
        include_dirs = [ "//third_party/FreeBSD/lib/libc/aarch64" ]
      }
      if (musl_arch == "arm") {
        include_dirs = [ "//third_party/FreeBSD/lib/libc/arm" ]
      }
    } else {
      if (musl_arch == "aarch64") {
        include_dirs += [ "//third_party/FreeBSD/lib/libc/aarch64" ]
      }
      if (musl_arch == "arm") {
        include_dirs += [ "//third_party/FreeBSD/lib/libc/arm" ]
      }
    }

W
weichaox 已提交
609
    configs -= musl_inherited_configs
X
xxlight 已提交
610
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
611

G
ganlan 已提交
612 613 614 615 616 617 618 619 620 621 622 623 624 625
    if (!defined(defines)) {
      defines = []
    }
    if (musl_target_os == "linux" && product_path != "" &&
        product_path != rebase_path("//productdefine/common/products")) {
      _product_config = read_file("${product_path}/config.json", "json")
      if (defined(_product_config.device_stack_size)) {
        defines += [ "TARGET_STACK_SIZE=${_product_config.device_stack_size}" ]
      }
      if (defined(_product_config.device_guard_size)) {
        defines += [ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ]
      }
    }

W
weichaox 已提交
626
    deps = porting_deps
627

C
cheng_jinsong 已提交
628
    if (!startup_init_with_param_base) {
629 630 631
      defines += [ "OHOS_ENABLE_PARAMETER" ]
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
W
weichaox 已提交
632 633
  }

634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
  source_set("soft_musl_src_optimize") {
    sources = []
    sources_orig = []

    if (musl_arch == "aarch64") {
      sources_orig += [
        "src/math/cos.c",
        "src/math/exp.c",
        "src/math/exp2.c",
        "src/math/exp2f.c",
        "src/math/expf.c",
        "src/math/log.c",
        "src/math/log10.c",
        "src/math/log2.c",
        "src/math/log2f.c",
        "src/math/logb.c",
        "src/math/logf.c",
        "src/math/sin.c",
        "src/math/sincos.c",
        "src/math/pow.c",
        "src/math/powf.c",
      ]
    }

    foreach(s, sources_orig) {
      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
    }

    if (musl_arch == "aarch64") {
      sources += [
        "$OPTRTDIR/math/cosf.c",
        "$OPTRTDIR/math/sincosf.c",
        "$OPTRTDIR/math/sincosf_data.c",
        "$OPTRTDIR/math/sinf.c",
      ]
    }

    configs -= musl_inherited_configs
    configs += [ ":soft_musl_config" ]
    cflags = [
      "-mllvm",
      "-instcombine-max-iterations=0",
G
guzhihao4 已提交
676
      "-ffp-contract=fast",
677 678 679 680 681 682 683 684
      "-O3",
      "-fPIC",
      "-fstack-protector-strong",
    ]

    deps = porting_deps
  }

X
xxlight 已提交
685
  source_set("soft_musl_src_nossp") {
W
weichaox 已提交
686 687 688 689 690 691 692 693
    sources = []
    sources_orig = [
      "src/string/mempcpy.c",
      "src/env/__init_tls.c",
      "src/env/__libc_start_main.c",
      "src/env/__stack_chk_fail.c",
    ]

694 695 696 697 698
    defines = []
    if (musl_iterate_and_stats_api) {
      defines += [ "MUSL_ITERATE_AND_STATS_API" ]
    }

Z
zhuoli 已提交
699 700 701 702
    if (musl_arch == "arm") {
      sources_orig += [ "src/thread/${musl_arch}/__set_thread_area.c" ]
    } else if (musl_arch == "aarch64") {
      sources_orig += [ "src/thread/${musl_arch}/__set_thread_area.s" ]
W
wangjiahui 已提交
703
    } else if (musl_arch == "x86_64") {
F
fangting 已提交
704 705 706 707
      sources_orig += [
        "src/thread/${musl_arch}/__set_thread_area.s",
        "src/string/memset.c",
      ]
Z
zhuoli 已提交
708 709
    }

W
weichaox 已提交
710 711 712 713 714
    foreach(s, sources_orig) {
      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
    }

    configs -= musl_inherited_configs
X
xxlight 已提交
715
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
716 717 718
    cflags = [
      "-O3",
      "-fPIC",
719
      "-ffreestanding",
W
weichaox 已提交
720 721 722 723 724 725
      "-fno-stack-protector",
    ]

    deps = porting_deps
  }

X
xxlight 已提交
726
  source_set("soft_musl_ldso") {
W
weichaox 已提交
727 728 729 730 731 732 733 734
    sources = []
    sources_orig = musl_src_ldso

    foreach(s, sources_orig) {
      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
    }

    configs -= musl_inherited_configs
X
xxlight 已提交
735
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
736 737
    cflags = [
      "-fPIC",
738
      "-ffreestanding",
W
weichaox 已提交
739
      "-fno-stack-protector",
Y
yinchuang 已提交
740
      "-O3",
W
weichaox 已提交
741
    ]
742 743 744 745 746 747
    if (is_asan) {
      defines = [
        "NSLIST_DEFAULT_SIZE=1600",
        "DSOLIST_DEFAULT_SIZE=1600",
        "INHERIT_DEFAULT_SIZE=1600",
      ]
G
ganlan 已提交
748 749 750 751 752
    } else {
      defines = [
        "HANDLE_RANDOMIZATION",
        "LOAD_ORDER_RANDOMIZATION",
      ]
753
    }
W
weichaox 已提交
754 755

    deps = porting_deps
C
cheng_jinsong 已提交
756
    if (!startup_init_with_param_base) {
J
jwz 已提交
757
      defines += [ "OHOS_ENABLE_PARAMETER" ]
J
jwz 已提交
758 759
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
D
dhy308 已提交
760 761 762 763 764 765 766

    if (musl_unit_test_flag) {
      defines += [
        "UNIT_TEST_STATIC",
        "DL_NOMMU_SUPPORT=1",
      ]
    }
W
weichaox 已提交
767 768
  }

X
xxlight 已提交
769
  source_set("soft_musl_hook") {
chuxuezhe1111's avatar
chuxuezhe1111 已提交
770 771
    sources = [
      "./porting/linux/user/src/hook/malloc_common.c",
L
lutao 已提交
772
      "./porting/linux/user/src/hook/memory_trace.c",
chuxuezhe1111's avatar
chuxuezhe1111 已提交
773 774
      "./porting/linux/user/src/hook/musl_preinit.c",
      "./porting/linux/user/src/hook/musl_preinit_common.c",
L
liyufan123 已提交
775 776 777
      "./porting/linux/user/src/hook/musl_socket_preinit.c",
      "./porting/linux/user/src/hook/musl_socket_preinit_common.c",
      "./porting/linux/user/src/hook/socket_common.c",
chuxuezhe1111's avatar
chuxuezhe1111 已提交
778 779 780 781 782 783 784 785
    ]

    deps = [
      "//third_party/musl:create_alltypes_h",
      "//third_party/musl:create_porting_src",
      "//third_party/musl:create_syscall_h",
      "//third_party/musl:create_version_h",
      "//third_party/musl:musl_copy_inc_bits",
G
ganlan 已提交
786
      "//third_party/musl:musl_copy_inc_fortify",
chuxuezhe1111's avatar
chuxuezhe1111 已提交
787
      "//third_party/musl:musl_copy_inc_root",
C
chenjianwen 已提交
788
      "//third_party/musl:musl_copy_inc_sys",
chuxuezhe1111's avatar
chuxuezhe1111 已提交
789
    ]
C
cheng_jinsong 已提交
790
    if (!startup_init_with_param_base) {
J
jwz 已提交
791
      defines = [ "OHOS_ENABLE_PARAMETER" ]
J
jwz 已提交
792 793
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
chuxuezhe1111's avatar
chuxuezhe1111 已提交
794

D
dhy308 已提交
795 796 797
    if (musl_unit_test_flag) {
      defines += [ "UNIT_TEST_STATIC" ]
    }
Z
zhang-cui11 已提交
798 799 800 801 802
    if (use_jemalloc) {
      defines += [ "USE_JEMALLOC" ]
      if (use_jemalloc_dfx_intf) {
        defines += [ "USE_JEMALLOC_DFX_INTF" ]
      }
L
lice 已提交
803 804 805
      if (use_jemalloc_recycle_func) {
        defines += [ "USE_JEMALLOC_RECYCLE_FUNC" ]
      }
S
surencong 已提交
806
      include_dirs = [ "${musl_malloc_plugin}/include/jemalloc" ]
Z
zhang-cui11 已提交
807 808
    }

chuxuezhe1111's avatar
chuxuezhe1111 已提交
809 810 811 812
    configs -= musl_inherited_configs

    configs += [
      "//build/config/compiler:compiler",
X
xxlight 已提交
813
      ":soft_hook",
chuxuezhe1111's avatar
chuxuezhe1111 已提交
814
    ]
Z
zhang-cui11 已提交
815 816 817 818 819 820

    cflags = [
      "-mllvm",
      "--instcombine-max-iterations=0",
      "-ffp-contract=fast",
      "-O3",
G
guzhihao4 已提交
821
      "-Wno-int-conversion",
Z
zhang-cui11 已提交
822
    ]
823
  }
Z
zhang-cui11 已提交
824

陈杰 已提交
825
  source_set("soft_musl_jemalloc") {
S
surencong 已提交
826
    sources = [ "${musl_malloc_plugin}/src/static.c" ]
陈杰 已提交
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842

    deps = [
      "//third_party/musl:create_alltypes_h",
      "//third_party/musl:create_porting_src",
      "//third_party/musl:create_syscall_h",
      "//third_party/musl:create_version_h",
      "//third_party/musl:musl_copy_inc_bits",
      "//third_party/musl:musl_copy_inc_root",
      "//third_party/musl:musl_copy_inc_sys",
    ]

    configs -= musl_inherited_configs

    configs += [ ":soft_jemalloc" ]
  }

X
xxlight 已提交
843
  static_library("soft_libc_musl_static") {
W
weichaox 已提交
844 845 846 847 848 849 850
    output_name = "libc"
    complete_static_lib = true

    configs -= musl_inherited_configs

    output_dir = "${target_out_dir}/${_libs_out_dir}"
    deps = [
X
xxlight 已提交
851
      ":soft_musl_hook",
M
maweiye 已提交
852
      ":soft_musl_ldso",
X
xxlight 已提交
853 854
      ":soft_musl_src",
      ":soft_musl_src_nossp",
855
      ":soft_musl_src_optimize",
W
weichaox 已提交
856
    ]
857
    deps += dfx_deps
C
cheng_jinsong 已提交
858
    if (!startup_init_with_param_base) {
M
Mupceet 已提交
859 860
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
861 862 863
    if (use_jemalloc) {
      deps += [ ":soft_musl_jemalloc" ]
    }
W
weichaox 已提交
864 865
  }

X
xxlight 已提交
866
  static_library("soft_libm") {
W
weichaox 已提交
867 868 869 870 871 872
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libm"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
873
  static_library("soft_librt") {
W
weichaox 已提交
874 875 876 877 878 879
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "librt"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
880
  static_library("soft_libpthread") {
W
weichaox 已提交
881 882 883 884 885 886
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libpthread"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
887
  static_library("soft_libcrypt") {
W
weichaox 已提交
888 889 890 891 892 893
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libcrypt"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
894
  static_library("soft_libutil") {
W
weichaox 已提交
895 896 897 898 899 900
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libutil"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
901
  static_library("soft_libresolv") {
W
weichaox 已提交
902 903 904 905 906 907
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libresolv"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
908
  static_library("soft_libxnet") {
W
weichaox 已提交
909 910 911 912 913 914
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libxnet"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
915
  static_library("soft_libdl") {
W
weichaox 已提交
916 917 918 919 920 921
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libdl"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
922
  shared_library("soft_libc_musl_shared") {
W
weichaox 已提交
923 924 925 926 927 928 929
    output_dir = "${target_out_dir}/${_libs_out_dir}"
    output_name = "libc"
    output_extension = "so"

    libclang_rt_path = rebase_path(
            "${runtime_lib_path}/${musl_target_triple}/${_libs_path_prefix}")

D
dhy308 已提交
930 931
    musl_lib_path = rebase_path("${target_out_dir}/${_libs_out_dir}")

D
dhy308 已提交
932 933 934 935 936 937
    ldflags = []
    if (!musl_unit_test_flag) {
      libc_map_path =
          rebase_path("${target_out_dir}/${musl_ported_dir}/libc.map.txt")
      ldflags += [ "-Wl,--version-script=${libc_map_path}" ]
    }
M
maweiye 已提交
938

D
dhy308 已提交
939
    ldflags += [
W
weichaox 已提交
940 941 942 943
      "-nostdlib",
      "-Wl,-e,_dlstart",
      "-L${libclang_rt_path}",
      "-lclang_rt.builtins",
D
dhy308 已提交
944 945 946 947
      "-lunwind",
      "-L${musl_lib_path}",
      "-ldl",
      "-lpthread",
W
weichaox 已提交
948 949 950 951
    ]

    configs -= musl_inherited_configs
    configs -= [ "//build/config:default_libs" ]
X
xxlight 已提交
952
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
953 954

    deps = [
X
xxlight 已提交
955 956 957 958 959 960 961
      ":soft_libdl",
      ":soft_libpthread",
      ":soft_musl_crt_install_action",
      ":soft_musl_hook",
      ":soft_musl_ldso",
      ":soft_musl_src",
      ":soft_musl_src_nossp",
962
      ":soft_musl_src_optimize",
W
weichaox 已提交
963
    ]
964
    deps += dfx_deps
C
cheng_jinsong 已提交
965
    if (!startup_init_with_param_base) {
M
Mupceet 已提交
966 967
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
C
ChenJie 已提交
968 969

    if (use_jemalloc) {
C
ChenJie 已提交
970
      deps += [ ":soft_musl_jemalloc" ]
C
ChenJie 已提交
971
    }
W
weichaox 已提交
972 973
  }

X
xxlight 已提交
974
  action_foreach("soft_musl_crt_install_action") {
W
weichaox 已提交
975 976 977
    redir = "${root_out_dir}/obj"
    script = "${target_out_dir}/${musl_ported_dir}/scripts/install.py"
    sources = [
X
xxlight 已提交
978 979
      "${redir}/${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/soft_musl_crt/crti.o",
      "${redir}/${target_out_dir}/${musl_ported_dir}/crt/${musl_arch}/soft_musl_crt/crtn.o",
X
xxlight 已提交
980 981 982
      "${redir}/${target_out_dir}/${musl_ported_dir}/crt/soft_musl_crt/Scrt1.o",
      "${redir}/${target_out_dir}/${musl_ported_dir}/crt/soft_musl_crt/crt1.o",
      "${redir}/${target_out_dir}/${musl_ported_dir}/crt/soft_musl_crt/rcrt1.o",
W
weichaox 已提交
983
    ]
D
dhy308 已提交
984

H
hhj 已提交
985
    outputs = [ "${root_build_dir}/obj/third_party/musl/${_libs_out_dir}/{{source_file_part}}" ]
D
dhy308 已提交
986 987 988 989 990 991 992 993 994 995

    ldpath = []
    if (is_mac) {
      ldpath += [ "${clang_base_path}/bin/ld64.lld" ]
    } else if (is_win) {
      ldpath += [ "${clang_base_path}/bin/lld-link.exe" ]
    } else {
      ldpath += [ "${clang_base_path}/bin/ld.lld" ]
    }

W
weichaox 已提交
996 997 998 999 1000
    args = [
      "--input",
      "{{source}}",
    ]
    args += [ "--output" ] + rebase_path(outputs, root_build_dir)
D
dhy308 已提交
1001 1002 1003 1004 1005
    args += [ "--ldpath" ] + rebase_path(ldpath, root_build_dir)
    args += [ "--crtplus" ] + rebase_path(
                [ "${redir}/${target_out_dir}/${musl_ported_dir}/crt/soft_musl_crt/crtplus.o" ],
                root_build_dir)

X
xxlight 已提交
1006
    deps = [ ":soft_musl_crt" ]
W
weichaox 已提交
1007 1008
  }

X
xxlight 已提交
1009 1010
  copy("soft_create_linker") {
    deps = [ ":soft_libc_musl_shared" ]
W
weichaox 已提交
1011

X
xxlight 已提交
1012
    # _libc_shared_outputs = get_target_outputs(":soft_libc_musl_shared")
W
weichaox 已提交
1013 1014
    _libc_shared_so = "${target_out_dir}/${_libs_out_dir}/libc.so"
    sources = [ _libc_shared_so ]
C
Caoruihong 已提交
1015 1016 1017 1018 1019
    if (is_asan) {
      asan = "-asan"
    } else {
      asan = ""
    }
X
xxlight 已提交
1020
    _muls_linker_so = "${root_out_dir}/common/common/libc/${_libs_path_prefix}/ld-musl-${musl_arch}${asan}.so.1"
W
weichaox 已提交
1021 1022 1023
    outputs = [ _muls_linker_so ]
  }
}