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

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

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

Z
zengchunliang 已提交
14
  dfx_deps = [ "//base/hiviewdfx/faultloggerd/interfaces/innerkits/signal_handler:dfxsignalhandler" ]
W
weichaox 已提交
15 16 17 18 19 20 21 22 23
  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 已提交
24 25 26 27
      ":soft_create_linker",
      ":soft_libc_musl_shared",
      ":soft_libc_musl_static",
      ":soft_musl_crt_libs",
W
weichaox 已提交
28 29 30
    ]
  }

X
xxlight 已提交
31
  group("soft_shared_libs") {
W
weichaox 已提交
32 33
    deps = [
      ":musl_headers",
X
xxlight 已提交
34 35 36 37 38 39 40 41 42 43
      ":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 已提交
44 45 46
    ]
  }

X
xxlight 已提交
47
  group("soft_static_libs") {
W
weichaox 已提交
48 49
    deps = [
      ":musl_headers",
X
xxlight 已提交
50 51 52 53 54 55 56 57 58 59
      ":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 已提交
60 61 62
    ]
  }

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

  # 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 已提交
84
    "//build/config/sanitizers:default_sanitizer_flags",
W
weichaox 已提交
85 86
  ]

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

    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",
      "-D_FORTIFY_SOURCE=2",
      "-Wl,-z,relro,-z,now,-z,noexecstack",
    ]

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

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

M
mucor 已提交
127
    if (!is_asan) {
128 129 130 131
      cflags_auto += [
        "-DHOOK_ENABLE",
        "-DOHOS_SOCKET_HOOK_ENABLE",
      ]
M
mucor 已提交
132 133
    }

134
    cflags_auto += [ "-DRESERVE_SIGNAL_STACK" ]
Z
zengchunliang 已提交
135
    cflags_auto += [ "-DDFX_SIGNAL_LIBC" ]
136

W
weichaox 已提交
137 138 139 140 141 142 143 144 145 146
    cflags_c99fse = [
      "-std=c99",
      "-nostdinc",
      "-Wa,--noexecstack",
    ]

    cflags_all = cflags_basic + cflags_c99fse + cflags_auto

    cflags = cflags_all

X
xxlight 已提交
147
    defines = [ "BROKEN_VFP_ASM" ]
F
fangting 已提交
148
    if (is_standard_system) {
149 150 151 152
      defines += [
        "OHOS_DNS_PROXY_BY_NETSYS=1",
        "OHOS_PERMISSION_INTERNET=1",
      ]
W
weichaox 已提交
153 154
    }

155 156 157 158
    if (!is_standard_system && defined(enable_musl_log)) {
      if (enable_musl_log) {
        defines += [ "ENABLE_MUSL_LOG" ]
      }
G
ganlan 已提交
159 160
    }

W
weichaox 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    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 已提交
179
  config("soft_hook") {
chuxuezhe1111's avatar
chuxuezhe1111 已提交
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
    defines = []
    configs = []

    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 已提交
199 200

    if (!is_asan) {
201 202 203 204
      defines += [
        "HOOK_ENABLE",
        "OHOS_SOCKET_HOOK_ENABLE",
      ]
M
mucor 已提交
205
    }
chuxuezhe1111's avatar
chuxuezhe1111 已提交
206 207 208 209 210 211 212 213 214
    ldflags = [ "-nostdlib" ]

    libs = []

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

C
ChenJie 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
  config("soft_jemalloc") {
    configs = []

    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}",
      "${clang_base_path}/lib/clang/${clang_version}/include",
    ]

    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",

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

      "-U_FORTIFY_SOURCE",

C
ChenJie 已提交
250 251
      "-DOHOS_ENABLE_TCACHE", # For jemalloc 5.X
      "-DJEMALLOC_TCACHE",    # For jemalloc 4.X
C
ChenJie 已提交
252
      "-DOHOS_LG_TCACHE_MAXCLASS_DEFAULT=16",
