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