diff --git a/build/config/BUILD.gn b/build/config/BUILD.gn index 1323361d8ae47e822b9471db9261c7be6c8e58c5..15230024b42ffb83cd6aa1b2e5e359ade8314a02 100644 --- a/build/config/BUILD.gn +++ b/build/config/BUILD.gn @@ -24,6 +24,13 @@ config("executable_config") { ] if (current_os == "linux") { ldflags += [ "-lpthread" ] + if (ark_standalone_build && is_asan) { + cflags += [ "-fsanitize=address" ] + ldflags += [ + "-lasan", + "-lubsan", + ] + } } } if (is_ohos) { @@ -40,7 +47,15 @@ config("executable_config") { # This config defines the configs applied to all shared libraries. config("shared_library_config") { configs = [] - + if (current_os == "linux") { + if (ark_standalone_build && is_asan) { + cflags = [ "-fsanitize=address" ] + ldflags = [ + "-lasan", + "-lubsan", + ] + } + } if (is_mac) { configs += [ "$build_root/config/mac:mac_dynamic_flags" ] } diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 6f9d1fbf83b1b05c217d61cb5bc14e7254e82976..509b1dc06a057e1de48b8ad735aa65f3e7d0c617 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -21,6 +21,8 @@ declare_args() { timeout = 1200 } +import("$build_root/config/sanitizers/sanitizers.gni") + check_mac_system_and_cpu_script = rebase_path("$build_root/scripts/check_mac_system_and_cpu.py") check_darwin_system_result = diff --git a/build/config/sanitizers/sanitizers.gni b/build/config/sanitizers/sanitizers.gni index effba924bb58361d2692125246431d8470e0e749..210f2b610c35421dff4794367cecdfdd7c83864d 100644 --- a/build/config/sanitizers/sanitizers.gni +++ b/build/config/sanitizers/sanitizers.gni @@ -14,6 +14,8 @@ declare_args() { is_asan = false + use_hwasan = false + is_ubsan_vptr = false is_safestack = false diff --git a/build/templates/cxx/external_deps_handler.py b/build/templates/cxx/external_deps_handler.py index 82107af743099cb05a511846ed371f86396e46bf..828d672dc17f5d1b0a0b9f50ff404cb9a0355523 100755 --- a/build/templates/cxx/external_deps_handler.py +++ b/build/templates/cxx/external_deps_handler.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -139,6 +139,11 @@ def main(): "json/dummy_bundle.json".format(args.root_src_dir)) target_name = dep.split(":")[1] deps.append(get_full_path_from_target_name(config_info, target_name)) + elif dep.startswith("vixl"): + config_info = read_json_file("{}arkcompiler/toolchain/build/third_party_gn/" \ + "vixl/dummy_bundle.json".format(args.root_src_dir)) + target_name = dep.split(":")[1] + deps.append(get_full_path_from_target_name(config_info, target_name)) else: print("Component in which the external_dep defined is ommited in the logic of {}!".format(__file__)) sys.exit(1) diff --git a/build/third_party_gn/asmjit/BUILD.gn b/build/third_party_gn/asmjit/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..cced83c4650161673e3fa1a0c8081f94c25a23ce --- /dev/null +++ b/build/third_party_gn/asmjit/BUILD.gn @@ -0,0 +1,167 @@ +# Copyright (c) 2021-2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/ark.gni") + +ark_root = "//arkcompiler/runtime_core/static_core/" + +config("asmjit_public_config") { + include_dirs = [ + "//third_party/asmjit/src", + ] +} + +config("asmjit_config") { + cflags_cc = [ + "-Wno-bitwise-instead-of-logical", + "-Wno-unused-but-set-variable", + "-Wno-deprecated-copy" + ] +} + +asmjit_sources = [ + "//third_party/asmjit/src/asmjit/asmjit.h", + + "//third_party/asmjit/src/asmjit/core.h", + "//third_party/asmjit/src/asmjit/core/api-build_p.h", + "//third_party/asmjit/src/asmjit/core/api-config.h", + "//third_party/asmjit/src/asmjit/core/arch.cpp", + "//third_party/asmjit/src/asmjit/core/arch.h", + "//third_party/asmjit/src/asmjit/core/assembler.cpp", + "//third_party/asmjit/src/asmjit/core/assembler.h", + "//third_party/asmjit/src/asmjit/core/builder.cpp", + "//third_party/asmjit/src/asmjit/core/builder.h", + "//third_party/asmjit/src/asmjit/core/callconv.cpp", + "//third_party/asmjit/src/asmjit/core/callconv.h", + "//third_party/asmjit/src/asmjit/core/codebuffer.h", + "//third_party/asmjit/src/asmjit/core/codebufferwriter_p.h", + "//third_party/asmjit/src/asmjit/core/codeholder.cpp", + "//third_party/asmjit/src/asmjit/core/codeholder.h", + "//third_party/asmjit/src/asmjit/core/compiler.cpp", + "//third_party/asmjit/src/asmjit/core/compiler.h", + "//third_party/asmjit/src/asmjit/core/constpool.cpp", + "//third_party/asmjit/src/asmjit/core/constpool.h", + "//third_party/asmjit/src/asmjit/core/cpuinfo.cpp", + "//third_party/asmjit/src/asmjit/core/cpuinfo.h", + "//third_party/asmjit/src/asmjit/core/datatypes.h", + "//third_party/asmjit/src/asmjit/core/emitter.cpp", + "//third_party/asmjit/src/asmjit/core/emitter.h", + "//third_party/asmjit/src/asmjit/core/emitterutils.cpp", + "//third_party/asmjit/src/asmjit/core/emitterutils_p.h", + "//third_party/asmjit/src/asmjit/core/environment.cpp", + "//third_party/asmjit/src/asmjit/core/environment.h", + "//third_party/asmjit/src/asmjit/core/errorhandler.cpp", + "//third_party/asmjit/src/asmjit/core/errorhandler.h", + "//third_party/asmjit/src/asmjit/core/features.h", + "//third_party/asmjit/src/asmjit/core/formatter.cpp", + "//third_party/asmjit/src/asmjit/core/formatter.h", + "//third_party/asmjit/src/asmjit/core/func.cpp", + "//third_party/asmjit/src/asmjit/core/func.h", + "//third_party/asmjit/src/asmjit/core/globals.cpp", + "//third_party/asmjit/src/asmjit/core/globals.h", + "//third_party/asmjit/src/asmjit/core/inst.cpp", + "//third_party/asmjit/src/asmjit/core/inst.h", + "//third_party/asmjit/src/asmjit/core/jitallocator.cpp", + "//third_party/asmjit/src/asmjit/core/jitallocator.h", + "//third_party/asmjit/src/asmjit/core/jitruntime.cpp", + "//third_party/asmjit/src/asmjit/core/jitruntime.h", + "//third_party/asmjit/src/asmjit/core/logger.cpp", + "//third_party/asmjit/src/asmjit/core/logger.h", + "//third_party/asmjit/src/asmjit/core/misc_p.h", + "//third_party/asmjit/src/asmjit/core/operand.cpp", + "//third_party/asmjit/src/asmjit/core/operand.h", + "//third_party/asmjit/src/asmjit/core/osutils.cpp", + "//third_party/asmjit/src/asmjit/core/osutils.h", + "//third_party/asmjit/src/asmjit/core/raassignment_p.h", + "//third_party/asmjit/src/asmjit/core/rabuilders_p.h", + "//third_party/asmjit/src/asmjit/core/radefs_p.h", + "//third_party/asmjit/src/asmjit/core/ralocal.cpp", + "//third_party/asmjit/src/asmjit/core/ralocal_p.h", + "//third_party/asmjit/src/asmjit/core/rapass.cpp", + "//third_party/asmjit/src/asmjit/core/rapass_p.h", + "//third_party/asmjit/src/asmjit/core/rastack.cpp", + "//third_party/asmjit/src/asmjit/core/rastack_p.h", + "//third_party/asmjit/src/asmjit/core/string.cpp", + "//third_party/asmjit/src/asmjit/core/string.h", + "//third_party/asmjit/src/asmjit/core/support.cpp", + "//third_party/asmjit/src/asmjit/core/support.h", + "//third_party/asmjit/src/asmjit/core/target.cpp", + "//third_party/asmjit/src/asmjit/core/target.h", + "//third_party/asmjit/src/asmjit/core/type.cpp", + "//third_party/asmjit/src/asmjit/core/type.h", + "//third_party/asmjit/src/asmjit/core/virtmem.cpp", + "//third_party/asmjit/src/asmjit/core/virtmem.h", + "//third_party/asmjit/src/asmjit/core/zone.cpp", + "//third_party/asmjit/src/asmjit/core/zone.h", + "//third_party/asmjit/src/asmjit/core/zonehash.cpp", + "//third_party/asmjit/src/asmjit/core/zonehash.h", + "//third_party/asmjit/src/asmjit/core/zonelist.cpp", + "//third_party/asmjit/src/asmjit/core/zonelist.h", + "//third_party/asmjit/src/asmjit/core/zonestack.cpp", + "//third_party/asmjit/src/asmjit/core/zonestack.h", + "//third_party/asmjit/src/asmjit/core/zonestring.h", + "//third_party/asmjit/src/asmjit/core/zonetree.cpp", + "//third_party/asmjit/src/asmjit/core/zonetree.h", + "//third_party/asmjit/src/asmjit/core/zonevector.cpp", + "//third_party/asmjit/src/asmjit/core/zonevector.h", + + "//third_party/asmjit/src/asmjit/x86.h", + "//third_party/asmjit/src/asmjit/x86/x86archdata.cpp", + "//third_party/asmjit/src/asmjit/x86/x86archdata_p.h", + "//third_party/asmjit/src/asmjit/x86/x86assembler.cpp", + "//third_party/asmjit/src/asmjit/x86/x86assembler.h", + "//third_party/asmjit/src/asmjit/x86/x86builder.cpp", + "//third_party/asmjit/src/asmjit/x86/x86builder.h", + "//third_party/asmjit/src/asmjit/x86/x86callconv.cpp", + "//third_party/asmjit/src/asmjit/x86/x86callconv_p.h", + "//third_party/asmjit/src/asmjit/x86/x86compiler.cpp", + "//third_party/asmjit/src/asmjit/x86/x86compiler.h", + "//third_party/asmjit/src/asmjit/x86/x86emitter.h", + "//third_party/asmjit/src/asmjit/x86/x86features.cpp", + "//third_party/asmjit/src/asmjit/x86/x86features.h", + "//third_party/asmjit/src/asmjit/x86/x86formatter.cpp", + "//third_party/asmjit/src/asmjit/x86/x86formatter_p.h", + "//third_party/asmjit/src/asmjit/x86/x86globals.h", + "//third_party/asmjit/src/asmjit/x86/x86internal.cpp", + "//third_party/asmjit/src/asmjit/x86/x86internal_p.h", + "//third_party/asmjit/src/asmjit/x86/x86instdb.cpp", + "//third_party/asmjit/src/asmjit/x86/x86instdb.h", + "//third_party/asmjit/src/asmjit/x86/x86instdb_p.h", + "//third_party/asmjit/src/asmjit/x86/x86instapi.cpp", + "//third_party/asmjit/src/asmjit/x86/x86instapi_p.h", + "//third_party/asmjit/src/asmjit/x86/x86operand.cpp", + "//third_party/asmjit/src/asmjit/x86/x86operand.h", + "//third_party/asmjit/src/asmjit/x86/x86rapass.cpp", + "//third_party/asmjit/src/asmjit/x86/x86rapass_p.h", +] + +asmjit_configs = [ + ":asmjit_public_config", + "$ark_root:ark_config", + "$ark_root/libpandabase:arkbase_public_config", + ":asmjit_config", +] + +ohos_static_library("libasmjit") { + sources = asmjit_sources + configs = asmjit_configs + deps = [ "$ark_root/libpandabase:libarktsbase" ] + subsystem_name = "ark_subsystem_name" +} + +ohos_static_library("libasmjit_frontend_static") { + sources = asmjit_sources + configs = asmjit_configs + deps = [ "$ark_root/libpandabase:libarktsbase_frontend_static" ] + subsystem_name = "ark_subsystem_name" +} diff --git a/build/third_party_gn/asmjit/dummy_bundle.json b/build/third_party_gn/asmjit/dummy_bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..8db0daa75491abf4c9626bd9125a47a2da75217e --- /dev/null +++ b/build/third_party_gn/asmjit/dummy_bundle.json @@ -0,0 +1,22 @@ +{ + "component": { + "build": { + "inner_kits": [ + { + "header": { + "header_base": "//third_party/asmjit", + "header_files": "" + }, + "name": "//arkcompiler/toolchain/build/third_party_gn/asmjit:libasmjit" + }, + { + "header": { + "header_base": "//third_party/zlib", + "header_files": "" + }, + "name": "//arkcompiler/toolchain/build/third_party_gn/asmjit:libasmjit_frontend_static" + } + ] + } + } +} \ No newline at end of file diff --git a/build/third_party_gn/vixl/BUILD.gn b/build/third_party_gn/vixl/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d9ba636b734776b77a1adfbc60321b882d87691d --- /dev/null +++ b/build/third_party_gn/vixl/BUILD.gn @@ -0,0 +1,142 @@ +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of ARM Limited nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("$build_root/ark.gni") + +config("vixl_public_config") { + defines = [] + if (is_debug) { + defines += [ "VIXL_DEBUG" ] + } + + defines += [ "PANDA_BUILD" ] + + if (defined(ark_standalone_build) && ark_standalone_build) { + cflags_cc = [ "-Wno-bitwise-instead-of-logical" ] + } + + include_dirs = [ + "//third_party/vixl", + "//third_party/vixl/src", + ] + if (target_cpu == "arm") { + include_dirs += [ "//third_party/vixl/src/aarch32" ] + } else if (target_cpu == "arm64" || target_cpu == "amd64" || + target_cpu == "x64" || target_cpu == "x86_64") { + include_dirs += [ "//third_party/vixl/src/aarch64" ] + } +} + +ohos_static_library("libvixl") { + sources = [ + "//third_party/vixl/src/code-buffer-vixl.cc", + "//third_party/vixl/src/compiler-intrinsics-vixl.cc", + "//third_party/vixl/src/cpu-features.cc", + "//third_party/vixl/src/utils-vixl.cc", + ] + + defines = [] + cflags_cc = [ + "-std=c++17", + "-pedantic", + "-Wall", + "-Wextra", + "-Werror", + "-fno-rtti", + "-fno-exceptions", + "-Wno-invalid-offsetof", + + "-Wno-gnu-statement-expression", + "-Wno-unused-parameter", + "-Wno-unused-result", + "-Wno-deprecated-declarations", + ] + if (is_debug) { + cflags_cc += [ + "-Og", + "-ggdb3", + "-gdwarf-4", + ] + } + + if (is_asan) { + cflags_cc += [ "-g" ] + defines += [ "__SANITIZE_ADDRESS__" ] + } + + if (target_cpu == "arm") { + sources += [ + "//third_party/vixl/src/aarch32/assembler-aarch32.cc", + "//third_party/vixl/src/aarch32/constants-aarch32.cc", + "//third_party/vixl/src/aarch32/disasm-aarch32.cc", + "//third_party/vixl/src/aarch32/instructions-aarch32.cc", + "//third_party/vixl/src/aarch32/location-aarch32.cc", + "//third_party/vixl/src/aarch32/macro-assembler-aarch32.cc", + "//third_party/vixl/src/aarch32/operands-aarch32.cc", + ] + defines += [ "VIXL_INCLUDE_TARGET_A32" ] + } else if (target_cpu == "arm64" || target_cpu == "amd64" || + target_cpu == "x64" || target_cpu == "x86_64") { + sources += [ + "//third_party/vixl/src/aarch64/assembler-aarch64.cc", + "//third_party/vixl/src/aarch64/assembler-sve-aarch64.cc", + "//third_party/vixl/src/aarch64/cpu-aarch64.cc", + "//third_party/vixl/src/aarch64/cpu-features-auditor-aarch64.cc", + "//third_party/vixl/src/aarch64/debugger-aarch64.cc", + "//third_party/vixl/src/aarch64/decoder-aarch64.cc", + "//third_party/vixl/src/aarch64/disasm-aarch64.cc", + "//third_party/vixl/src/aarch64/instructions-aarch64.cc", + "//third_party/vixl/src/aarch64/logic-aarch64.cc", + "//third_party/vixl/src/aarch64/macro-assembler-aarch64.cc", + "//third_party/vixl/src/aarch64/macro-assembler-sve-aarch64.cc", + "//third_party/vixl/src/aarch64/operands-aarch64.cc", + "//third_party/vixl/src/aarch64/pointer-auth-aarch64.cc", + "//third_party/vixl/src/aarch64/simulator-aarch64.cc", + ] + defines += [ + "VIXL_INCLUDE_TARGET_A64", + "VIXL_INCLUDE_SIMULATOR_AARCH64", + ] + } + if (current_cpu == "arm") { + cflags_cc += [ + "-march=armv7-a", + "-mfloat-abi=softfp", + "-marm", + "-mfpu=vfp", + ] + } + + if (is_mac) { + cflags_cc += [ "-DVIXL_CODE_BUFFER_MALLOC" ] + } else { + cflags_cc += [ "-DVIXL_CODE_BUFFER_MMAP" ] + } + + public_configs = [ ":vixl_public_config" ] + + subsystem_name = "thirdparty" + part_name = "vixl" +} diff --git a/build/third_party_gn/vixl/dummy_bundle.json b/build/third_party_gn/vixl/dummy_bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..40b9cd3daaef8e677d4d78f98838b19878dccc81 --- /dev/null +++ b/build/third_party_gn/vixl/dummy_bundle.json @@ -0,0 +1,15 @@ +{ + "component": { + "build": { + "inner_kits": [ + { + "header": { + "header_base": "//third_party/vixl", + "header_files": "" + }, + "name": "//arkcompiler/toolchain/build/third_party_gn/vixl:libvixl" + } + ] + } + } +} \ No newline at end of file diff --git a/build/third_party_gn/zydis/BUILD.gn b/build/third_party_gn/zydis/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ab90739dc5801872d5db84341e12a64165f21197 --- /dev/null +++ b/build/third_party_gn/zydis/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + +import("$build_root/ark.gni") + +config("zydis_public_config") { + include_dirs = [ + "//third_party/zydis/include", + "//third_party/zydis/zycore/include", + "//third_party/zydis/src", + ] +} + +ohos_static_library("libZydis") { + sources = [ + "//third_party/zydis/include/Zydis/Decoder.h", + "//third_party/zydis/include/Zydis/DecoderTypes.h", + "//third_party/zydis/include/Zydis/Formatter.h", + "//third_party/zydis/include/Zydis/FormatterBuffer.h", + "//third_party/zydis/include/Zydis/Internal/DecoderData.h", + "//third_party/zydis/include/Zydis/Internal/FormatterATT.h", + "//third_party/zydis/include/Zydis/Internal/FormatterBase.h", + "//third_party/zydis/include/Zydis/Internal/FormatterIntel.h", + "//third_party/zydis/include/Zydis/Internal/SharedData.h", + "//third_party/zydis/include/Zydis/Internal/String.h", + "//third_party/zydis/include/Zydis/MetaInfo.h", + "//third_party/zydis/include/Zydis/Mnemonic.h", + "//third_party/zydis/include/Zydis/Register.h", + "//third_party/zydis/include/Zydis/SharedTypes.h", + "//third_party/zydis/include/Zydis/ShortString.h", + "//third_party/zydis/include/Zydis/Status.h", + "//third_party/zydis/include/Zydis/Utils.h", + "//third_party/zydis/include/Zydis/Zydis.h", + "//third_party/zydis/src/Decoder.c", + "//third_party/zydis/src/DecoderData.c", + "//third_party/zydis/src/Formatter.c", + "//third_party/zydis/src/FormatterATT.c", + "//third_party/zydis/src/FormatterBase.c", + "//third_party/zydis/src/FormatterBuffer.c", + "//third_party/zydis/src/FormatterIntel.c", + "//third_party/zydis/src/MetaInfo.c", + "//third_party/zydis/src/Mnemonic.c", + "//third_party/zydis/src/Register.c", + "//third_party/zydis/src/SharedData.c", + "//third_party/zydis/src/String.c", + "//third_party/zydis/src/Utils.c", + "//third_party/zydis/src/Zydis.c", + ] + + configs = [ ":zydis_public_config" ] +} diff --git a/build/third_party_gn/zydis/dummy_bundle.json b/build/third_party_gn/zydis/dummy_bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..83037eb89b6e881ecc347dbd250fae7499d5d876 --- /dev/null +++ b/build/third_party_gn/zydis/dummy_bundle.json @@ -0,0 +1,15 @@ +{ + "component": { + "build": { + "inner_kits": [ + { + "header": { + "header_base": "//third_party/zydis", + "header_files": "" + }, + "name": "//arkcompiler/toolchain/build/third_party_gn/zydis:libZydis" + } + ] + } + } +} \ No newline at end of file