C
ChenJie 已提交
253 254
      "-DOHOS_NUM_ARENAS=2",  # For jemalloc 5.X
      "-DOHOS_MAX_ARENAS=2",  # For jemalloc 4.X
C
ChenJie 已提交
255 256 257 258 259
      "-DOHOS_TCACHE_NSLOTS_SMALL_MAX=8",
      "-DOHOS_TCACHE_NSLOTS_LARGE=16",
    ]

    if (musl_arch == "arm") {
C
ChenJie 已提交
260 261 262 263
      cflags += [
        "-march=armv7-a",
        "-DOHOS_LG_CHUNK_DEFAULT=19", # For jemalloc 4.X
      ]
C
ChenJie 已提交
264
    } else if (musl_arch == "aarch64") {
C
ChenJie 已提交
265 266 267 268
      cflags += [
        "-march=armv8",
        "-DOHOS_LG_CHUNK_DEFAULT=19", # For jemalloc 4.X
      ]
C
ChenJie 已提交
269 270 271 272 273 274 275 276 277 278 279 280 281 282
    } else if (musl_arch == "x86_64") {
      cflags += [ "-march=x86-64" ]
    }


    include_dirs += [
      "//third_party",
      "//third_party/musl/src/include/",
      "//third_party/jemalloc/include/",
      "//third_party/jemalloc/include/jemalloc/internal",
      "//third_party/jemalloc/include/jemalloc",
    ]
  }

X
xxlight 已提交
283
  source_set("soft_musl_crt") {
W
weichaox 已提交
284 285 286 287 288
    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 已提交
289
      "${target_out_dir}/${musl_ported_dir}/crt/crtplus.c",
W
weichaox 已提交
290 291 292 293 294 295
      "${target_out_dir}/${musl_ported_dir}/crt/rcrt1.c",
    ]

    defines = [ "CRT" ]

    configs -= musl_inherited_configs
X
xxlight 已提交
296
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
297 298
    cflags = [
      "-fPIC",
299
      "-ffreestanding",
W
weichaox 已提交
300 301 302 303 304 305 306 307
      "-fno-stack-protector",
    ]

    deps = porting_deps

    asmflags = cflags
  }

X
xxlight 已提交
308
  source_set("soft_musl_src") {
W
weichaox 已提交
309 310 311 312 313 314 315 316 317 318 319 320 321 322
    sources_orig = []
    sources = []
    set_sources_assignment_filter([])

    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",
    ]

Z
zhuoli 已提交
323
    if (musl_arch == "arm") {
F
fangting 已提交
324 325 326
      sources_orig -= [
        "src/thread/${musl_arch}/__set_thread_area.c",
        "src/string/arm/memcpy_le.S",
F
fangting 已提交
327 328 329
        "src/string/memchr.c",
        "src/string/strcmp.c",
        "src/string/strlen.c",
F
fangting 已提交
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
        "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",
349 350
        "src/math/sinf.c",
        "src/math/cosf.c",
F
fangting 已提交
351
      ]
Z
zhuoli 已提交
352
    } else if (musl_arch == "aarch64") {
F
fangting 已提交
353 354 355
      sources_orig -= [
        "src/thread/${musl_arch}/__set_thread_area.s",
        "src/string/memcpy.c",
Y
yinchuang 已提交
356
        "src/string/memmove.c",
F
fangting 已提交
357
        "src/string/memchr.c",
F
fangting 已提交
358
        "src/string/memcmp.c",
F
fangting 已提交
359 360 361
        "src/string/strcpy.c",
        "src/string/strcmp.c",
        "src/string/strlen.c",
F
fangting 已提交
362 363 364 365 366 367
        "src/string/stpcpy.c",
        "src/string/strchr.c",
        "src/string/strrchr.c",
        "src/string/strnlen.c",
        "src/string/strncmp.c",
        "src/math/sincosf.c",
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
        "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 已提交
385
      ]
W
wangjiahui 已提交
386 387
    } else if (musl_arch == "x86_64") {
      sources_orig -= [ "src/thread/${musl_arch}/__set_thread_area.s" ]
Z
zhuoli 已提交
388 389
    }

