diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py index c3fba73276e37a7aafa0ef242488f934205e5ecd..0ecc55a3d836670d95f22eaba4c275f2b685768f 100755 --- a/build/compile_script/ark.py +++ b/build/compile_script/ark.py @@ -174,6 +174,14 @@ class ArkPy: "gn_args": ["target_os=\"mac\"", "target_cpu=\"x86\""], "prefix_of_name_of_out_dir_of_second_level": "mac_x86", }, + "ohos_loongarch64": { + "flags": ["ohos_loongarch64", "loongarch64"], + "description": + "Build for arkcompiler target of target-operating-system ohos and " + "target-central-processing-unit loongarch64.", + "gn_args": ["target_os=\"ohos\"", "target_cpu=\"loongarch64\""], + "prefix_of_name_of_out_dir_of_second_level": "loongarch64", + }, }, "mode": { "release": { @@ -201,6 +209,7 @@ class ArkPy: "description": "Compile arkcompiler target and run test262 with arkcompiler target.", "gn_targets_depend_on": ["default"], "arm64_gn_targets_depend_on": ["ark_js_packages"], + "loongarch64_gn_targets_depend_on": ["ark_js_packages"], }, "unittest": { "flags": ["unittest", "ut"], @@ -317,23 +326,23 @@ class ArkPy: return False @staticmethod - def libs_dir(is_arm, is_aot, is_pgo, out_dir, x64_out_dir) -> str: - if is_arm and is_aot and is_pgo: + def libs_dir(is_arm, is_loongarch64, is_aot, is_pgo, out_dir, x64_out_dir) -> str: + if (is_arm or is_loongarch64) and is_aot and is_pgo: return (f"--libs-dir ../../{out_dir}/arkcompiler/ets_runtime:" f"../../{out_dir}/thirdparty/icu:" f"../../{out_dir}/third_party/icu:" - f"../../thirdparty/zlib:" + f"../../{out_dir}/thirdparty/zlib:" f"../../prebuilts/clang/ohos/linux-x86_64/llvm/lib") - if is_arm and is_aot and not is_pgo: + if (is_arm or is_loongarch64) and is_aot and not is_pgo: return ("--libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" f":../../{x64_out_dir}/thirdparty/icu/") - if not is_arm and is_aot: + if not (is_arm or is_loongarch64) and is_aot: return (f"--libs-dir ../../{out_dir}/arkcompiler/ets_runtime" f":../../{out_dir}/thirdparty/icu:" f"../../{out_dir}/third_party/icu:" - f"../../thirdparty/zlib:" + f"../../{out_dir}/thirdparty/zlib:" f"../../prebuilts/clang/ohos/linux-x86_64/llvm/lib") - # not is_arm and not is_aot + # not is_arm and not is_loongarch64 and not is_aot return " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" @staticmethod @@ -347,8 +356,10 @@ class ArkPy: "--ark-frontend=es2panda" ] is_arm = any('target_cpu="arm64"' in arg for arg in gn_args) - if is_arm: - cmd.append("--ark-arch aarch64") + is_loongarch64 = any('target_cpu="loongarch64"' in arg for arg in gn_args) + if is_arm or is_loongarch64: + ark_arch = "aarch64" if is_arm else "loongarch64" + cmd.append(f"--ark-arch {ark_arch}") cmd.append(f"--ark-arch-root=../../{out_path}/common/common/libc/") cmd.append(f"--ark-frontend-binary=../../{x64_out_path}/arkcompiler/ets_frontend/es2abc") cmd.append(f"--merge-abc-binary=../../{x64_out_path}/arkcompiler/ets_frontend/merge_abc") @@ -366,6 +377,7 @@ class ArkPy: cmd.append(ArkPy.libs_dir( is_arm=is_arm, + is_loongarch64=is_loongarch64, is_aot=aot_mode, is_pgo=run_pgo, out_dir=out_path, @@ -396,13 +408,16 @@ class ArkPy: def get_test262_aot_cmd(gn_args, out_path, x64_out_path, run_pgo, enable_litecg, args_to_test262_cmd, timeout): print("running test262 in AotMode\n") - if any('target_cpu="arm64"' in arg for arg in gn_args): + is_arm = any('target_cpu="arm64"' in arg for arg in gn_args) + is_loongarch64 = any('target_cpu="loongarch64"' in arg for arg in gn_args) + if is_arm or is_loongarch64: + ark_arch = "aarch64" if is_arm else "loongarch64" if run_pgo: test262_cmd = f"cd arkcompiler/ets_frontend && python3 test262/run_test262.py {args_to_test262_cmd}" \ f" --timeout {timeout}" \ f" --libs-dir ../../{out_path}/arkcompiler/ets_runtime:../../{out_path}/thirdparty/icu:" \ f"../../{out_path}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-arch aarch64" \ + f" --ark-arch {ark_arch}" \ f" --ark-arch-root=../../{out_path}/common/common/libc/" \ f" --ark-tool=../../{out_path}/arkcompiler/ets_runtime/ark_js_vm" \ f" --ark-aot-tool=../../{out_path}/arkcompiler/ets_runtime/ark_aot_compiler" \ @@ -414,7 +429,8 @@ class ArkPy: else: test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{2}/thirdparty/icu/" \ - " --ark-arch aarch64" \ + ":../../{2}/thirdparty/zlib" \ + f" --ark-arch {ark_arch}" \ " --ark-arch-root=../../{1}/common/common/libc/" \ " --ark-aot" \ " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ @@ -443,12 +459,15 @@ class ArkPy: def get_jit_cmd(test_suite, test_script_name, test_script_path, gn_args, out_path, x64_out_path, args_to_cmd, timeout): print(f"running {test_suite} in JIT mode\n") - if any('target_cpu="arm64"' in arg for arg in gn_args): + is_arm = any('target_cpu="arm64"' in arg for arg in gn_args) + is_loongarch64 = any('target_cpu="loongarch64"' in arg for arg in gn_args) + if is_arm or is_loongarch64: + ark_arch = "aarch64" if is_arm else "loongarch64" cmd = f"cd {test_script_path} && python3 {test_script_name} {args_to_cmd} --timeout {timeout}" \ f" --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{out_path}/thirdparty/icu/" \ f":../../{out_path}/thirdparty/bounds_checking_function" \ f":../../{out_path}/arkcompiler/ets_runtime:" \ - " --ark-arch aarch64" \ + f" --ark-arch {ark_arch}" \ " --run-jit" \ f" --ark-arch-root=../../{out_path}/common/common/libc/" \ f" --ark-aot-tool=../../{x64_out_path}/arkcompiler/ets_runtime/ark_aot_compiler" \ @@ -471,15 +490,18 @@ class ArkPy: def get_baseline_jit_cmd(test_suite, test_script_name, test_script_path, gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout): print(f"running {test_suite} in baseline JIT mode\n") - if any('target_cpu="arm64"' in arg for arg in gn_args): + is_arm = any('target_cpu="arm64"' in arg for arg in gn_args) + is_loongarch64 = any('target_cpu="loongarch64"' in arg for arg in gn_args) + if is_arm or is_loongarch64: + ark_arch = "aarch64" if is_arm else "loongarch64" cmd = f"cd {test_script_path} && python3 {test_script_name} {args_to_test262_cmd} --timeout {timeout}" \ f" --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ f":../../{out_path}/thirdparty/icu" \ - f":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos" \ + f":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib/{ark_arch}-linux-ohos" \ f":../../{out_path}/thirdparty/bounds_checking_function" \ f":../../{out_path}/arkcompiler/ets_runtime" \ f":../../{out_path}/common/common/libc/lib" \ - " --ark-arch aarch64" \ + f" --ark-arch {ark_arch}" \ " --run-baseline-jit" \ f" --ark-arch-root=../../{out_path}/common/common/libc/" \ f" --ark-aot-tool=../../{x64_out_path}/arkcompiler/ets_runtime/ark_aot_compiler" \ @@ -862,6 +884,21 @@ class ArkPy: gn_args, self.ARG_DICT.get("target").get(test_suite).get("arm64_gn_targets_depend_on"), log_file_name) + elif any('target_cpu="loongarch64"' in arg for arg in gn_args): + gn_args.append("so_dir_for_qemu=\"../../{0}/common/common/libc/\"".format(out_path)) + gn_args.append("run_with_qemu=true".format(out_path)) + if not os.path.exists(x64_out_path): + os.makedirs(x64_out_path) + self.build_for_gn_target( + x64_out_path, + ['target_os="linux"', 'target_cpu="x64"', 'is_debug=false'], + self.ARG_DICT.get("target").get(test_suite).get("gn_targets_depend_on"), + log_file_name) + self.build_for_gn_target( + out_path, + gn_args, + self.ARG_DICT.get("target").get(test_suite).get("loongarch64_gn_targets_depend_on"), + log_file_name) else: self.build_for_gn_target( out_path, diff --git a/build/config/ohos/config.gni b/build/config/ohos/config.gni index 1da4bc2f34ba46f5169bac7ff7c17a0cac024247..8e1f7bcdac73614a075a339f5ce9ee5394554c4b 100644 --- a/build/config/ohos/config.gni +++ b/build/config/ohos/config.gni @@ -25,6 +25,8 @@ if (is_ohos) { abi_target = "x86_64-linux-ohos" } else if (current_cpu == "mipsel") { abi_target = "mipsel-linux-ohos" + } else if (current_cpu == "loongarch64") { + abi_target = "loongarch64-linux-ohos" } else { assert(false, "Arch not supported") } diff --git a/build/core/gn/BUILD.gn b/build/core/gn/BUILD.gn index 0d33dffaf7a8ea872dc85aaab88bdaa786594070..bd78df860e1db046ada838572c6fdd60030cd51f 100644 --- a/build/core/gn/BUILD.gn +++ b/build/core/gn/BUILD.gn @@ -59,6 +59,7 @@ group("ets_runtime") { ] if ((target_os == "linux" && target_cpu == "x64") || (target_cpu == "arm64" && target_os == "ohos") || + (target_cpu == "loongarch64" && target_os == "ohos") || (target_cpu == "arm64" && target_os == "mac")) { deps += [ "$js_root/ecmascript/compiler:ark_aot_compiler", diff --git a/build/third_party_gn/musl/musl_config.gni b/build/third_party_gn/musl/musl_config.gni index 52814f23281d1df92cb18d28f97a26720d4e9ab8..decd5ecb1f79857068ae3e61f1f9beda2a5dd9bd 100644 --- a/build/third_party_gn/musl/musl_config.gni +++ b/build/third_party_gn/musl/musl_config.gni @@ -20,6 +20,8 @@ declare_args() { musl_arch = "aarch64" } else if (current_cpu == "mipsel") { musl_arch = "mips" + } else if (current_cpu == "loongarch64") { + musl_arch = "loongarch64" } } diff --git a/build/third_party_gn/musl/musl_template.gni b/build/third_party_gn/musl/musl_template.gni index c62f882fa666d5916e7a52046c09ac0d5266cd17..e22d5fa6c21ca6b94b328c9c4a17a851ff6946b1 100644 --- a/build/third_party_gn/musl/musl_template.gni +++ b/build/third_party_gn/musl/musl_template.gni @@ -348,6 +348,15 @@ template("musl_libs") { "src/string/strncpy.c", ] + if (musl_arch == "loongarch64") { + sources_orig += [ + "src/string/memset.c", + "src/stdlib/qsort.c", + "src/stdlib/qsort_nr.c", + "src/string/strncpy.c", + ] + } + freebsd_files = [ "//third_party/FreeBSD/contrib/gdtoa/strtod.c", "//third_party/FreeBSD/contrib/gdtoa/gethex.c", @@ -613,6 +622,8 @@ template("musl_libs") { "-D__strncmp_aarch64 = strncmp", ] } + } else if (musl_arch == "loongarch64") { + not_needed(freebsd_files) } cflags = [ diff --git a/build/third_party_gn/openssl/BUILD.gn b/build/third_party_gn/openssl/BUILD.gn index cae0e8ea69d4ef5c96eb868b3671c7ee6ae3b524..a882c31bcafefa7fdcfba649edf8b5f3701bac10 100644 --- a/build/third_party_gn/openssl/BUILD.gn +++ b/build/third_party_gn/openssl/BUILD.gn @@ -50,6 +50,9 @@ if (current_cpu == "arm" && !(current_os == "linux" || host_os == "mac")) { } else if (current_cpu == "arm64" && current_os == "android") { print("openssl selected linux-aarch64") openssl_selected_platform = "linux-aarch64" +} else if (current_cpu == "loongarch64" && current_os == "ohos") { + print("openssl selected linux64-loongarch64") + openssl_selected_platform = "linux64-loongarch64" } print( "openssl detecting os done. openssl_selected_platform = ${openssl_selected_platform}") @@ -326,6 +329,13 @@ openssl_internal_cflags = [ "-Wno-unused-but-set-variable", ] +if (current_cpu == "loongarch64") { + openssl_internal_cflags -= [ + "-Wno-error=constant-conversion", + "-Wno-error=macro-redefined", + ] +} + # 升级修改适配检查点9 内部公共头文件目录列表 crypto_config_common_private_include_dirs = [ "//third_party/openssl/", @@ -529,6 +539,19 @@ crypto_config_mingw64_cflags = [ "-DX25519_ASM", ] +crypto_config_linux_loongarch64_cflags = [ + "-DOPENSSL_USE_NODELETE", + "-fPIC", + "-pthread", + "-Wall", + "-O3", + "-DNDEBUG", + "-MMD", + "-MF", + "-DOPENSSL_BUILDING_OPENSSL", + "-DOPENSSL_PIC", +] + crypto_config_current_platform_cflags = [] if (openssl_selected_platform == "linux-armv4") { crypto_config_current_platform_cflags += crypto_config_linux_armv4_cflags @@ -544,6 +567,9 @@ if (openssl_selected_platform == "linux-armv4") { crypto_config_current_platform_cflags += crypto_config_linux_x86_64_cflags } else if (openssl_selected_platform == "mingw64") { crypto_config_current_platform_cflags += crypto_config_mingw64_cflags +} else if (openssl_selected_platform == "linux64-loongarch64") { + crypto_config_current_platform_cflags += + crypto_config_linux_loongarch64_cflags } mingw32_libs_path = [] @@ -1554,6 +1580,35 @@ ohos_source_set("crypto_source") { "//third_party/openssl/crypto/bn/rsaz_exp.c", "//third_party/openssl/crypto/bn/rsaz_exp_x2.c", ] + } else if (openssl_selected_platform == "linux64-loongarch64") { + sources += [ + "//third_party/openssl/crypto/aes/aes_cbc.c", + "//third_party/openssl/crypto/aes/aes_core.c", + "//third_party/openssl/crypto/bn/bn_asm.c", + "//third_party/openssl/crypto/camellia/camellia.c", + "//third_party/openssl/crypto/camellia/cmll_cbc.c", + "//third_party/openssl/crypto/loongarchcap.c", + "//third_party/openssl/crypto/rc4/rc4_enc.c", + "//third_party/openssl/crypto/rc4/rc4_skey.c", + "//third_party/openssl/crypto/whrlpool/wp_block.c", + + # v_check bind_engine multi defined + "//third_party/openssl/engines/e_afalg.c", + + # ChaCha20_ctr32 + # ./crypto/sha/keccak1600.c:1096 SHA3_squeeze func + "//third_party/openssl/crypto/chacha/chacha_enc.c", + "//third_party/openssl/crypto/loongarch64cpuid.S", + "//third_party/openssl/crypto/sha/keccak1600.c", + ] + + sources -= [ + # ecp_nistz256_xxx func + "//third_party/openssl/crypto/ec/ecp_nistz256.c", + + # v_check bind_engine multi defined + "//third_party/openssl/engines/e_capi.c", + ] } configs = [ ":crypto_config_private" ] @@ -1641,6 +1696,7 @@ unused_variables += crypto_config_darwin64_x86_64_cc_cflags unused_variables += crypto_config_darwin64_arm64_cc_cflags unused_variables += crypto_config_linux_x86_64_cflags unused_variables += crypto_config_mingw64_cflags +unused_variables += crypto_config_linux_loongarch64_cflags unused_variables += libcommon_common_sources unused_variables += libdefault_common_sources unused_variables += libcrypto_build_all_generated_linux_armv4_sources diff --git a/build/toolchain/ark/BUILD.gn b/build/toolchain/ark/BUILD.gn index 5bea83dda0136848621e1d039d495392435573bf..298ceda2f29d17168cb15686b5079f6ac1fff957 100644 --- a/build/toolchain/ark/BUILD.gn +++ b/build/toolchain/ark/BUILD.gn @@ -48,3 +48,12 @@ ark_clang_toolchain("ark_clang_mipsel") { current_os = "ohos" } } + +ark_clang_toolchain("ark_clang_loongarch64") { + sysroot = "${musl_sysroot}" + lib_dir = "usr/lib/loongarch64-linux-ohos" + toolchain_args = { + current_cpu = "loongarch64" + current_os = "ohos" + } +} diff --git a/build/toolchain/ark/ark_toolchain.gni b/build/toolchain/ark/ark_toolchain.gni index 2b169d85cc0d2fb79875dab84b0b3160c4c78eef..ee696b931365dc1321ff15dd3d0e088990e6f134 100644 --- a/build/toolchain/ark/ark_toolchain.gni +++ b/build/toolchain/ark/ark_toolchain.gni @@ -32,6 +32,8 @@ template("ark_clang_toolchain") { abi_target = "aarch64-linux-ohos" } else if (invoker.target_name == "ark_clang_x86_64") { abi_target = "x86_64-linux-ohos" + } else if (invoker.target_name == "ark_clang_loongarch64") { + abi_target = "loongarch64-linux-ohos" } clang_rt_dir =