F
Far 已提交
390 391 392 393
    defines = []
    if (musl_secure_level > 0) {
      defines += [ "MALLOC_FREELIST_HARDENED" ]
    }
394 395 396
    if (musl_secure_level > 1) {
      defines += [ "MALLOC_FREELIST_QUARANTINE" ]
    }
397 398 399
    if (musl_secure_level > 2) {
      defines += [ "MALLOC_RED_ZONE" ]
    }
400
    if (is_debug || musl_secure_level >= 3) {
F
Far 已提交
401
      defines += [ "MALLOC_SECURE_ALL" ]
W
weichaox 已提交
402 403
    }

Z
zgq-0218 已提交
404 405 406 407
    if (musl_iterate_and_stats_api) {
      defines += [ "MUSL_ITERATE_AND_STATS_API" ]
    }

W
weichaox 已提交
408 409 410
    foreach(s, sources_orig) {
      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
    }
F
fangting 已提交
411
    if (musl_arch == "arm") {
F
fangting 已提交
412
      sources += [
413
        "$OPTRTDIR/math/cosf.c",
F
fangting 已提交
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
        "$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",
430
        "$OPTRTDIR/math/sinf.c",
F
fangting 已提交
431 432
        "$OPTRTDIR/string/arm/memchr.S",
        "$OPTRTDIR/string/arm/memcpy.S",
F
fangting 已提交
433
        "$OPTRTDIR/string/arm/memset.S",
F
fangting 已提交
434 435 436 437 438 439
        "$OPTRTDIR/string/arm/strcmp.S",
        "$OPTRTDIR/string/arm/strlen-armv6t2.S",
      ]
      asmflags = [
        "-D__memcpy_arm = memcpy",
        "-D__memchr_arm = memchr",
F
fangting 已提交
440
        "-D__memset_arm = memset",
F
fangting 已提交
441 442 443
        "-D__strcmp_arm = strcmp",
        "-D__strlen_armv6t2 = strlen",
      ]
F
fangting 已提交
444
    } else if (musl_arch == "aarch64") {
F
fangting 已提交
445 446 447
      if (defined(ARM_FEATURE_SVE)) {
        sources += [
          "$OPTRTDIR/string/aarch64/memchr-sve.S",
F
fangting 已提交
448
          "$OPTRTDIR/string/aarch64/memcmp-sve.S",
F
fangting 已提交
449
          "$OPTRTDIR/string/aarch64/memcpy.S",
F
fangting 已提交
450 451 452
          "$OPTRTDIR/string/aarch64/memset.S",
          "$OPTRTDIR/string/aarch64/stpcpy-sve.S",
          "$OPTRTDIR/string/aarch64/strchr-sve.S",
F
fangting 已提交
453 454 455
          "$OPTRTDIR/string/aarch64/strcmp-sve.S",
          "$OPTRTDIR/string/aarch64/strcpy-sve.S",
          "$OPTRTDIR/string/aarch64/strlen-sve.S",
F
fangting 已提交
456 457 458
          "$OPTRTDIR/string/aarch64/strncmp-sve.S",
          "$OPTRTDIR/string/aarch64/strnlen-sve.S",
          "$OPTRTDIR/string/aarch64/strrchr-sve.S",
F
fangting 已提交
459 460 461
        ]
        asmflags = [
          "-D__memcpy_aarch64 = memcpy",
F
fangting 已提交
462 463
          "-D__memset_aarch64 = memset",
          "-D__memcmp_aarch64_sve = memcmp",
F
fangting 已提交
464 465 466 467
          "-D__memchr_aarch64_sve = memchr",
          "-D__strcmp_aarch64_sve = strcmp",
          "-D__strlen_aarch64_sve = strlen",
          "-D__strcpy_aarch64_sve = strcpy",
F
fangting 已提交
468 469 470 471 472
          "-D__stpcpy_aarch64_sve = stpcpy",
          "-D__strchr_aarch64_sve = strchr",
          "-D__strrchr_aarch64_sve = strrchr",
          "-D__strnlen_aarch64_sve = strnlen",
          "-D__strncmp_aarch64_sve = strncmp",
F
fangting 已提交
473 474 475 476
        ]
      } else if (defined(ARM_FEATURE_MTE)) {
        sources += [
          "$OPTRTDIR/string/aarch64/memchr-mte.S",
F
fangting 已提交
477
          "$OPTRTDIR/string/aarch64/memcmp.S",
F
fangting 已提交
478
          "$OPTRTDIR/string/aarch64/memcpy.S",
F
fangting 已提交
479 480 481
          "$OPTRTDIR/string/aarch64/memset.S",
          "$OPTRTDIR/string/aarch64/stpcpy-mte.S",
          "$OPTRTDIR/string/aarch64/strchr-mte.S",
F
fangting 已提交
482 483 484
          "$OPTRTDIR/string/aarch64/strcmp-mte.S",
          "$OPTRTDIR/string/aarch64/strcpy-mte.S",
          "$OPTRTDIR/string/aarch64/strlen-mte.S",
F
fangting 已提交
485 486 487
          "$OPTRTDIR/string/aarch64/strncmp-mte.S",
          "$OPTRTDIR/string/aarch64/strnlen.S",
          "$OPTRTDIR/string/aarch64/strrchr-mte.S",
F
fangting 已提交
488 489 490
        ]
        asmflags = [
          "-D__memcpy_aarch64 = memcpy",
F
fangting 已提交
491 492
          "-D__memset_aarch64 = memset",
          "-D__memcmp_aarch64 = memcmp",
F
fangting 已提交
493 494 495 496
          "-D__memchr_aarch64_mte = memchr",
          "-D__strcmp_aarch64_mte = strcmp",
          "-D__strlen_aarch64_mte = strlen",
          "-D__strcpy_aarch64_mte = strcpy",
F
fangting 已提交
497 498 499 500 501
          "-D__stpcpy_aarch64_mte = stpcpy",
          "-D__strchr_aarch64_mte = strchr",
          "-D__strrchr_aarch64_mte = strrchr",
          "-D__strnlen_aarch64 = strnlen",
          "-D__strncmp_aarch64_mte = strncmp",
F
fangting 已提交
502 503 504 505
        ]
      } else {
        sources += [
          "$OPTRTDIR/string/aarch64/memchr.S",
F
fangting 已提交
506
          "$OPTRTDIR/string/aarch64/memcmp.S",
F
fangting 已提交
507
          "$OPTRTDIR/string/aarch64/memcpy.S",
F
fangting 已提交
508 509 510
          "$OPTRTDIR/string/aarch64/memset.S",
          "$OPTRTDIR/string/aarch64/stpcpy.S",
          "$OPTRTDIR/string/aarch64/strchr.S",
F
fangting 已提交
511 512 513
          "$OPTRTDIR/string/aarch64/strcmp.S",
          "$OPTRTDIR/string/aarch64/strcpy.S",
          "$OPTRTDIR/string/aarch64/strlen.S",
F
fangting 已提交
514 515 516
          "$OPTRTDIR/string/aarch64/strncmp.S",
          "$OPTRTDIR/string/aarch64/strnlen.S",
          "$OPTRTDIR/string/aarch64/strrchr.S",
F
fangting 已提交
517 518
        ]
        asmflags = [
Y
yinchuang 已提交
519
          "-D__memmove_aarch64 = memmove",
F
fangting 已提交
520 521
          "-D__memcpy_aarch64 = memcpy",
          "-D__memchr_aarch64 = memchr",
F
fangting 已提交
522 523
          "-D__memset_aarch64 = memset",
          "-D__memcmp_aarch64 = memcmp",
F
fangting 已提交
524 525 526
          "-D__strcmp_aarch64 = strcmp",
          "-D__strlen_aarch64 = strlen",
          "-D__strcpy_aarch64 = strcpy",
F
fangting 已提交
527 528 529 530 531
          "-D__stpcpy_aarch64 = stpcpy",
          "-D__strchr_aarch64 = strchr",
          "-D__strrchr_aarch64 = strrchr",
          "-D__strnlen_aarch64 = strnlen",
          "-D__strncmp_aarch64 = strncmp",
F
fangting 已提交
532 533
        ]
      }
F
fangting 已提交
534
    }
W
weichaox 已提交
535 536 537 538

    cflags = [
      "-O3",
      "-fPIC",
539
      "-ffreestanding",
W
weichaox 已提交
540 541 542
      "-fstack-protector-strong",
    ]

C
ChenJie 已提交
543 544
    if (use_jemalloc) {
      defines += [ "USE_JEMALLOC" ]
Z
zgq-0218 已提交
545 546 547
      if (use_jemalloc_dfx_intf) {
        defines += [ "USE_JEMALLOC_DFX_INTF" ]
      }
C
ChenJie 已提交
548 549 550
      include_dirs = [ "//third_party/jemalloc/include/jemalloc" ]
    }

W
weichaox 已提交
551
    configs -= musl_inherited_configs
X
xxlight 已提交
552
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
553

G
ganlan 已提交
554 555 556 557 558 559 560 561 562 563 564 565 566 567
    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 已提交
568
    deps = porting_deps
569

570
    if (!startup_init_with_param_base) {
571 572 573
      defines += [ "OHOS_ENABLE_PARAMETER" ]
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
W
weichaox 已提交
574 575
  }

576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
  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 已提交
618
      "-ffp-contract=fast",
619 620 621 622 623 624 625 626
      "-O3",
      "-fPIC",
      "-fstack-protector-strong",
    ]

    deps = porting_deps
  }

X
xxlight 已提交
627
  source_set("soft_musl_src_nossp") {
W
weichaox 已提交
628 629 630 631 632 633 634 635
    sources = []
    sources_orig = [
      "src/string/mempcpy.c",
      "src/env/__init_tls.c",
      "src/env/__libc_start_main.c",
      "src/env/__stack_chk_fail.c",
    ]

Z
zgq-0218 已提交
636 637 638 639 640
    defines = []
    if (musl_iterate_and_stats_api) {
      defines += [ "MUSL_ITERATE_AND_STATS_API" ]
    }

Z
zhuoli 已提交
641 642 643 644
    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 已提交
645
    } else if (musl_arch == "x86_64") {
F
fangting 已提交
646 647 648 649
      sources_orig += [
        "src/thread/${musl_arch}/__set_thread_area.s",
        "src/string/memset.c",
      ]
Z
zhuoli 已提交
650 651
    }

W
weichaox 已提交
652 653 654 655 656
    foreach(s, sources_orig) {
      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
    }

    configs -= musl_inherited_configs
X
xxlight 已提交
657
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
658 659 660
    cflags = [
      "-O3",
      "-fPIC",
661
      "-ffreestanding",
W
weichaox 已提交
662 663 664 665 666 667
      "-fno-stack-protector",
    ]

    deps = porting_deps
  }

X
xxlight 已提交
668
  source_set("soft_musl_ldso") {
W
weichaox 已提交
669 670 671 672 673 674 675 676
    sources = []
    sources_orig = musl_src_ldso

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

    configs -= musl_inherited_configs
X
xxlight 已提交
677
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
678 679
    cflags = [
      "-fPIC",
680
      "-ffreestanding",
W
weichaox 已提交
681 682
      "-fno-stack-protector",
    ]
683 684 685 686 687 688
    if (is_asan) {
      defines = [
        "NSLIST_DEFAULT_SIZE=1600",
        "DSOLIST_DEFAULT_SIZE=1600",
        "INHERIT_DEFAULT_SIZE=1600",
      ]
G
ganlan 已提交
689 690 691 692 693
    } else {
      defines = [
        "HANDLE_RANDOMIZATION",
        "LOAD_ORDER_RANDOMIZATION",
      ]
694
    }
W
weichaox 已提交
695 696

    deps = porting_deps
697
    if (!startup_init_with_param_base) {
J
jwz 已提交
698
      defines += [ "OHOS_ENABLE_PARAMETER" ]
J
jwz 已提交
699 700
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
W
weichaox 已提交
701 702
  }

X
xxlight 已提交
703
  source_set("soft_musl_hook") {
chuxuezhe1111's avatar
chuxuezhe1111 已提交
704 705
    sources = [
      "./porting/linux/user/src/hook/malloc_common.c",
F
fangting 已提交
706
      "./porting/linux/user/src/hook/memory_tag.c",
chuxuezhe1111's avatar
chuxuezhe1111 已提交
707 708
      "./porting/linux/user/src/hook/musl_preinit.c",
      "./porting/linux/user/src/hook/musl_preinit_common.c",
709 710 711
      "./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 已提交
712 713 714 715 716 717 718 719
    ]

    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 已提交
720
      "//third_party/musl:musl_copy_inc_fortify",
chuxuezhe1111's avatar
chuxuezhe1111 已提交
721
      "//third_party/musl:musl_copy_inc_root",
C
chenjianwen 已提交
722
      "//third_party/musl:musl_copy_inc_sys",
chuxuezhe1111's avatar
chuxuezhe1111 已提交
723
    ]
724
    if (!startup_init_with_param_base) {
J
jwz 已提交
725
      defines = [ "OHOS_ENABLE_PARAMETER" ]
J
jwz 已提交
726 727
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
chuxuezhe1111's avatar
chuxuezhe1111 已提交
728 729 730 731 732

    configs -= musl_inherited_configs

    configs += [
      "//build/config/compiler:compiler",
X
xxlight 已提交
733
      ":soft_hook",
chuxuezhe1111's avatar
chuxuezhe1111 已提交
734 735 736
    ]
  }

C
ChenJie 已提交
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
  source_set("soft_musl_jemalloc") {
    sources = [ "./porting/linux/user/src/malloc/jemalloc/jemalloc.c" ]

    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 已提交
755
  static_library("soft_libc_musl_static") {
W
weichaox 已提交
756 757 758 759 760 761 762
    output_name = "libc"
    complete_static_lib = true

    configs -= musl_inherited_configs

    output_dir = "${target_out_dir}/${_libs_out_dir}"
    deps = [
X
xxlight 已提交
763
      ":soft_musl_hook",
M
maweiye 已提交
764
      ":soft_musl_ldso",
X
xxlight 已提交
765 766
      ":soft_musl_src",
      ":soft_musl_src_nossp",
767
      ":soft_musl_src_optimize",
W
weichaox 已提交
768
    ]
769
    deps += dfx_deps
770
    if (!startup_init_with_param_base) {
M
Mupceet 已提交
771 772
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
W
weichaox 已提交
773 774
  }

X
xxlight 已提交
775
  static_library("soft_libm") {
W
weichaox 已提交
776 777 778 779 780 781
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libm"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
782
  static_library("soft_librt") {
W
weichaox 已提交
783 784 785 786 787 788
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "librt"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
789
  static_library("soft_libpthread") {
W
weichaox 已提交
790 791 792 793 794 795
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libpthread"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
796
  static_library("soft_libcrypt") {
W
weichaox 已提交
797 798 799 800 801 802
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libcrypt"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
803
  static_library("soft_libutil") {
W
weichaox 已提交
804 805 806 807 808 809
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libutil"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
810
  static_library("soft_libresolv") {
W
weichaox 已提交
811 812 813 814 815 816
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libresolv"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
817
  static_library("soft_libxnet") {
W
weichaox 已提交
818 819 820 821 822 823
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libxnet"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
824
  static_library("soft_libdl") {
W
weichaox 已提交
825 826 827 828 829 830
    complete_static_lib = true
    configs -= musl_inherited_configs
    output_name = "libdl"
    output_dir = "${target_out_dir}/${_libs_out_dir}"
  }

X
xxlight 已提交
831
  shared_library("soft_libc_musl_shared") {
W
weichaox 已提交
832 833 834 835 836 837 838
    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 已提交
839 840
    musl_lib_path = rebase_path("${target_out_dir}/${_libs_out_dir}")

M
maweiye 已提交
841 842 843
    libc_map_path =
        rebase_path("${target_out_dir}/${musl_ported_dir}/libc.map.txt")

W
weichaox 已提交
844 845 846 847 848
    ldflags = [
      "-nostdlib",
      "-Wl,-e,_dlstart",
      "-L${libclang_rt_path}",
      "-lclang_rt.builtins",
D
dhy308 已提交
849 850 851 852
      "-lunwind",
      "-L${musl_lib_path}",
      "-ldl",
      "-lpthread",
M
maweiye 已提交
853
      "-Wl,--version-script=${libc_map_path}",
W
weichaox 已提交
854 855 856 857
    ]

    configs -= musl_inherited_configs
    configs -= [ "//build/config:default_libs" ]
X
xxlight 已提交
858
    configs += [ ":soft_musl_config" ]
W
weichaox 已提交
859 860

    deps = [
X
xxlight 已提交
861 862 863 864 865 866 867
      ":soft_libdl",
      ":soft_libpthread",
      ":soft_musl_crt_install_action",
      ":soft_musl_hook",
      ":soft_musl_ldso",
      ":soft_musl_src",
      ":soft_musl_src_nossp",
868
      ":soft_musl_src_optimize",
W
weichaox 已提交
869
    ]
870
    deps += dfx_deps
871
    if (!startup_init_with_param_base) {
M
Mupceet 已提交
872 873
      deps += [ "//base/startup/init/services/param/base:parameterbase" ]
    }
C
ChenJie 已提交
874 875 876 877

    if (use_jemalloc) {
      deps += [ ":soft_musl_jemalloc" ]
    }
W
weichaox 已提交
878 879
  }

X
xxlight 已提交
880
  action_foreach("soft_musl_crt_install_action") {
W
weichaox 已提交
881 882 883
    redir = "${root_out_dir}/obj"
    script = "${target_out_dir}/${musl_ported_dir}/scripts/install.py"
    sources = [
X
xxlight 已提交
884 885
      "${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 已提交
886 887 888
      "${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 已提交
889
    ]
D
dhy308 已提交
890

H
hhj 已提交
891
    outputs = [ "${root_build_dir}/obj/third_party/musl/${_libs_out_dir}/{{source_file_part}}" ]
D
dhy308 已提交
892 893 894 895 896 897 898 899 900 901

    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 已提交
902 903 904 905 906
    args = [
      "--input",
      "{{source}}",
    ]
    args += [ "--output" ] + rebase_path(outputs, root_build_dir)
D
dhy308 已提交
907 908 909 910 911
    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 已提交
912
    deps = [ ":soft_musl_crt" ]
W
weichaox 已提交
913 914
  }

X
xxlight 已提交
915 916
  copy("soft_create_linker") {
    deps = [ ":soft_libc_musl_shared" ]
W
weichaox 已提交
917

X
xxlight 已提交
918
    # _libc_shared_outputs = get_target_outputs(":soft_libc_musl_shared")
W
weichaox 已提交
919 920
    _libc_shared_so = "${target_out_dir}/${_libs_out_dir}/libc.so"
    sources = [ _libc_shared_so ]
C
Caoruihong 已提交
921 922 923 924 925
    if (is_asan) {
      asan = "-asan"
    } else {
      asan = ""
    }
X
xxlight 已提交
926
    _muls_linker_so = "${root_out_dir}/common/common/libc/${_libs_path_prefix}/ld-musl-${musl_arch}${asan}.so.1"
W
weichaox 已提交
927 928 929
    outputs = [ _muls_linker_so ]
  }
}