diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cpp b/compiler-rt/lib/tsan/rtl/tsan_report.cpp index b5481eb8b340c3367ae549d93570ebc409000642..ae59355b7f582bec814ecb0375047123254e3e9c 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_report.cpp @@ -376,6 +376,7 @@ void PrintReport(const ReportDesc *rep) { DumpProcessMap(); Printf("==================\n"); + Printf("End Tsan report\n"); // OHOS_LOCAL } #else // #if !SANITIZER_GO diff --git a/llvm-build/MakeLiblzma b/llvm-build/MakeLiblzma index 4f4ceff1e6c3f9da51c886fef158b0495e8a91ce..4970b9f9803323e8fd6deabe642bef9712eb1a70 100644 --- a/llvm-build/MakeLiblzma +++ b/llvm-build/MakeLiblzma @@ -15,7 +15,7 @@ SYSROOT := INSTALL_DIR := TARGET_TRIPLE := CC := -SRCS := 7zAlloc.c 7zArcIn.c 7zBuf2.c 7zBuf.c 7zCrc.c 7zCrcOpt.c 7zDec.c 7zFile.c 7zStream.c Aes.c AesOpt.c Alloc.c Bcj2.c Bra86.c Bra.c BraIA64.c CpuArch.c Delta.c LzFind.c Lzma2Dec.c Lzma2Enc.c Lzma86Dec.c Lzma86Enc.c LzmaDec.c LzmaEnc.c LzmaLib.c Ppmd7.c Ppmd7Dec.c Ppmd7Enc.c Sha256.c Sha256Opt.c Sort.c Xz.c XzCrc64.c XzCrc64Opt.c XzDec.c XzEnc.c XzIn.c +SRCS := 7zAlloc.c 7zArcIn.c 7zBuf2.c 7zBuf.c 7zCrc.c 7zCrcOpt.c 7zDec.c 7zFile.c 7zStream.c Aes.c AesOpt.c Alloc.c Bcj2.c Bra86.c Bra.c BraIA64.c CpuArch.c Delta.c LzFind.c Lzma2Dec.c Lzma2Enc.c Lzma86Dec.c Lzma86Enc.c LzmaDec.c LzmaEnc.c LzmaLib.c Ppmd7.c Ppmd7Dec.c Ppmd7Enc.c Sha256.c Sha256Opt.c Sort.c Xz.c XzCrc64.c XzCrc64Opt.c XzDec.c XzEnc.c XzIn.c MtDec.c MtCoder.c LzFindMt.c LzFindOpt.c Threads.c SRC_PREFIX := LIB_VERSION := diff --git a/llvm-build/Makefile b/llvm-build/Makefile index ecb982228b0ecbb4d4dca3e65e1b2e9e62087551..79c3c413ccb9d1e63d0966881eb5d41a83f62458 100644 --- a/llvm-build/Makefile +++ b/llvm-build/Makefile @@ -92,7 +92,11 @@ endif endif ifeq ($(ARCH),aarch64) +ifeq ($(BUILD_DEBUG),true) +CFLAGS = -march=armv8 -g -gdwarf-4 -O0 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack +else CFLAGS = -march=armv8 -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack +endif else ifeq ($(ARCH),riscv64) CFLAGS = -march=rv64gc -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack @@ -225,7 +229,9 @@ musl_install_for_linux_user: musl_patch_for_linux_user make -sj install clean: + ifeq ($(BUILD_DEBUG),false) $(HIDE) rm -rf musl_copy_for_* linux_header_install_for_* + endif distclean: clean $(HIDE) rm -rf $(SYSROOTDIR)/lib $(SYSROOTDIR)/usr diff --git a/llvm-build/README.md b/llvm-build/README.md index 407b4b4c1871c8a6e602fbe357d1ea7e77433bef..fbf67c6362eb3e57431e0ab3838e4c30c69440b9 100644 --- a/llvm-build/README.md +++ b/llvm-build/README.md @@ -75,7 +75,7 @@ build.py options: --build-instrumented # enable instrument pgo when build toolchain --xunit-xml-output # specify LLVM unit test XML report path --build-lldb-static # build statically lldb tool for ARM and AARCH64 ---build-python # build python (not using prebuilt one, currently effective for Windows) +--build-python # build python (not using prebuilt one, currently effective for Windows and OHOS) --build-ncurses # build ncurses tool for linux, Mac x86-64 or M1 --build-libedit # build libedit tool for linux, Mac x86-64 or M1 --build-libxml2 # build libxml2 tool for linux, windows, Mac x86_64 or M1 @@ -91,6 +91,13 @@ build.py options: OH LLVM BOTH +--build-only # build only some targets, skip building windows, lldb-server and package step + lld + llvm-readelf + llvm-objdump + musl + compiler-rt + libcxx --enable-check-abi # Check libc++_shared.so ABI. If the ABI was changed then interrupt a build process and report an error. ```
@@ -145,6 +152,10 @@ build-ohos-aarch64.py options: --enable-assertions # enable assertion when compiling --debug # build debug version llvm toolchain --strip # strip llvm toolchain binaries +--build-python # build python and enable script in debugger +--build-ncurses # build ncurses and enable ncurses in debugger +--build-libedit # build libedit and enable libedit in debugger +--build-libxml2 # build libxml2 and enable libxml in debugger ```
@@ -154,6 +165,33 @@ When build successfully completed, artifacts will be available in `out/ohos-aarc ## Function Introduction
+### Build process of Arm debugger + +First build toolchain on Linux. +Here is an example of starting build process on Linux: +``` +# build +python3 ./toolchain/llvm-project/llvm-build/build-ohos-arm.py +``` + +
+ +build-ohos-arm.py options: + +``` +--build-python # build python and enable script in debugger +--build-ncurses # build ncurses and enable ncurses in debugger +--build-libedit # build libedit and enable libedit in debugger +--build-libxml2 # build libxml2 and enable libxml in debugger +``` +
+ +When build successfully completed, artifacts will be available in `out/ohos-arm-install` directory, including lldb for arm. + + +## Function Introduction +
+ ### Functionality The LLVM toolchain is built based on LLVM 15.0.4. It is used to provide capability of building ohos image. For detailed information about LLVM 15.0.4, please refer to [LLVM 15.0.4](https://discourse.llvm.org/t/llvm-15-0-4-released/66337). diff --git a/llvm-build/build-ohos-aarch64.py b/llvm-build/build-ohos-aarch64.py index dd8fec1d54cc063e54a377764b86980e0badcb1d..bd4828ec51840b3b879dc3b5be506623b43b2876 100755 --- a/llvm-build/build-ohos-aarch64.py +++ b/llvm-build/build-ohos-aarch64.py @@ -14,163 +14,84 @@ # limitations under the License. import os +from ohos_toolchain_builder import OHOSToolchainBuilder + + +class Aarch64ToolchainBuilder(OHOSToolchainBuilder): + def __init__(self) -> None: + super().__init__("aarch64-linux-ohos") + + def _update_build_args(self): + self._cflags.extend( + [ + "-v", + "-funwind-tables", + "-no-canonical-prefixes", + "-D__MUSL__", + ] + ) + + cflags_debug = "-O0 -g -fno-limit-debug-info" + cflags_release = "-O2 -DNDEBUG" + + self._ldflags.extend(["-static-libstdc++"]) + + llvm_extra_env = {} + llvm_extra_env["LD_LIBRARY_PATH"] = os.path.join(self._llvm_root, "lib") + env = dict(self._build_config.ORIG_ENV) + if llvm_extra_env is not None: + env.update(llvm_extra_env) + + # We do not build runtimes, since they will be copied from main toolchain build + self._llvm_defines.update( + { + "CMAKE_C_FLAGS_DEBUG": cflags_debug, + "CMAKE_CXX_FLAGS_DEBUG": cflags_debug, + "CMAKE_ASM_FLAGS_DEBUG": cflags_debug, + "CMAKE_C_FLAGS_RELEASE": cflags_release, + "CMAKE_CXX_FLAGS_RELEASE": cflags_release, + "CMAKE_ASM_FLAGS_RELEASE": cflags_release, + "OPENMP_STANDALONE_BUILD": "ON", + "LLVM_DIR": os.path.join(self._llvm_root, "lib", "cmake", "llvm"), + "LLVM_ENABLE_FFI": "OFF", + "LLVM_BUILD_LLVM_DYLIB": "ON", + "CMAKE_LIBRARY_ARCHITECTURE": self._llvm_triple, + "LLVM_INCLUDE_BENCHMARKS": "OFF", + "LLVM_INCLUDE_EXAMPLES": "OFF", + "LLVM_INCLUDE_TESTS": "OFF", + "LLVM_BUILD_TOOLS": "ON", + "LLVM_INSTALL_UTILS": "ON", + "LLVM_ENABLE_ZLIB": "OFF", + "LLVM_ENABLE_PROJECTS": ";".join(self._build_config.host_projects), + "CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN": self._llvm_root, + "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN": self._llvm_root, + "CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN": self._llvm_root, + "CMAKE_NM": os.path.join(self._llvm_root, "bin", "llvm-nm"), + "CMAKE_RANLIB": os.path.join(self._llvm_root, "bin", "llvm-ranlib"), + "CMAKE_OBJCOPY": os.path.join(self._llvm_root, "bin", "llvm-objcopy"), + "CMAKE_OBJDUMP": os.path.join(self._llvm_root, "bin", "llvm-objdump"), + "CMAKE_READELF": os.path.join(self._llvm_root, "bin", "llvm-readelf"), + "CMAKE_STRIP": os.path.join(self._llvm_root, "bin", "llvm-strip"), + "CMAKE_LINKER": os.path.join(self._llvm_root, "bin", "ld.lld"), + "CMAKE_POSITION_INDEPENDENT_CODE": "True", + "CMAKE_CXX_FLAGS": " ".join(self._cflags) + " -stdlib=libc++", + "CMAKE_ASM_FLAGS": " ".join(self._cflags), + "CMAKE_C_FLAGS": " ".join(self._cflags), + "CMAKE_SHARED_LINKER_FLAGS": " ".join(self._ldflags), + "CMAKE_MODULE_LINKER_FLAGS": " ".join(self._ldflags), + "CMAKE_EXE_LINKER_FLAGS": " ".join(self._ldflags) + + " -Wl,--gc-sections", + } + ) + + if self._build_config.enable_assertions: + self._llvm_defines["LLVM_ENABLE_ASSERTIONS"] = "ON" -from build import BuildConfig, BuildUtils def main(): - print('Start cross-compiling LLVM toolchain for OHOS AArch64 host on linux') - build_config = BuildConfig() - build_utils = BuildUtils(build_config) + print("Start cross-compiling LLVM toolchain for OHOS AArch64 host on linux") + Aarch64ToolchainBuilder().build() - llvm_project_path = os.path.abspath(os.path.join(build_config.LLVM_PROJECT_DIR, 'llvm')) - llvm_path = build_utils.merge_out_path('ohos-aarch64') - llvm_install = build_utils.merge_out_path('ohos-aarch64-install') - llvm_root = build_utils.merge_out_path('llvm-install') - sysroot = build_utils.merge_out_path('sysroot') - llvm_triple = 'aarch64-linux-ohos' - - cflags = [ '-v', - '-fstack-protector-strong', - '-fdata-sections', - '-ffunction-sections', - '-funwind-tables', - '-no-canonical-prefixes', - '-D__MUSL__', - '-target %s' % llvm_triple, - ] - - cflags_debug = '-O0 -g -fno-limit-debug-info' - cflags_release = '-O2 -DNDEBUG' - - ldflags = [ '-fuse-ld=lld', - '--rtlib=compiler-rt', - '-lunwind', - '-stdlib=libc++', - '-static-libstdc++', - '-pie', - '-Wl,--build-id=sha1', - '-Wl,-z,relro,-z,now', - ] - - if build_config.strip: - ldflags.append('-s') - - llvm_extra_env = {} - llvm_extra_env['LD_LIBRARY_PATH'] = os.path.join(llvm_root, 'lib') - env = dict(build_config.ORIG_ENV) - if llvm_extra_env is not None: - env.update(llvm_extra_env) - - llvm_defines = {} - llvm_defines['CMAKE_SYSTEM_NAME'] = 'OHOS' - llvm_defines['CMAKE_CROSSCOMPILING'] = 'True' - llvm_defines['CMAKE_INSTALL_PREFIX'] = llvm_install - llvm_defines['CMAKE_SYSROOT'] = sysroot - llvm_defines['CMAKE_LIBRARY_ARCHITECTURE'] = llvm_triple - llvm_defines['LLVM_HOST_TRIPLE'] = llvm_triple - llvm_defines['LLVM_TARGETS_TO_BUILD'] = build_config.TARGETS - llvm_defines['LLVM_TARGET_ARCH'] = 'AArch64' - llvm_defines['LLVM_DEFAULT_TARGET_TRIPLE'] = llvm_triple - llvm_defines['LLVM_BUILD_LLVM_DYLIB'] = 'ON' - llvm_defines['LLVM_ENABLE_FFI'] = 'OFF' - llvm_defines['LLVM_ENABLE_TERMINFO'] = 'OFF' - llvm_defines['LLVM_INCLUDE_BENCHMARKS'] = 'OFF' - llvm_defines['LLVM_INCLUDE_EXAMPLES'] = 'OFF' - llvm_defines['LLVM_INCLUDE_TESTS'] = 'OFF' - llvm_defines['LLVM_BUILD_TOOLS'] = 'ON' - llvm_defines['LLVM_INSTALL_UTILS'] = 'ON' - llvm_defines['LLVM_ENABLE_ZLIB'] = 'OFF' - llvm_defines['LLVM_ENABLE_PROJECTS'] = ';'.join(build_config.host_projects) - # We do not build runtimes, since they will be copied from main toolchain build - llvm_defines['LLVM_CONFIG_PATH'] = os.path.join(llvm_root, 'bin', 'llvm-config') - llvm_defines['LLVM_TABLEGEN'] = os.path.join(llvm_root, 'bin', 'llvm-tblgen') - llvm_defines['CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN'] = llvm_root - llvm_defines['CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN'] = llvm_root - llvm_defines['CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN'] = llvm_root - llvm_defines['CMAKE_C_COMPILER'] = os.path.join(llvm_root, 'bin', 'clang') - llvm_defines['CMAKE_CXX_COMPILER'] = os.path.join(llvm_root, 'bin', 'clang++') - llvm_defines['CMAKE_AR'] = os.path.join(llvm_root, 'bin', 'llvm-ar') - llvm_defines['CMAKE_NM'] = os.path.join(llvm_root, 'bin', 'llvm-nm') - llvm_defines['CMAKE_RANLIB'] = os.path.join(llvm_root, 'bin', 'llvm-ranlib') - llvm_defines['CMAKE_OBJCOPY'] = os.path.join(llvm_root, 'bin', 'llvm-objcopy') - llvm_defines['CMAKE_OBJDUMP'] = os.path.join(llvm_root, 'bin', 'llvm-objdump') - llvm_defines['CMAKE_READELF'] = os.path.join(llvm_root, 'bin', 'llvm-readelf') - llvm_defines['CMAKE_STRIP'] = os.path.join(llvm_root, 'bin', 'llvm-strip') - llvm_defines['CMAKE_LINKER'] = os.path.join(llvm_root, 'bin', 'ld.lld') - llvm_defines['CMAKE_ASM_FLAGS'] = ' '.join(cflags) - llvm_defines['CMAKE_C_FLAGS'] = ' '.join(cflags) - llvm_defines['CMAKE_CXX_FLAGS'] = ' '.join(cflags) + ' -stdlib=libc++' - llvm_defines['CMAKE_EXE_LINKER_FLAGS'] = ' '.join(ldflags) + ' -Wl,--gc-sections' - llvm_defines['CMAKE_SHARED_LINKER_FLAGS'] = ' '.join(ldflags) - llvm_defines['CMAKE_MODULE_LINKER_FLAGS'] = ' '.join(ldflags) - llvm_defines['CMAKE_FIND_ROOT_PATH_MODE_INCLUDE'] = 'ONLY' - llvm_defines['CMAKE_FIND_ROOT_PATH_MODE_LIBRARY'] = 'ONLY' - llvm_defines['CMAKE_FIND_ROOT_PATH_MODE_PACKAGE'] = 'ONLY' - llvm_defines['CMAKE_FIND_ROOT_PATH_MODE_PROGRAM'] = 'NEVER' - llvm_defines['CMAKE_POSITION_INDEPENDENT_CODE'] = 'True' - llvm_defines['Python3_EXECUTABLE'] = os.path.join(build_utils.get_python_dir(), 'bin', build_config.LLDB_PYTHON) - llvm_defines['CMAKE_C_FLAGS_DEBUG'] = cflags_debug - llvm_defines['CMAKE_CXX_FLAGS_DEBUG'] = cflags_debug - llvm_defines['CMAKE_ASM_FLAGS_DEBUG'] = cflags_debug - llvm_defines['CMAKE_C_FLAGS_RELEASE'] = cflags_release - llvm_defines['CMAKE_CXX_FLAGS_RELEASE'] = cflags_release - llvm_defines['CMAKE_ASM_FLAGS_RELEASE'] = cflags_release - llvm_defines['OPENMP_STANDALONE_BUILD'] = 'ON' - llvm_defines['LLVM_DIR'] = os.path.join(llvm_root, 'lib', 'cmake', 'llvm') - - lldb_defines = set_lldb_defines() - llvm_defines.update(lldb_defines) - - if build_config.enable_assertions: - llvm_defines['LLVM_ENABLE_ASSERTIONS'] = 'ON' - - if build_config.debug: - llvm_defines['CMAKE_BUILD_TYPE'] = 'Debug' - else: - llvm_defines['CMAKE_BUILD_TYPE'] = 'Release' - - build_utils.invoke_cmake(llvm_project_path, llvm_path, llvm_defines, env=env) - - build_utils.invoke_ninja(out_path=llvm_path, env=env, target=None, install=True) - - # Copy required aarch64-linux-ohos libs from main toolchain build. - arch_list = [build_utils.liteos_triple('arm'), build_utils.open_ohos_triple('arm'), - build_utils.open_ohos_triple('aarch64'), build_utils.open_ohos_triple('riscv64'), - build_utils.open_ohos_triple('mipsel'), build_utils.open_ohos_triple('x86_64')] - for arch in arch_list: - build_utils.check_copy_tree(os.path.join(llvm_root, 'lib', arch), - os.path.join(llvm_install, 'lib', arch)) - build_utils.check_copy_tree(os.path.join(llvm_root, 'lib', 'clang', '15.0.4', 'lib', arch), - os.path.join(llvm_install, 'lib', 'clang', '15.0.4', 'lib', arch)) - - #Copy required c++ headerfiles from main toolchain build. - build_utils.check_copy_tree(os.path.join(llvm_root, 'include', 'c++'), os.path.join(llvm_install, 'include', 'c++')) - build_utils.check_copy_tree(os.path.join(llvm_root, 'include', 'libcxx-ohos'), os.path.join(llvm_install, 'include', 'libcxx-ohos')) - - # Package ohos-aarch64 toolchain. - if build_config.do_package: - tarball_name = 'clang-%s-ohos-aarch64' % (build_config.build_name) - package_path = '%s%s' % (build_utils.merge_packages_path(tarball_name), build_config.ARCHIVE_EXTENSION) - build_utils.logger().info('Packaging %s', package_path) - args = ['tar', build_config.ARCHIVE_OPTION, '-h', '-C', build_config.OUT_PATH, '-f', package_path, 'ohos-aarch64-install'] - build_utils.check_create_dir(build_config.PACKAGES_PATH) - build_utils.check_call(args) - -def set_lldb_defines(): - lldb_defines = {} - lldb_defines['LLDB_INCLUDE_TESTS'] = 'OFF' - lldb_defines['LLDB_ENABLE_TIMEOUT'] = 'False' - # Optional Dependencies - lldb_defines['LLDB_ENABLE_LIBEDIT'] = 'OFF' - lldb_defines['LLDB_ENABLE_CURSE'] = 'OFF' - lldb_defines['LLDB_ENABLE_LIBXML2'] = 'OFF' - lldb_defines['LLDB_ENABLE_LZMA'] = 'OFF' - lldb_defines['LLDB_ENABLE_PYTHON'] = 'OFF' - # Debug & Tuning - lldb_defines['LLDB_ENABLE_PERFORMANCE'] = 'OFF' - - return lldb_defines - -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/llvm-build/build-ohos-arm.py b/llvm-build/build-ohos-arm.py new file mode 100755 index 0000000000000000000000000000000000000000..27931c07287d2951fe1f21049e727ba743546e53 --- /dev/null +++ b/llvm-build/build-ohos-arm.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# Copyright (C) 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 os +from ohos_toolchain_builder import OHOSToolchainBuilder + + +class ArmToolchainBuilder(OHOSToolchainBuilder): + def __init__(self) -> None: + super().__init__("arm-linux-ohos") + self._llvm_prebuilt_path = self._build_utils.merge_out_path("llvm_make") + + def _update_build_args(self): + self._cflags.extend( + [ + "-march=armv7-a -mfloat-abi=soft", + ] + ) + + self._ldflags.extend( + [ + "-Wl,-rpath,'$ORIGIN/../lib'", + ] + ) + + self._llvm_defines.update( + { + "CMAKE_CXX_FLAGS": " ".join(self._cflags), + "CMAKE_ASM_FLAGS": " ".join(self._cflags), + "CMAKE_C_FLAGS": " ".join(self._cflags), + "CMAKE_SHARED_LINKER_FLAGS": " ".join(self._ldflags), + "CMAKE_MODULE_LINKER_FLAGS": " ".join(self._ldflags), + "CMAKE_EXE_LINKER_FLAGS": " ".join(self._ldflags), + "LLVM_ENABLE_ASSERTIONS": "OFF", + "LLVM_USE_NEWPM": "ON", + "LLVM_ENABLE_BINDINGS": "OFF", + "CLANG_REPOSITORY_STRING": "llvm-project", + "COMPILER_RT_BUILD_XRAY": "OFF", + "CMAKE_POSITION_INDEPENDENT_CODE": "ON", + "LLVM_ENABLE_PER_TARGET_RUNTIME_DIR": "ON", + "COMPILER_RT_USE_BUILTINS_LIBRARY": "ON", + "LLVM_ENABLE_LIBCXX": "ON", + "LLVM_ENABLE_PROJECTS": "clang;lldb", + "CLANG_TABLEGEN": os.path.join( + self._llvm_root, + "..", + self._llvm_prebuilt_path, + "bin", + "clang-tblgen", + ), + "LLDB_TABLEGEN": os.path.join( + self._llvm_root, + "..", + self._llvm_prebuilt_path, + "bin", + "lldb-tblgen", + ), + } + ) + + +def main(): + print("Start building LLDB tools for OHOS ARM host") + ArmToolchainBuilder().build(build_target=["lldb", "lldb-server"]) + + +if __name__ == "__main__": + main() diff --git a/llvm-build/build.py b/llvm-build/build.py index ee12969b8e24e5aed27446f043eecf5cbe131618..76b1b941c583f1d0b58069f9bbc2ecf7c25f27e7 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -37,9 +37,12 @@ class BuildConfig(): def __init__(self): args = self.parse_args() + + assert not(args.no_build and args.build_only), "Error! --no-build and --build-only flags aren't compatible." + self.no_strip_libs = args.no_strip_libs self.do_build = not args.skip_build - self.do_package = not args.skip_package + self.do_package = not args.skip_package and not args.build_only self.build_name = args.build_name self.debug = args.debug self.target_debug = args.target_debug @@ -48,12 +51,17 @@ class BuildConfig(): self.build_instrumented = args.build_instrumented self.xunit_xml_output = args.xunit_xml_output self.enable_assertions = args.enable_assertions + self.build_gtest_libs = args.build_gtest_libs self.build_clean = args.build_clean self.need_libs = self.do_build and 'libs' not in args.no_build - self.need_lldb_server = self.do_build and 'lldb-server' not in args.no_build + self.need_lldb_server = self.do_build and 'lldb-server' not in args.no_build and not args.build_only self.build_python = args.build_python self.build_with_debug_info = args.build_with_debug_info + self.build_only = True if args.build_only else False + self.build_only_llvm = args.build_only["llvm"] if self.build_only else [] + self.build_only_libs = args.build_only["libs"] if self.build_only else [] + self.no_build_arm = args.skip_build or args.no_build_arm self.no_build_aarch64 = args.skip_build or args.no_build_aarch64 self.no_build_riscv64 = args.skip_build or args.no_build_riscv64 @@ -69,6 +77,7 @@ class BuildConfig(): self.enable_lzma_7zip = args.enable_lzma_7zip self.build_libs = args.build_libs self.build_libs_flags = args.build_libs_flags + self.adlt_debug_build = args.adlt_debug_build self.compression_format = args.compression_format self.enable_check_abi = args.enable_check_abi self.discover_paths() @@ -89,7 +98,7 @@ class BuildConfig(): self.ARCHIVE_EXTENSION = '.tar.' + self.compression_format self.ARCHIVE_OPTION = '-c' + ('j' if self.compression_format == "bz2" else 'z') self.LIBXML2_VERSION = None - self.LZMA_VERSION = '22.0' + self.LZMA_VERSION = None logging.basicConfig(level=logging.INFO) self.host_projects = args.host_build_projects @@ -130,6 +139,12 @@ class BuildConfig(): default=False, help='Apply assertions, some parameters are affected.') + parser.add_argument( + '--build-gtest-libs', + action='store_true', + default=False, + help='Build gtest libraries.') + parser.add_argument( '--build-name', default='dev', @@ -216,7 +231,7 @@ class BuildConfig(): '--build-python', action='store_true', default=False, - help='Build Python (not using prebuilt one, currently effective for Windows)') + help='Build Python (not using prebuilt one, currently effective for Windows and OHOS)') parser.add_argument( '--build-ncurses', @@ -269,6 +284,12 @@ class BuildConfig(): default=False, help='Append -g to build flags in build_libs') + parser.add_argument( + '--adlt-debug-build', + action='store_true', + default=False, + help='Build adlt with debug flags') + parser.add_argument( '--enable-check-abi', nargs='?', @@ -354,6 +375,29 @@ class BuildConfig(): default=llvm_runtimes, help=f'Runtimes to build for host. Choices: {", ".join(llvm_runtimes)}') + llvm_components = ("lld", "llvm-readelf", "llvm-objdump") + libs_components = ("musl", "compiler-rt", "libcxx") + + class SeparatedListByCommaToDictAction(argparse.Action): + def __call__(self, parser, namespace, vals, option_string): + vals_dct = {"llvm": [], "libs": []} + for val in vals.split(','): + if val in llvm_components: + vals_dct["llvm"].append(val) + continue + elif val in libs_components: + vals_dct["libs"].append(val) + continue + else: + error = '\'{}\' invalid. Choose from {}, {}'.format(val, llvm_components, libs_components) + raise argparse.ArgumentError(self, error) + setattr(namespace, self.dest, vals_dct) + + parser.add_argument( + '--build-only', + action=SeparatedListByCommaToDictAction, + default=dict(), + help=f'Build only {", ".join(llvm_components)} llvm components and {", ".join(libs_components)} lib components.') return parser.parse_args() @@ -486,6 +530,11 @@ class BuildUtils(object): subprocess.check_call(cmd, *args, **kwargs) + def force_symlink(self, src, dst): + if os.path.exists(dst): + os.remove(dst) + os.symlink(src, dst) + def merge_out_path(self, *args): return os.path.abspath(os.path.join(self.build_config.OUT_PATH, *args)) @@ -574,20 +623,38 @@ class BuildUtils(object): def get_mingw_python_dir(self): return self._mingw_python_dir - def get_ncurses_version(self): - ncurses_spec = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'ncurses', 'ncurses.spec') - if os.path.exists(ncurses_spec): - with open(ncurses_spec, 'r') as file: + def get_version(self, fileName, prog): + if os.path.exists(fileName): + with open(fileName, 'r') as file: lines = file.readlines() - - prog = re.compile(r'Version:\s*(\S+)') for line in lines: version_match = prog.match(line) if version_match: return version_match.group(1) - return None + def get_ncurses_version(self): + ncurses_spec = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'ncurses', 'ncurses.spec') + prog = re.compile(r'Version:\s*(\S+)') + return self.get_version(ncurses_spec, prog) + + def get_lzma_version(self): + lzma_version_file = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'lzma', 'C', '7zVersion.h') + prog = re.compile(r'#define MY_VERSION_NUMBERS "(.*?)"') + return self.get_version(lzma_version_file, prog) + + def merge_ncurses_install_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'ncurses', 'install', platform_triple, *args) + + def get_ncurses_dependence_libs(self, platform_triple): + ncurses_libs = ['libncurses', 'libpanel', 'libform'] + if self.use_platform() != platform_triple: + ncurses_libs.append('libtinfo') + return ncurses_libs + + def merge_ncurses_build_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'ncurses', 'build', platform_triple, *args) + def get_libxml2_version(self): version_file = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libxml2', 'libxml2.spec') if os.path.isfile(version_file): @@ -604,14 +671,40 @@ class BuildUtils(object): return None - def get_libxml2_source_path(self): - return self.merge_out_path('third_party', 'libxml2', ('libxml2-' + self.build_config.LIBXML2_VERSION)) + def merge_libxml2_install_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'libxml2', 'install', platform_triple, *args) - def get_libxml2_install_path(self, triple): - return self.merge_out_path('third_party', 'libxml2', 'install', triple) + def merge_libxml2_build_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'libxml2', 'build', platform_triple, *args) - def get_libxml2_build_path(self, triple): - return self.merge_out_path('third_party', 'libxml2', 'build', triple) + def get_libedit_version(self): + libedit_spec = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libedit', 'libedit.spec') + if os.path.exists(libedit_spec): + with open(libedit_spec, 'r') as file: + lines = file.readlines() + + prog = re.compile(r'Version:\s*(\S+)') + for line in lines: + version_match = prog.match(line) + if version_match: + return version_match.group(1) + + return None + + def merge_libedit_install_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'libedit', 'install', platform_triple, *args) + + def merge_libedit_build_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'libedit', 'build', platform_triple, *args) + + def merge_python_install_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'python', 'install', platform_triple, *args) + + def merge_python_build_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'python', 'build', platform_triple, *args) + + def get_libxml2_source_path(self): + return self.merge_out_path('third_party', 'libxml2', ('libxml2-' + self.build_config.LIBXML2_VERSION)) class LlvmCore(BuildUtils): @@ -623,6 +716,7 @@ class LlvmCore(BuildUtils): build_dir, install_dir, build_name, + build_target=None, extra_defines=None, extra_env=None): @@ -653,6 +747,7 @@ class LlvmCore(BuildUtils): if extra_env is not None: env.update(extra_env) + install = not self.build_config.build_only llvm_project_path = os.path.abspath(os.path.join(self.build_config.LLVM_PROJECT_DIR, 'llvm')) self.invoke_cmake(llvm_project_path, @@ -662,8 +757,28 @@ class LlvmCore(BuildUtils): self.invoke_ninja(out_path=build_dir, env=env, - target=None, - install=True) + target=build_target, + install=install) + if not install: + self.llvm_install(build_dir, install_dir) + + def llvm_install(self, build_dir, install_dir): + target_dirs = ["bin", "include", "lib", "libexec", "share"] + for target_dir in target_dirs: + target_dir = f"{build_dir}/{target_dir}" + if not os.path.exists(target_dir): + continue + for (src_path, dirs, files) in os.walk(target_dir): + dst_path = src_path.replace(build_dir, install_dir) + for file in files: + src = os.path.join(src_path, file) + dst = os.path.join(dst_path, file) + if file.endswith(".cpp.o") or file == "cmake_install.cmake": + continue + if os.path.exists(dst) and os.stat(src) == os.stat(dst): + continue + os.makedirs(dst_path, exist_ok=True) + shutil.copy2(src, dst) def llvm_compile_darwin_defines(self, llvm_defines): if self.host_is_darwin(): @@ -674,10 +789,11 @@ class LlvmCore(BuildUtils): llvm_defines['LLVM_ENABLE_ZSTD'] = 'OFF' llvm_defines['LLDB_PYTHON_EXT_SUFFIX'] = '.dylib' if self.build_config.build_ncurses: - libncurse = os.path.join(self.get_prebuilts_dir('ncurses'), 'lib', 'libncurses.6.dylib') - libpanel = os.path.join(self.get_prebuilts_dir('ncurses'), 'lib', 'libpanel.6.dylib') - libform = os.path.join(self.get_prebuilts_dir('ncurses'), 'lib', 'libform.6.dylib') - ncurses_libs = ';'.join([libncurse, libpanel, libform]) + ncurses_libs = ';'.join([ + self.merge_ncurses_install_dir( + self.use_platform(), + 'lib', + f'{lib_name}.6.dylib') for lib_name in self.get_ncurses_dependence_libs(self.use_platform())]) llvm_defines['CURSES_LIBRARIES'] = ncurses_libs llvm_defines['PANEL_LIBRARIES'] = ncurses_libs @@ -685,11 +801,12 @@ class LlvmCore(BuildUtils): llvm_defines['LIBLZMA_LIBRARIES'] = self.merge_out_path('lzma', 'lib', self.use_platform(), f'liblzma.{self.build_config.LZMA_VERSION}.dylib') if self.build_config.build_libedit: - llvm_defines['LibEdit_LIBRARIES'] = os.path.join(self.get_prebuilts_dir('libedit'), 'lib', 'libedit.0.dylib') + llvm_defines['LibEdit_LIBRARIES'] = \ + self.merge_libedit_install_dir(self.use_platform(), 'lib', 'libedit.0.dylib') if self.build_config.build_libxml2: - llvm_defines['LIBXML2_LIBRARIES'] = os.path.join(self.get_libxml2_install_path(self.use_platform()), 'lib', f'libxml2.{self.build_config.LIBXML2_VERSION}.dylib') - + llvm_defines['LIBXML2_LIBRARIES'] = \ + self.merge_libxml2_install_dir(self.use_platform(), 'lib', f'libxml2.{self.build_config.LIBXML2_VERSION}.dylib') def llvm_compile_linux_defines(self, llvm_defines, @@ -715,12 +832,18 @@ class LlvmCore(BuildUtils): llvm_defines['LLDB_PYTHON_EXT_SUFFIX'] = '.so' ncurses_version = self.get_ncurses_version() if self.build_config.build_ncurses and ncurses_version is not None: - ncurses_libs = [] - prebuilts_dir = self.get_prebuilts_dir('ncurses') - for library in ['libncurses', 'libpanel', 'libform']: - library_path = os.path.join(prebuilts_dir, 'lib', f'{library}.so.%s' % ncurses_version) - ncurses_libs.append(library_path) - ncurses_libs = ';'.join(ncurses_libs) + ncurses_libs = ";".join( + [ + self.merge_ncurses_install_dir( + self.use_platform(), + "lib", + f"{lib_name}.so.{ncurses_version}", + ) + for lib_name in self.get_ncurses_dependence_libs( + self.use_platform() + ) + ] + ) llvm_defines['CURSES_LIBRARIES'] = ncurses_libs llvm_defines['PANEL_LIBRARIES'] = ncurses_libs @@ -728,13 +851,15 @@ class LlvmCore(BuildUtils): llvm_defines['LIBLZMA_LIBRARIES'] = self.merge_out_path('lzma', 'lib', 'linux-x86_64', 'liblzma.so') if self.build_config.build_libedit: - llvm_defines['LibEdit_LIBRARIES'] = os.path.join(self.get_prebuilts_dir('libedit'), 'lib', 'libedit.so.0.0.68') + llvm_defines['LibEdit_LIBRARIES'] = \ + self.merge_libedit_install_dir(self.use_platform(), 'lib', 'libedit.so.0.0.68') if not build_instrumented and not no_lto and not debug_build: llvm_defines['LLVM_ENABLE_LTO'] = 'Thin' if self.build_config.build_libxml2: - llvm_defines['LIBXML2_LIBRARY'] = os.path.join(self.get_libxml2_install_path(self.use_platform()), 'lib', f'libxml2.so.{self.build_config.LIBXML2_VERSION}') + llvm_defines['LIBXML2_LIBRARY'] = \ + self.merge_libxml2_install_dir(self.use_platform(), 'lib', f'libxml2.so.{self.build_config.LIBXML2_VERSION}') def llvm_compile_llvm_defines(self, llvm_defines, llvm_root, cflags, ldflags): llvm_defines['LLVM_ENABLE_PROJECTS'] = ';'.join(self.build_config.host_projects) @@ -770,7 +895,7 @@ class LlvmCore(BuildUtils): if self.build_config.build_ncurses and self.get_ncurses_version() is not None: llvm_defines['LLDB_ENABLE_CURSES'] = 'ON' - llvm_defines['CURSES_INCLUDE_DIRS'] = os.path.join(self.get_prebuilts_dir('ncurses'), 'include') + llvm_defines['CURSES_INCLUDE_DIRS'] = self.merge_ncurses_install_dir(self.use_platform(), 'include') if self.build_config.enable_lzma_7zip: llvm_defines['LLDB_ENABLE_LZMA'] = 'ON' @@ -779,11 +904,11 @@ class LlvmCore(BuildUtils): if self.build_config.build_libedit: llvm_defines['LLDB_ENABLE_LIBEDIT'] = 'ON' - llvm_defines['LibEdit_INCLUDE_DIRS'] = os.path.join(self.get_prebuilts_dir('libedit'), 'include') + llvm_defines['LibEdit_INCLUDE_DIRS'] = self.merge_libedit_install_dir(self.use_platform(), 'include') if self.build_config.build_libxml2: llvm_defines['LLDB_ENABLE_LIBXML2'] = 'ON' - llvm_defines['LIBXML2_INCLUDE_DIR'] = os.path.join(self.get_libxml2_install_path(self.use_platform()), 'include', 'libxml2') + llvm_defines['LIBXML2_INCLUDE_DIR'] = self.merge_libxml2_install_dir(self.use_platform(), 'include', 'libxml2') if self.build_config.enable_monitoring: llvm_defines['LLDB_ENABLE_PERFORMANCE'] = 'ON' @@ -794,6 +919,7 @@ class LlvmCore(BuildUtils): debug_build=False, no_lto=False, build_instrumented=False, + build_target=None, xunit_xml_output=None): llvm_clang_install = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, @@ -851,6 +977,7 @@ class LlvmCore(BuildUtils): build_dir=llvm_path, install_dir=out_dir, build_name=build_name, + build_target=build_target, extra_defines=llvm_defines, extra_env=llvm_extra_env) @@ -909,8 +1036,8 @@ class LlvmCore(BuildUtils): if self.build_config.build_libxml2: windows_defines['LLDB_ENABLE_LIBXML2'] = 'ON' - windows_defines['LIBXML2_INCLUDE_DIR'] = os.path.join(self.get_libxml2_install_path('windows-x86_64'), 'include', 'libxml2') - windows_defines['LIBXML2_LIBRARY'] = os.path.join(self.get_libxml2_install_path('windows-x86_64'), 'lib', 'libxml2.dll.a') + windows_defines['LIBXML2_INCLUDE_DIR'] = self.merge_libxml2_install_dir('windows-x86_64', 'include', 'libxml2') + windows_defines['LIBXML2_LIBRARY'] = self.merge_libxml2_install_dir('windows-x86_64', 'lib', 'libxml2.dll.a') if self.build_config.enable_monitoring: windows_defines['LLDB_ENABLE_PERFORMANCE'] = 'ON' @@ -967,7 +1094,6 @@ class LlvmCore(BuildUtils): ldflags, windows_defines): - zlib_path = self.merge_out_path('../', 'prebuilts', 'clang', 'host', 'windows-x86', 'toolchain-prebuilts', 'zlib') zlib_inc = os.path.join(zlib_path, 'include') @@ -984,7 +1110,6 @@ class LlvmCore(BuildUtils): windows_defines['CMAKE_SHARED_LINKER_FLAGS'] = ' '.join(ldflags) windows_defines['CMAKE_MODULE_LINKER_FLAGS'] = ' '.join(ldflags) - def llvm_compile_for_windows(self, targets, enable_assertions, @@ -1061,12 +1186,15 @@ class SysrootComposer(BuildUtils): self.get_python_dir(), 'bin', self.build_config.LLDB_PYTHON) llvm_gn_args = 'is_llvm_build=true startup_init_with_param_base=true use_thin_lto=false' subprocess.run([python_execute_dir, hb_build_py, 'build', '--product-name', product_name, '--target-cpu', - target_cpu, '--build-target', target_name, '--gn-args', + target_cpu, '--build-target', target_name, '--gn-args', gn_args, llvm_gn_args, '--deps-guard=false'], shell=False, stdout=subprocess.PIPE, cwd=self.build_config.REPOROOT_DIR) def build_musl_libs(self, product_name, target_cpu, target_name, ohos_lib_dir, sysroot_lib_dir, ld_musl_lib, gn_args=''): + if (self.build_config.adlt_debug_build): + gn_args = f"is_debug=true ohos_extra_cflags=-O0 {gn_args}" + self.run_hb_build(product_name, target_cpu, target_name, gn_args) libc_name = 'libc.so' crtplus_lib = self.merge_out_path('llvm_build', 'obj', 'out', 'llvm_build', 'obj', 'third_party', 'musl', @@ -1262,7 +1390,7 @@ class LlvmLibs(BuildUtils): ldflags.extend(ldflag) cflag = [ - '-fstack-protector-strong', + '-fstack-protector-strong', '--target=%s' % llvm_triple, '-ffunction-sections', '-fdata-sections', @@ -1318,6 +1446,8 @@ class LlvmLibs(BuildUtils): defines = self.base_cmake_defines() ldflags = [] cflags = [] + if self.build_config.adlt_debug_build: + cflags.append("-g -gdwarf-4 -O0") self.logger().info('Build libs for %s', llvm_triple) if self.build_config.target_debug: defines['CMAKE_BUILD_TYPE'] = 'Debug' @@ -1359,8 +1489,8 @@ class LlvmLibs(BuildUtils): self.build_lldb_tools(llvm_install, llvm_path, arch, llvm_triple, cflags, ldflags, defines) seen_arch_list.append(llvm_triple) - def build_libs_by_type(self, llvm_install, llvm_build, libs_type, is_first_time, is_ndk_install): - configs_list, cc, cxx, ar, llvm_config = self.libs_argument(llvm_install) + def build_libs_by_type(self, compiler_path, llvm_install, llvm_build, libs_type, is_first_time, is_ndk_install): + configs_list, cc, cxx, ar, llvm_config = self.libs_argument(compiler_path) for (arch, llvm_triple, extra_flags, multilib_suffix) in configs_list: if llvm_build != llvm_triple: @@ -1368,6 +1498,9 @@ class LlvmLibs(BuildUtils): defines = self.base_cmake_defines() ldflags = [] cflags = [] + if self.build_config.adlt_debug_build: + cflags.append("-g -gdwarf-4 -O0") + self.logger().info('Build %s libs for %s', libs_type, llvm_triple) out_path = self.merge_out_path('llvm_build') self.logger().info('Make %s libs for %s build_libs_flags: %s', libs_type, llvm_triple, self.build_config.build_libs_flags) @@ -1463,10 +1596,10 @@ class LlvmLibs(BuildUtils): rt_defines['LIBUNWIND_INSTALL_LIBRARY'] = 'OFF' else: rt_defines['LIBCXX_ABI_NAMESPACE'] = '__h' - + self.check_rm_tree(out_path) cmake_rt = os.path.abspath(os.path.join(self.build_config.LLVM_PROJECT_DIR, 'runtimes')) - + self.invoke_cmake(cmake_rt, out_path, rt_defines, @@ -1694,12 +1827,32 @@ class LlvmLibs(BuildUtils): lldb_defines['LIBLLDB_BUILD_STATIC'] = 'ON' lldb_target.append('lldb') + if self.build_config.build_ncurses: + self.build_ncurses(None, llvm_install, llvm_triple) + lldb_defines['LLDB_ENABLE_CURSES'] = 'ON' + ncurses_install_path = self.merge_ncurses_install_dir(llvm_triple) + lldb_defines['CURSES_INCLUDE_DIRS'] = os.path.join(ncurses_install_path, 'include') + lldb_defines['CURSES_HAVE_NCURSES_CURSES_H'] = 'ON' + ncurses_lib_path = os.path.join(ncurses_install_path, 'lib') + ncurses_libs = [] + for library in self.get_ncurses_dependence_libs(llvm_triple): + ncurses_libs.append(os.path.join(ncurses_lib_path, f'{library}.a')) + ncurses_libs = ';'.join(ncurses_libs) + lldb_defines['CURSES_LIBRARIES'] = ncurses_libs + lldb_defines['PANEL_LIBRARIES'] = ncurses_libs + + if self.build_config.build_libedit: + self.build_libedit(None, llvm_install, llvm_triple) + lldb_defines['LLDB_ENABLE_LIBEDIT'] = 'ON' + libedit_install_path = self.merge_libedit_install_dir(llvm_triple) + lldb_defines['LibEdit_INCLUDE_DIRS'] = os.path.join(libedit_install_path, 'include') + lldb_defines['LibEdit_LIBRARIES'] = os.path.join(libedit_install_path, 'lib', 'libedit.a') + if self.build_config.build_libxml2: - self.build_libxml2(llvm_triple, None, llvm_install) + self.build_libxml2(llvm_triple, None, llvm_install, True) lldb_defines['LLDB_ENABLE_LIBXML2'] = 'ON' - libxml2_install_path = self.get_libxml2_install_path(llvm_triple) - lldb_defines['LIBXML2_INCLUDE_DIR'] = os.path.join(libxml2_install_path, 'include', 'libxml2') - lldb_defines['LIBXML2_LIBRARY'] = os.path.join(libxml2_install_path, 'lib', 'libxml2.a') + lldb_defines['LIBXML2_INCLUDE_DIR'] = self.merge_libxml2_install_dir(llvm_triple, 'include', 'libxml2') + lldb_defines['LIBXML2_LIBRARY'] = self.merge_libxml2_install_dir(llvm_triple, 'lib', 'libxml2.a') if self.build_config.lldb_timeout: lldb_defines['LLDB_ENABLE_TIMEOUT'] = 'True' @@ -1764,12 +1917,12 @@ class LlvmLibs(BuildUtils): env=dict(self.build_config.ORIG_ENV), install=True) - def build_ncurses(self, llvm_make, llvm_install): + def build_ncurses(self, llvm_make, llvm_install, platform_triple): self.logger().info('Building ncurses.') libncurses_src_dir = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'ncurses')) - libncurses_build_path = self.merge_out_path('ncurses') - libncurses_install_path = self.get_prebuilts_dir('ncurses') + libncurses_install_path = self.merge_ncurses_install_dir(platform_triple) + libncurses_build_path = self.merge_ncurses_build_dir(platform_triple) prebuilts_path = os.path.join(self.build_config.REPOROOT_DIR, 'prebuilts') self.check_rm_tree(libncurses_build_path) @@ -1783,13 +1936,16 @@ class LlvmLibs(BuildUtils): ncurses_version = self.get_ncurses_version() if ncurses_version is not None: + libncurses_untar_path = self.merge_out_path('third_party', 'ncurses', 'ncurses-' + ncurses_version) args = ['./build_ncurses.sh', libncurses_src_dir, libncurses_build_path, libncurses_install_path, - prebuilts_path, clang_version, ncurses_version] + prebuilts_path, clang_version, ncurses_version, platform_triple, libncurses_untar_path, + self.merge_ncurses_install_dir(self.use_platform())] self.check_call(args) os.chdir(cur_dir) - self.llvm_package.copy_ncurses_to_llvm(llvm_make) - self.llvm_package.copy_ncurses_to_llvm(llvm_install) + if platform_triple == self.use_platform(): + self.llvm_package.copy_ncurses_to_llvm(platform_triple, llvm_make) + self.llvm_package.copy_ncurses_to_llvm(platform_triple, llvm_install) def build_lzma(self, llvm_make, llvm_install): self.logger().info('Building lzma') @@ -1827,12 +1983,12 @@ class LlvmLibs(BuildUtils): self.check_create_dir(lib_dst_path) self.check_copy_file(lzma_file, lib_dst_path + '/liblzma' + shlib_ext) - def build_libedit(self, llvm_make, llvm_install): + def build_libedit(self, llvm_make, llvm_install, platform_triple): self.logger().info('Building libedit') libedit_src_dir = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libedit')) - libedit_build_path = self.merge_out_path('libedit') - libedit_install_path = self.get_prebuilts_dir('libedit') + libedit_build_path = self.merge_libedit_build_dir(platform_triple) + libedit_install_path = self.merge_libedit_install_dir(platform_triple) prebuilts_path = os.path.join(self.build_config.REPOROOT_DIR, 'prebuilts') self.check_rm_tree(libedit_build_path) @@ -1840,17 +1996,79 @@ class LlvmLibs(BuildUtils): self.check_rm_tree(libedit_install_path) self.rm_cmake_cache(libedit_install_path) - libncurses_path = self.get_prebuilts_dir('ncurses') + libncurses_path = self.merge_ncurses_install_dir(platform_triple) cur_dir = os.getcwd() os.chdir(self.build_config.LLVM_BUILD_DIR) clang_version = self.build_config.CLANG_VERSION - args = ['./build_libedit.sh', libedit_src_dir, libedit_build_path , libedit_install_path, libncurses_path, prebuilts_path, clang_version] + libedit_untar_path = self.merge_out_path('third_party', 'libedit', 'libedit-' + self.get_libedit_version()) + args = ['./build_libedit.sh', libedit_src_dir, libedit_build_path , libedit_install_path, libncurses_path, prebuilts_path, clang_version, platform_triple, libedit_untar_path] self.check_call(args) os.chdir(cur_dir) - self.llvm_package.copy_libedit_to_llvm(llvm_make) - self.llvm_package.copy_libedit_to_llvm(llvm_install) + if platform_triple == self.use_platform(): + self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_make) + self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_install) + + def copy_gtest_to_sysroot(self, build_dir): + build_lib_dir = os.path.join(build_dir, 'lib') + self.logger().info('LlvmPackage copy_gtest_to_sysroot from %s', build_lib_dir) + libs = [ "libLLVMSupport.so", "libLLVMDemangle.so", "libllvm_gtest.so" ] + sysroot_lib_dir = self.merge_out_path('sysroot', 'aarch64-linux-ohos', 'usr', 'lib') + + os.chdir(build_lib_dir) + for f in libs: + self.check_copy_file(f'{f}.15', sysroot_lib_dir) + os.chdir(sysroot_lib_dir) + self.force_symlink(f'{f}.15', f) + os.chdir(build_lib_dir) + + def build_gtest_defines(self, llvm_install): + sysroot = self.merge_out_path('sysroot', 'aarch64-linux-ohos', 'usr') + common_flags = f'--target=aarch64-linux-ohos -B{sysroot}/lib -L{sysroot}/lib' + libcxx = self.merge_out_path('llvm-install', 'include', 'libcxx-ohos', 'include', 'c++', 'v1') + libc = os.path.join(sysroot, "include") + + gtest_defines = {} + gtest_defines['BUILD_SHARED_LIBS'] = 'YES' + gtest_defines['CMAKE_BUILD_TYPE'] = 'Release' + gtest_defines['CMAKE_C_COMPILER'] = os.path.join(llvm_install, 'bin', 'clang') + gtest_defines['CMAKE_CXX_COMPILER'] = os.path.join(llvm_install, 'bin', 'clang++') + gtest_defines['LLVM_TABLEGEN'] = os.path.join(llvm_install, 'bin', 'llvm-tblgen') + gtest_defines['CMAKE_LINKER'] = os.path.join(llvm_install, 'bin', 'ld.lld') + gtest_defines['CMAKE_EXE_LINKER_FLAGS'] = f'{common_flags}' + gtest_defines['CMAKE_C_FLAGS'] = f'{common_flags} -I{libc}' + gtest_defines['CMAKE_CXX_FLAGS'] = f'{common_flags} -I{libcxx} -I{libc}' + + return gtest_defines + + def build_gtest(self, compiler_path, llvm_install): + gtest_defines = self.build_gtest_defines(compiler_path) + gtest_cmake_path = os.path.abspath(os.path.join(self.build_config.LLVM_PROJECT_DIR, 'llvm')) + + gtest_build_path = self.merge_out_path('gtest') + + self.rm_cmake_cache(gtest_build_path) + + self.invoke_cmake(gtest_cmake_path, + gtest_build_path, + gtest_defines, + env=dict(self.build_config.ORIG_ENV)) + + self.invoke_ninja(out_path=gtest_build_path, + env=dict(self.build_config.ORIG_ENV), + target=[ "LLVMSupport", "LLVMDemangle", "llvm_gtest" ], + install=False) + + self.copy_gtest_to_sysroot(gtest_build_path) + shutil.copytree( + os.path.join(self.build_config.LLVM_PROJECT_DIR, 'llvm', 'utils', 'unittest', 'googlemock', 'include', 'gmock'), + os.path.join(llvm_install, 'include', 'gmock'), + dirs_exist_ok = True) + shutil.copytree( + os.path.join(self.build_config.LLVM_PROJECT_DIR, 'llvm', 'utils', 'unittest', 'googletest', 'include', 'gtest'), + os.path.join(llvm_install, 'include', 'gtest'), + dirs_exist_ok = True) def build_libxml2_defines(self): libxml2_defines = {} @@ -1862,7 +2080,7 @@ class LlvmLibs(BuildUtils): return libxml2_defines - def build_libxml2(self, triple, llvm_make, llvm_install): + def build_libxml2(self, triple, llvm_make, llvm_install, static = False): self.logger().info('Building libxml2 for %s', triple) cmake_path = self.get_libxml2_source_path() @@ -1873,31 +2091,23 @@ class LlvmLibs(BuildUtils): self.check_create_dir(untar_path) subprocess.run(['python3', untar_py, '--gen-dir', untar_path, '--source-file', package_path]) - build_path = self.get_libxml2_build_path(triple) - install_path = self.get_libxml2_install_path(triple) - self.check_rm_tree(build_path) + build_path = self.merge_libxml2_build_dir(triple) + install_path = self.merge_libxml2_install_dir(triple) self.check_rm_tree(install_path) defines = self.build_libxml2_defines() defines['CMAKE_INSTALL_PREFIX'] = install_path + if static: + defines['BUILD_SHARED_LIBS'] = 'OFF' - if triple != self.use_platform(): - configs_list, cc, cxx, ar, llvm_config = self.libs_argument(llvm_install) - for (arch, llvm_triple, extra_flags, multilib_suffix) in configs_list: - if llvm_triple != triple or multilib_suffix != '': - continue + if triple in ['arm-linux-ohos', 'aarch64-linux-ohos']: + defines['CMAKE_C_COMPILER'] = self.merge_out_path('llvm-install','bin','clang') + cflags = [f"--target={triple}"] + if triple == 'arm-linux-ohos': + cflags.append('-march=armv7-a -mfloat-abi=soft') + defines['CMAKE_C_FLAGS'] = ' '.join(cflags) - ldflags = [] - cflags = [] - self.build_libs_defines(triple, defines, cc, cxx, ar, llvm_config, ldflags, cflags, extra_flags) - defines['CMAKE_C_FLAGS'] = ' '.join(cflags) - defines['CMAKE_CXX_FLAGS'] = ' '.join(cflags) - defines['CMAKE_SHARED_LINKER_FLAGS'] = ' '.join(ldflags) - defines['CMAKE_LINKER'] = os.path.join(llvm_install, 'bin', 'ld.lld') - defines['CMAKE_SYSTEM_NAME'] = 'OHOS' - defines['CMAKE_CROSSCOMPILING'] = 'True' - defines['BUILD_SHARED_LIBS'] = 'OFF' - break + self.rm_cmake_cache(build_path) self.invoke_cmake(cmake_path, build_path, @@ -1908,8 +2118,7 @@ class LlvmLibs(BuildUtils): dict(self.build_config.ORIG_ENV), None, True) - - if triple == self.use_platform(): + if not static: self.llvm_package.copy_libxml2_to_llvm(triple, llvm_make) self.llvm_package.copy_libxml2_to_llvm(triple, llvm_install) @@ -1918,8 +2127,8 @@ class LlvmLibs(BuildUtils): windows_sysroot = self.merge_out_path('mingw', self.build_config.MINGW_TRIPLE) windowstool_path = self.merge_out_path('llvm-install') - libxml2_build_path = self.get_libxml2_build_path('windows-x86_64') - libxml2_install_path = self.get_libxml2_install_path('windows-x86_64') + libxml2_build_path = self.merge_libxml2_build_dir('windows-x86_64') + libxml2_install_path = self.merge_libxml2_install_dir('windows-x86_64') cflags = ['--target=x86_64-pc-windows-gnu'] cflags.extend(('-I', os.path.join(windows_sysroot, 'include'))) @@ -2347,7 +2556,7 @@ class LlvmPackage(BuildUtils): if index_link != -1: subprocess.check_call(["install_name_tool", "-change", dependency, "@loader_path/../lib/%s" % lib_name, lib]) - def copy_ncurses_to_llvm(self, install_dir): + def copy_ncurses_to_llvm(self, platform_triple, install_dir): self.logger().info('copy_ncurses_to_llvm install_dir is %s', install_dir) if self.host_is_darwin(): @@ -2357,30 +2566,27 @@ class LlvmPackage(BuildUtils): lib_dst_path = os.path.join(install_dir, 'lib') - lib_src_path = self.merge_out_path('../prebuilts', 'ncurses', 'lib') - libncurses_src = os.path.join(lib_src_path, 'libncurses%s' % shlib_ext) - libpanel_src = os.path.join(lib_src_path, 'libpanel%s' % shlib_ext) - libform_src = os.path.join(lib_src_path, 'libform%s' % shlib_ext) - - libncurses_dst = os.path.join(lib_dst_path, 'libncurses%s' % shlib_ext) - libpanel_dst = os.path.join(lib_dst_path, 'libpanel%s' % shlib_ext) - libform_dst =os.path.join(lib_dst_path, 'libform%s' % shlib_ext) + lib_names = self.get_ncurses_dependence_libs(platform_triple) + lib_srcs = [self.merge_ncurses_install_dir(platform_triple, 'lib', + f'{name}{shlib_ext}') for name in lib_names] + lib_dsts = [os.path.join(install_dir, 'lib', + f'{name}{shlib_ext}') for name in lib_names] if not os.path.exists(lib_dst_path): os.makedirs(lib_dst_path) - for lib_file in (libncurses_src, libpanel_src, libform_src): - self.update_lib_id_link(lib_src_path, lib_file) + for lib_file in lib_srcs: + self.update_lib_id_link(self.merge_ncurses_install_dir(platform_triple, 'lib'), lib_file) # Clear historical libraries - for lib in (libncurses_dst, libpanel_dst, libform_dst): + for lib in lib_dsts: if os.path.exists(lib): os.remove(lib) - for lib_src in (libncurses_src, libpanel_src, libform_src): + for lib_src in lib_srcs: self.check_copy_file(lib_src, lib_dst_path) - def copy_libedit_to_llvm(self, install_dir): + def copy_libedit_to_llvm(self, platform_triple, install_dir): self.logger().info('LlvmPackage copy_libedit_to_llvm install_dir is %s', install_dir) if self.host_is_darwin(): @@ -2388,7 +2594,7 @@ class LlvmPackage(BuildUtils): if self.host_is_linux(): shlib_ext = '.so.0' - libedit_lib_path = self.merge_out_path('../prebuilts', 'libedit', 'lib') + libedit_lib_path = self.merge_libedit_install_dir(platform_triple, 'lib') libedit_src = os.path.join(libedit_lib_path, 'libedit%s' % shlib_ext) lib_dst_path = os.path.join(install_dir, 'lib') @@ -2413,7 +2619,7 @@ class LlvmPackage(BuildUtils): st = os.stat(os.path.join(bin_dir, sh_filename)) os.chmod(os.path.join(bin_dir, sh_filename), st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH) - def copy_libxml2_to_llvm(self, triple, install_dir): + def copy_libxml2_to_llvm(self, platform_triple, install_dir): self.logger().info('LlvmPackage copy_libxml2_to_llvm install_dir is %s', install_dir) libxml2_version = self.get_libxml2_version() @@ -2423,8 +2629,8 @@ class LlvmPackage(BuildUtils): if self.host_is_linux(): shlib_ext = f'.so.{libxml2_version}' - libxml2_lib_path = os.path.join(self.get_libxml2_install_path(triple), 'lib') - libxml2_src = os.path.join(libxml2_lib_path, 'libxml2%s' % shlib_ext) + lib_path = self.merge_libxml2_install_dir(platform_triple, 'lib') + libxml2_src = os.path.join(lib_path, 'libxml2%s' % shlib_ext) lib_dst_path = os.path.join(install_dir, 'lib') @@ -2433,7 +2639,7 @@ class LlvmPackage(BuildUtils): if not os.path.exists(lib_dst_path): os.makedirs(lib_dst_path) - self.update_lib_id_link(libxml2_lib_path, libxml2_src) + self.update_lib_id_link(lib_path, libxml2_src) # Clear historical library if os.path.isfile(libxml2_dst): @@ -2524,7 +2730,6 @@ class LlvmPackage(BuildUtils): return - def main(): build_config = BuildConfig() build_utils = BuildUtils(build_config) @@ -2535,12 +2740,14 @@ def main(): args = build_config.parse_args() need_host = build_utils.host_is_darwin() or ('linux' not in args.no_build) - need_windows = build_utils.host_is_linux() and \ + need_windows = build_utils.host_is_linux() and not build_config.build_only and \ ('windows' not in args.no_build) llvm_install = build_utils.merge_out_path('llvm-install') llvm_make = build_utils.merge_out_path('llvm_make') windows64_install = build_utils.merge_out_path('windows-x86_64-install') + llvm_path = llvm_install if not build_config.build_only else \ + os.path.join(build_config.REPOROOT_DIR, 'prebuilts', 'clang', 'ohos', 'linux-x86_64', f'clang-{build_config.CLANG_VERSION}') configs = [] if not build_config.no_build_arm: @@ -2560,13 +2767,16 @@ def main(): configs.append(('x86_64', build_utils.open_ohos_triple('x86_64'))) if build_config.build_ncurses: - llvm_libs.build_ncurses(llvm_make, llvm_install) + llvm_libs.build_ncurses(llvm_make, llvm_install, build_utils.use_platform()) + build_config.LZMA_VERSION = build_utils.get_lzma_version() + if build_config.LZMA_VERSION is None: + raise Exception('Lzma version information not found, please check if the 7zVersion.h file exists') if build_config.enable_lzma_7zip: llvm_libs.build_lzma(llvm_make, llvm_install) if build_config.build_libedit: - llvm_libs.build_libedit(llvm_make, llvm_install) + llvm_libs.build_libedit(llvm_make, llvm_install, build_utils.use_platform()) build_config.LIBXML2_VERSION = build_utils.get_libxml2_version() if build_config.LIBXML2_VERSION is None: @@ -2575,20 +2785,21 @@ def main(): if build_config.build_libxml2: llvm_libs.build_libxml2(build_utils.use_platform(), llvm_make, llvm_install) - if build_config.do_build and need_host: + if build_config.do_build and need_host and (build_config.build_only_llvm or not build_config.build_only): llvm_core.llvm_compile( build_config.build_name, llvm_install, build_config.debug, build_config.no_lto, build_config.build_instrumented, + build_config.build_only_llvm, build_config.xunit_xml_output) llvm_package.copy_python_to_host(llvm_make) llvm_package.copy_python_to_host(llvm_install) - llvm_core.set_clang_version(llvm_install) + llvm_core.set_clang_version(llvm_path) - if build_config.build_libs: + if build_config.build_libs and not build_config.build_only: libs_type = 'crts' if 'crts' in build_config.build_libs else 'runtimes' is_first_time = True if build_config.build_libs in ['crts_first_time', 'runtimes_libunwind'] else False is_ndk_install = True if build_config.build_libs == 'runtimes_libcxx_ndk' else False @@ -2597,7 +2808,7 @@ def main(): llvm_libs.build_libs_by_type(llvm_install, target, libs_type, is_first_time, is_ndk_install) return - if build_config.do_build and build_utils.host_is_linux(): + if build_config.do_build and build_utils.host_is_linux() and not build_config.build_only: sysroot_composer.setup_cmake_platform(llvm_install) llvm_libs.build_crt_libs(configs, llvm_install) @@ -2616,6 +2827,44 @@ def main(): print("Build is interrupted because of libCxx ABI changed") return + if build_config.build_only: + sysroot_composer.setup_cmake_platform(llvm_install) + # temporary hide cmake checks for sdk-partly + lib_cmake = os.path.join(build_config.REPOROOT_DIR, 'prebuilts/clang/ohos', build_utils.use_platform(), + 'clang-%s' % build_config.CLANG_VERSION, "lib/cmake") + lib_cmake_tmp = f"{lib_cmake}_tmp" + shutil.move(lib_cmake, lib_cmake_tmp) + + if "musl" in build_config.build_only_libs: + # change compiller path to prebuilds in clang.gni file + clang_gni = os.path.join(build_config.REPOROOT_DIR, "build", "config", "clang", "clang.gni") + clang_gni_tmp = f"{clang_gni}_tmp" + shutil.move(clang_gni, clang_gni_tmp) + with open(clang_gni_tmp, 'r') as f1: + data = f1.read() + with open(clang_gni, 'w') as f2: + data = data.replace("//out/llvm-install", "${toolchains_dir}/${host_platform_dir}/" + f"clang-{build_config.CLANG_VERSION}") + f2.write(data) + # build musl + for (arch, target) in configs: + sysroot_composer.build_musl_header(arch, target) + sysroot_composer.build_musl(arch, target) + # return original version of clang.gni + shutil.move(clang_gni_tmp, clang_gni) + + if "compiler-rt" in build_config.build_only_libs: + assert os.path.exists(os.path.join(build_config.REPOROOT_DIR, "out", "sysroot")), "Error! Compiler-rt require musl!" + for (_, target) in configs: + llvm_libs.build_libs_by_type(llvm_path, llvm_install, target, 'crts', True, False) + llvm_libs.build_libs_by_type(llvm_path, llvm_install, target, 'crts', False, False) + + if "libcxx" in build_config.build_only_libs: + assert os.path.exists(os.path.join(build_config.REPOROOT_DIR, "out", "sysroot")), "Error! Libcxx require musl!" + for (_, target) in configs: + llvm_libs.build_libs_by_type(llvm_path, llvm_install, target, 'runtimes', False, False) + # return original lib/cmake dir + shutil.move(lib_cmake_tmp, lib_cmake) + windows_python_builder = None if build_config.do_build and need_windows: @@ -2656,6 +2905,8 @@ def main(): build_config.enable_assertions, build_config.build_name) + if build_config.build_gtest_libs: + llvm_libs.build_gtest(llvm_path, llvm_install) if build_config.do_package: if build_utils.host_is_linux(): diff --git a/llvm-build/build_libedit.sh b/llvm-build/build_libedit.sh index 5d046197a8874edd4ee453928fa8e68c72edd108..becfc48fb9699fe4566d01d793114586b06f150d 100755 --- a/llvm-build/build_libedit.sh +++ b/llvm-build/build_libedit.sh @@ -10,6 +10,8 @@ LIBEDIT_INSTALL_PATH=$3 NCURSES_PATH=$4 PREBUILT_PATH=$5 CLANG_VERSION=$6 +TARGET=$7 +LIBEDIT_UNTAR_PATH=$8 # Get version and date form libedit.spec (Compatible with Linux and Mac) # The format in the libedit.spec is as follows: @@ -46,35 +48,61 @@ CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_ libedit_package=${LIBEDIT_SRC_DIR}/libedit-${DATE}-${LIBEDIT_VERSION}.tar.gz if [ -e ${libedit_package} ]; then - tar -xzvf ${libedit_package} --strip-components 1 -C ${LIBEDIT_SRC_DIR} + if [ ! -b ${LIBEDIT_UNTAR_PATH} ]; then + mkdir -p ${LIBEDIT_UNTAR_PATH} + fi + tar -xzvf ${libedit_package} --strip-components 1 -C ${LIBEDIT_UNTAR_PATH} + cd ${LIBEDIT_UNTAR_PATH} if [ ! -b ${LIBEDIT_BUILD_PATH} ]; then mkdir -p ${LIBEDIT_BUILD_PATH} fi + patches=($(grep -E '^Patch[0-9]+:' "${SPECFILE}" | sed 's/^[^:]*: *//')) + # Apply patches in order + for patch in "${patches[@]}" + do + patch -Np1 < ${LIBEDIT_SRC_DIR}/$patch + done # build libedit cd ${LIBEDIT_BUILD_PATH} - ldflags="-L${NCURSES_PATH}/lib" - ncuses_flags="-I${NCURSES_PATH}/include" - if [ "${host_platform}" = "darwin" ]; then - ncurses_libs="-Wl,-rpath,@loader_path/../lib:${NCURSES_PATH}/lib" - SDKROOT=$(xcrun --sdk macosx --show-sdk-path) - sdk_flags="-I${SDKROOT}/usr/include" - export LDFLAGS="$LDFLAGS $sdk_flags $ldflags $ncurses_libs" - export CFLAGS="$CFLAGS -isysroot$SDKROOT $ncuses_flags" - fi + ohos_suffix='-ohos' + if [[ ${TARGET} != *${ohos_suffix} ]]; then + ldflags="-L${NCURSES_PATH}/lib" + ncuses_flags="-I${NCURSES_PATH}/include" + if [ "${host_platform}" = "darwin" ]; then + ncurses_libs="-Wl,-rpath,@loader_path/../lib:${NCURSES_PATH}/lib" + SDKROOT=$(xcrun --sdk macosx --show-sdk-path) + sdk_flags="-I${SDKROOT}/usr/include" + export LDFLAGS="$LDFLAGS $sdk_flags $ldflags $ncurses_libs" + export CFLAGS="$CFLAGS -isysroot$SDKROOT $ncuses_flags" + fi - if [ "${host_platform}" = "linux" ]; then - ncurses_libs="-Wl,-rpath,\$$ORIGIN/../lib:${NCURSES_PATH}/lib" - export LDFLAGS="$LDFLAGS $ldflags $ncuses_flags $ncurses_libs" - export CFLAGS="$CFLAGS $ncuses_flags" - fi + if [ "${host_platform}" = "linux" ]; then + ncurses_libs="-Wl,-rpath,\$$ORIGIN/../lib:${NCURSES_PATH}/lib" + export LDFLAGS="$LDFLAGS $ldflags $ncuses_flags $ncurses_libs" + export CFLAGS="$CFLAGS $ncuses_flags" + fi - ${LIBEDIT_SRC_DIR}/configure \ - --prefix=${LIBEDIT_INSTALL_PATH} \ - CC=${CC_PATH} \ - CXX=${CXX_PATH} - make -j$(nproc --all) install | tee build_libedit.log + ${LIBEDIT_UNTAR_PATH}/configure \ + --prefix=${LIBEDIT_INSTALL_PATH} \ + CC=${CC_PATH} \ + CXX=${CXX_PATH} + make -j$(nproc --all) install | tee build_libedit.log + else + C_FLAGS="-I${NCURSES_PATH}/include/ -I${NCURSES_PATH}/include/ncurses -D__STDC_ISO_10646__=201103L -fPIC" + if [[ ${TARGET} =~ 'arm' ]]; then + C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" + fi + ${LIBEDIT_UNTAR_PATH}/configure \ + --prefix=${LIBEDIT_INSTALL_PATH} \ + --host="${TARGET}" \ + CC="${PREBUILT_PATH}/../out/llvm-install/bin/clang --target=${TARGET}" \ + CFLAGS="${C_FLAGS}" \ + LDFLAGS="-L${NCURSES_PATH}/lib" + + make -j$(nproc --all) install | tee build_libedit_${TARGET}.log + fi fi diff --git a/llvm-build/build_ncurses.sh b/llvm-build/build_ncurses.sh index df4f7b1ed45cf568f7c9e49d325186f0aa16b77e..e97163f64fb8cc3a14dc1aa5db5b643ac102ba3b 100755 --- a/llvm-build/build_ncurses.sh +++ b/llvm-build/build_ncurses.sh @@ -10,6 +10,8 @@ NCURSES_INSTALL_PATH=$3 PREBUILT_PATH=$4 CLANG_VERSION=$5 NCURSES_VERSION=$6 +TARGET=$7 +NCURSES_UNTAR_PATH=$8 SPECFILE="${NCURSES_SRC_DIR}/ncurses.spec" @@ -40,8 +42,11 @@ CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_ ncurses_package=${NCURSES_SRC_DIR}/ncurses-${NCURSES_VERSION}.tar.gz if [ -e ${ncurses_package} ]; then - tar -xvzf ${ncurses_package} --strip-components 1 -C ${NCURSES_SRC_DIR} - cd ${NCURSES_SRC_DIR} + if [ ! -b ${NCURSES_UNTAR_PATH} ]; then + mkdir -p ${NCURSES_UNTAR_PATH} + fi + tar -xvzf ${ncurses_package} --strip-components 1 -C ${NCURSES_UNTAR_PATH} + cd ${NCURSES_UNTAR_PATH} # Get the list of patch files for ncurses.spec # The format in the ncurses.spec is as follows: @@ -52,7 +57,7 @@ if [ -e ${ncurses_package} ]; then # Apply patches in order for patch in "${patches[@]}" do - patch -Np1 < $patch + patch -Np1 < ${NCURSES_SRC_DIR}/$patch done if [ ! -b ${NCURSES_BUILD_PATH} ]; then @@ -60,31 +65,55 @@ if [ -e ${ncurses_package} ]; then fi cd ${NCURSES_BUILD_PATH} # build ncurses - if [ "${host_platform}" == "darwin" ]; then - export LDFLAGS="-Wl,-rpath,@loader_path/../lib" - SDKROOT=$(xcrun --sdk macosx --show-sdk-path) - flags="-Wl,-syslibroot,${SDKROOT}" - export CPPFLAGS="$CPPFALGS -I${SDKROOT}/usr/include -I${SDKROOT}/usr/include/i368" - export CFLAGS="$CFLAGS -isysroot${SDKROOT} $flags" + ohos_suffix='-ohos' + if [[ ${7} != *${ohos_suffix} ]]; then + if [ "${host_platform}" == "darwin" ]; then + export LDFLAGS="-Wl,-rpath,@loader_path/../lib" + SDKROOT=$(xcrun --sdk macosx --show-sdk-path) + flags="-Wl,-syslibroot,${SDKROOT}" + export CPPFLAGS="$CPPFALGS -I${SDKROOT}/usr/include -I${SDKROOT}/usr/include/i368" + export CFLAGS="$CFLAGS -isysroot${SDKROOT} $flags" + ${NCURSES_UNTAR_PATH}/configure \ + --with-shared \ + --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ + --disable-mixed-case \ + --prefix=${NCURSES_INSTALL_PATH} \ + CC=${CC_PATH} \ + CXX=${CXX_PATH} + make -j$(nproc --all) install | tee build_ncurses.log + fi + if [ "${host_platform}" == "linux" ]; then + export LDFLAGS="-Wl,-rpath,\$$ORIGIN/../lib" + ${NCURSES_UNTAR_PATH}/configure \ + --with-shared \ + --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ + --prefix=${NCURSES_INSTALL_PATH} \ + CC=${CC_PATH} \ + CXX=${CXX_PATH} + make -j$(nproc --all) install | tee build_ncurses.log + fi + else + C_FLAGS="--target=${TARGET} -fPIC" + if [[ ${TARGET} =~ 'arm' ]]; then + C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" + fi + NCURSES_HOST_INSTALL_PATH=$9 + export LD_LIBRARY_PATH="${NCURSES_HOST_INSTALL_PATH}/lib:$LD_LIBRARY_PATH" ${NCURSES_SRC_DIR}/configure \ + --host="${TARGET}" \ --with-shared \ - --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ - --disable-mixed-case \ - --prefix=${NCURSES_INSTALL_PATH} \ - CC=${CC_PATH} \ - CXX=${CXX_PATH} - make -j$(nproc --all) install | tee build_ncurses.log - fi - if [ "${host_platform}" == "linux" ]; then - export LDFLAGS="-Wl,-rpath,\$$ORIGIN/../lib" - ${NCURSES_SRC_DIR}/configure \ - --with-shared \ - --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ --prefix=${NCURSES_INSTALL_PATH} \ - CC=${CC_PATH} \ - CXX=${CXX_PATH} - make -j$(nproc --all) install | tee build_ncurses.log + --with-termlib \ + --without-manpages \ + --with-strip-program="${PREBUILT_PATH}/../out/llvm-install/bin/llvm-strip" \ + --with-fallbacks=linux,vt100,xterm \ + --with-tic-path=${NCURSES_HOST_INSTALL_PATH}/bin/tic \ + --with-infocmp-path=${NCURSES_HOST_INSTALL_PATH}/bin/infocmp \ + CC=${PREBUILT_PATH}/../out/llvm-install/bin/clang \ + CXX=${PREBUILT_PATH}/../out/llvm-install/bin/clang++ \ + CFLAGS="${C_FLAGS}" + make -j$(nproc --all) install | tee build_ncurses_${TARGET}.log fi fi diff --git a/llvm-build/env_prepare.sh b/llvm-build/env_prepare.sh index 6614f8c2fc6ffb7dc3d58d0447b451e1f9eafdbb..e2111ee61d6824945fabf5662921151df5c5cd9a 100755 --- a/llvm-build/env_prepare.sh +++ b/llvm-build/env_prepare.sh @@ -131,11 +131,13 @@ CLANG_DARWIN_BUILD=$(basename "$darwin_filename" .tar.bz2) if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/${CLANG_LINUX_BUILD}" ]; then SET_CLANG_VERSION='15.0.4' mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/${CLANG_LINUX_BUILD}" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-${SET_CLANG_VERSION}" + ln -s "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-${SET_CLANG_VERSION}" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm" fi if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/${CLANG_DARWIN_BUILD}" ]; then SET_CLANG_VERSION='15.0.4' mv "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/${CLANG_DARWIN_BUILD}" "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-${SET_CLANG_VERSION}" + ln -s "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-${SET_CLANG_VERSION}" "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm" fi # try to detect version ... diff --git a/llvm-build/ohos_toolchain_builder.py b/llvm-build/ohos_toolchain_builder.py new file mode 100644 index 0000000000000000000000000000000000000000..f8a586f90c9d71b30cd879ea811064cb19517cd0 --- /dev/null +++ b/llvm-build/ohos_toolchain_builder.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python3 +# Copyright (C) 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 os +from typing import List +from build import BuildConfig, BuildUtils, LlvmLibs, SysrootComposer, LlvmPackage +from python_builder import OHOSPythonBuilder + + +class OHOSToolchainBuilder: + def __init__(self, llvm_triple) -> None: + self._llvm_triple = llvm_triple + self._platform = llvm_triple.split("-")[0] + self._build_config = BuildConfig() + self._build_utils = BuildUtils(self._build_config) + self._sysroot_composer = SysrootComposer(self._build_config) + self._llvm_package = LlvmPackage(self._build_config) + self._llvm_libs = LlvmLibs( + self._build_config, self._sysroot_composer, self._llvm_package + ) + self._python_builder = OHOSPythonBuilder(self._build_utils, self._llvm_triple) + self._llvm_project_path = os.path.abspath( + os.path.join(self._build_config.LLVM_PROJECT_DIR, "llvm") + ) + self._llvm_path = self._build_utils.merge_out_path(f"ohos-{self._platform}") + self._llvm_install = self._build_utils.merge_out_path( + f"ohos-{self._platform}-install" + ) + self._llvm_root = self._build_utils.merge_out_path("llvm-install") + self._sysroot = self._build_utils.merge_out_path("sysroot") + + self._cflags = self._init_cflags() + self._ldflags = self._init_ldflags() + self._llvm_defines = self._init_llvm_defines() + + def _init_cflags(self) -> List[str]: + cflags = [ + "-fstack-protector-strong", + "--target=%s" % self._llvm_triple, + "-ffunction-sections", + "-fdata-sections", + ] + return cflags + + def _init_ldflags(self) -> List[str]: + ldflags = [ + "-fuse-ld=lld", + "-Wl,--gc-sections", + "-Wl,--build-id=sha1", + "--rtlib=compiler-rt", + "-stdlib=libc++", + "-Wl,-z,relro,-z,now", + "-pie", + "-lunwind", + ] + return ldflags + + def _init_llvm_defines(self): + llvm_defines = {} + llvm_defines["LLVM_TARGET_ARCH"] = self._platform + llvm_defines["OHOS"] = "1" + llvm_defines["CMAKE_SYSTEM_NAME"] = "OHOS" + llvm_defines["CMAKE_CROSSCOMPILING"] = "True" + llvm_defines["CMAKE_INSTALL_PREFIX"] = self._llvm_install + llvm_defines["CMAKE_SYSROOT"] = self._sysroot + llvm_defines["LLVM_HOST_TRIPLE"] = self._llvm_triple + llvm_defines["LLVM_TARGETS_TO_BUILD"] = self._build_config.TARGETS + llvm_defines["LLVM_DEFAULT_TARGET_TRIPLE"] = self._llvm_triple + llvm_defines["LLVM_ENABLE_TERMINFO"] = "OFF" + llvm_defines["LLVM_CONFIG_PATH"] = os.path.join( + self._llvm_root, "bin", "llvm-config" + ) + llvm_defines["LLVM_TABLEGEN"] = os.path.join( + self._llvm_root, "bin", "llvm-tblgen" + ) + llvm_defines["CMAKE_C_COMPILER"] = os.path.join(self._llvm_root, "bin", "clang") + llvm_defines["CMAKE_CXX_COMPILER"] = os.path.join( + self._llvm_root, "bin", "clang++" + ) + llvm_defines["CMAKE_AR"] = os.path.join(self._llvm_root, "bin", "llvm-ar") + llvm_defines["CMAKE_FIND_ROOT_PATH_MODE_INCLUDE"] = "ONLY" + llvm_defines["CMAKE_FIND_ROOT_PATH_MODE_LIBRARY"] = "ONLY" + llvm_defines["CMAKE_FIND_ROOT_PATH_MODE_PACKAGE"] = "ONLY" + llvm_defines["CMAKE_FIND_ROOT_PATH_MODE_PROGRAM"] = "NEVER" + llvm_defines["Python3_EXECUTABLE"] = os.path.join( + self._build_utils.get_python_dir(), "bin", self._build_config.LLDB_PYTHON + ) + + if self._build_config.debug: + llvm_defines["CMAKE_BUILD_TYPE"] = "Debug" + else: + llvm_defines["CMAKE_BUILD_TYPE"] = "Release" + + llvm_defines.update(self._init_lldb_defines()) + + return llvm_defines + + def _init_lldb_defines(self): + lldb_defines = {} + lldb_defines["LLDB_INCLUDE_TESTS"] = "OFF" + if self._build_config.lldb_timeout: + lldb_defines["LLDB_ENABLE_TIMEOUT"] = "True" + # Optional Dependencies + if self._build_config.build_ncurses: + lldb_defines["LLDB_ENABLE_CURSES"] = "ON" + lldb_defines["CURSES_INCLUDE_DIRS"] = ";".join( + [ + self._build_utils.merge_ncurses_install_dir( + self._llvm_triple, "include" + ), + self._build_utils.merge_ncurses_install_dir( + self._llvm_triple, "include", "ncurses" + ), + ] + ) + ncurses_libs = [] + for library in self._build_utils.get_ncurses_dependence_libs(self._llvm_triple): + library_path = self._build_utils.merge_ncurses_install_dir( + self._llvm_triple, + "lib", + f"{library}.so.%s" % self._build_utils.get_ncurses_version(), + ) + ncurses_libs.append(library_path) + lldb_defines["CURSES_LIBRARIES"] = ";".join(ncurses_libs) + lldb_defines["PANEL_LIBRARIES"] = ";".join(ncurses_libs) + + if self._build_config.build_libxml2: + self._build_config.LIBXML2_VERSION = self._build_utils.get_libxml2_version() + + lldb_defines["LLDB_ENABLE_LIBXML2"] = "ON" + lldb_defines["LIBXML2_INCLUDE_DIR"] = ( + self._build_utils.merge_libxml2_install_dir( + self._llvm_triple, "include", "libxml2" + ) + ) + lldb_defines["LIBXML2_LIBRARY"] = ( + self._build_utils.merge_libxml2_install_dir( + self._llvm_triple, + "lib", + "libxml2.so.%s" % self._build_utils.get_libxml2_version(), + ) + ) + + if self._build_config.build_libedit: + lldb_defines["LLDB_ENABLE_LIBEDIT"] = "ON" + lldb_defines["LibEdit_INCLUDE_DIRS"] = ( + self._build_utils.merge_libedit_install_dir( + self._llvm_triple, "include" + ) + ) + lldb_defines["LibEdit_LIBRARIES"] = ( + self._build_utils.merge_libedit_install_dir( + self._llvm_triple, "lib", "libedit.so.0.0.68" + ) + ) + + if self._build_config.build_python: + lldb_defines["LLDB_ENABLE_PYTHON"] = "ON" + lldb_defines["LLDB_EMBED_PYTHON_HOME"] = "ON" + lldb_defines["LLDB_PYTHON_HOME"] = f"../{self._build_config.LLDB_PYTHON}" + lldb_defines["LLDB_PYTHON_RELATIVE_PATH"] = "bin/python/lib/python%s" % ( + self._build_config.LLDB_PY_VERSION + ) + lldb_defines["LLDB_PYTHON_EXE_RELATIVE_PATH"] = "bin/python" + lldb_defines["LLDB_PYTHON_EXT_SUFFIX"] = ".so" + lldb_defines["Python3_INCLUDE_DIRS"] = ( + self._build_utils.merge_python_install_dir( + self._llvm_triple, + "include", + f"python{self._build_config.LLDB_PY_VERSION}", + ) + ) + lldb_defines["Python3_LIBRARIES"] = self._build_utils.merge_python_install_dir( + self._llvm_triple, + "lib", + "libpython%s.so" % self._build_config.LLDB_PY_VERSION, + ) + + lldb_defines["LLDB_ENABLE_LZMA"] = "OFF" + # Debug & Tuning + if self._build_config.enable_monitoring: + lldb_defines["LLDB_ENABLE_PERFORMANCE"] = "ON" + + return lldb_defines + + def _build_and_install(self, build_target): + if self._build_config.build_ncurses: + self._llvm_libs.build_ncurses("", self._llvm_install, self._llvm_triple) + if self._build_config.build_libxml2: + self._llvm_libs.build_libxml2(self._llvm_triple, "", self._llvm_install) + if self._build_config.build_libedit: + self._llvm_libs.build_libedit("", self._llvm_install, self._llvm_triple) + if self._build_config.build_python: + self._python_builder.build() + + self._build_utils.invoke_cmake( + self._llvm_project_path, + self._llvm_path, + self._llvm_defines, + env=dict(self._build_config.ORIG_ENV), + ) + + self._build_utils.invoke_ninja( + out_path=self._llvm_path, + env=dict(self._build_config.ORIG_ENV), + target=build_target, + install=True, + ) + + if self._build_config.build_python: + self._python_builder.copy_python_to_host(self._llvm_install) + + # Copy required arm-linux-ohos libs from main toolchain build. + arch_list = [ + self._build_utils.liteos_triple("arm"), + self._build_utils.open_ohos_triple("arm"), + self._build_utils.open_ohos_triple("aarch64"), + self._build_utils.open_ohos_triple("riscv64"), + self._build_utils.open_ohos_triple("mipsel"), + self._build_utils.open_ohos_triple("x86_64"), + ] + for arch in arch_list: + self._build_utils.check_copy_tree( + os.path.join(self._llvm_root, "lib", arch), + os.path.join(self._llvm_install, "lib", arch), + ) + self._build_utils.check_copy_tree( + os.path.join(self._llvm_root, "lib", "clang", "15.0.4", "lib", arch), + os.path.join(self._llvm_install, "lib", "clang", "15.0.4", "lib", arch), + ) + + # Copy required c++ headerfiles from main toolchain build. + self._build_utils.check_copy_tree( + os.path.join(self._llvm_root, "include", "c++"), + os.path.join(self._llvm_install, "include", "c++"), + ) + self._build_utils.check_copy_tree( + os.path.join(self._llvm_root, "include", "libcxx-ohos"), + os.path.join(self._llvm_install, "include", "libcxx-ohos"), + ) + + def _package_if_need(self): + if self._build_config.do_package: + tarball_name = ( + f"clang-{self._build_config.build_name}-ohos-{self._platform}" + ) + package_path = "%s%s" % ( + self._build_utils.merge_packages_path(tarball_name), + self._build_config.ARCHIVE_EXTENSION, + ) + self._build_utils.logger().info("Packaging %s", package_path) + args = [ + "tar", + self._build_config.ARCHIVE_OPTION, + "-h", + "-C", + self._build_config.OUT_PATH, + "-f", + package_path, + f"ohos-{self._platform}-install", + ] + self._build_utils.check_create_dir(self._build_config.PACKAGES_PATH) + self._build_utils.check_call(args) + + # virtual function + def _update_build_args(self): + return + + def build(self, build_target=None): + self._update_build_args() + + self._build_and_install(build_target) + + self._package_if_need() diff --git a/llvm-build/python_builder.py b/llvm-build/python_builder.py index 7ca5426987ee9b781fbc404ec7765ab1d7bb0337..1663b59168753e7aedeff266b9e073f77d427566 100755 --- a/llvm-build/python_builder.py +++ b/llvm-build/python_builder.py @@ -18,28 +18,22 @@ import shutil import subprocess from typing import List, Mapping -class MinGWPythonBuilder: - target_platform = "x86_64-w64-mingw32" +class PythonBuilder: + target_platform = "" + patches = [] def __init__(self, build_config) -> None: - repo_root = Path(build_config.REPOROOT_DIR).resolve() + self.repo_root = Path(build_config.REPOROOT_DIR).resolve() self._out_dir = Path(build_config.OUT_PATH).resolve() self._clang_toolchain_dir = self._out_dir / 'llvm-install' - self._mingw_install_dir = self._out_dir / 'mingw' / build_config.MINGW_TRIPLE - self._source_dir = repo_root / 'third_party' / 'python' - self._build_dir = self._out_dir / 'python-windows-build' - self._install_dir = self._out_dir / 'python-windows-install' self._version = build_config.LLDB_PY_DETAILED_VERSION version_parts = self._version.split('.') self._major_version = version_parts[0] + '.' + version_parts[1] - # This file is used to detect whether patches are applied - self._mingw_ignore_file = self._source_dir / 'mingw_ignorefile.txt' + self._source_dir = self.repo_root / 'third_party' / 'python' self._patch_dir = self._source_dir / 'patches' + self._install_dir = "" - for directory in (self._clang_toolchain_dir, self._mingw_install_dir, - self._source_dir): - if not directory.is_dir(): - raise ValueError(f'No such directory "{directory}"') + self._clean_patches() @property def _logger(self) -> logging.Logger: @@ -49,6 +43,14 @@ class MinGWPythonBuilder: def _cc(self) -> Path: return self._clang_toolchain_dir/ 'bin' / 'clang' + @property + def _cflags(self) -> List[str]: + return [] + + @property + def _ldflags(self) -> List[str]: + return [] + @property def _cxx(self) -> Path: return self._clang_toolchain_dir / 'bin' / 'clang++' @@ -57,33 +59,13 @@ class MinGWPythonBuilder: def _strip(self) -> Path: return self._clang_toolchain_dir / 'bin' / 'llvm-strip' - @property - def _cflags(self) -> List[str]: - cflags = [ - f'-target {self.target_platform}', - f'--sysroot={self._mingw_install_dir}', - ] - return cflags - @property def _cxxflags(self) -> List[str]: return self._cflags.copy() - @property - def _ldflags(self) -> List[str]: - ldflags = [ - f'--sysroot={self._mingw_install_dir}', - f'-rtlib=compiler-rt', - f'-target {self.target_platform}', - f'-lucrt', - f'-lucrtbase', - f'-fuse-ld=lld', - ] - return ldflags - @property def _rcflags(self) -> List[str]: - return [ f'-I{self._mingw_install_dir}/include' ] + return [] @property def _env(self) -> Mapping[str, str]: @@ -104,26 +86,19 @@ class MinGWPythonBuilder: 'CXXFLAGS': ' '.join(self._cxxflags), 'LDFLAGS': ' '.join(self._ldflags), 'RCFLAGS': ' '.join(self._rcflags), + 'CPPFLAGS': ' '.join(self._cflags), }) return env def _configure(self) -> None: - subprocess.check_call(['autoreconf', '-vfi'], cwd=self._source_dir) - build_platform = subprocess.check_output( - ['./config.guess'], cwd=self._source_dir).decode().strip() - config_flags = [ - f'--prefix={self._install_dir}', - f'--build={build_platform}', - f'--host={self.target_platform}', - '--enable-shared', - '--without-ensurepip', - '--enable-loadable-sqlite-extensions', - ] - cmd = [str(self._source_dir / 'configure')] + config_flags - subprocess.check_call(cmd, env=self._env, cwd=self._build_dir) + return + + def _clean_patches(self) -> None: + subprocess.check_call(['git', 'reset', '--hard', 'HEAD'], cwd=self._source_dir) + subprocess.check_call(['git', 'clean', '-df'], cwd=self._source_dir) def _pre_build(self) -> None: - if self._mingw_ignore_file.is_file(): + if self._patch_ignore_file.is_file(): self._logger.warning('Patches for Python have being applied, skip patching') return @@ -132,7 +107,7 @@ class MinGWPythonBuilder: return for patch in self._patch_dir.iterdir(): - if patch.is_file(): + if patch.is_file() and patch.name in self.patches: cmd = [ 'git', 'apply', str(patch) ] subprocess.check_call(cmd, cwd=self._source_dir) @@ -142,8 +117,8 @@ class MinGWPythonBuilder: shutil.rmtree(self._build_dir) if self._install_dir.exists(): shutil.rmtree(self._install_dir) - self._build_dir.mkdir() - self._install_dir.mkdir() + self._build_dir.mkdir(parents=True) + self._install_dir.mkdir(parents=True) self._configure() self._install() @@ -194,6 +169,70 @@ class MinGWPythonBuilder: for cache_dir in pycaches: shutil.rmtree(cache_dir) + @property + def install_dir(self) -> str: + return str(self._install_dir) + + +class MinGWPythonBuilder(PythonBuilder): + def __init__(self, build_config) -> None: + super().__init__(build_config) + + self.target_platform = "x86_64-w64-mingw32" + self.patches = ["cpython_mingw_v3.10.2.patch"] + + self._mingw_install_dir = self._out_dir / 'mingw' / build_config.MINGW_TRIPLE + self._build_dir = self._out_dir / 'python-windows-build' + self._install_dir = self._out_dir / 'python-windows-install' + + # This file is used to detect whether patches are applied + self._patch_ignore_file = self._source_dir / 'mingw_ignorefile.txt' + + + for directory in (self._clang_toolchain_dir, self._mingw_install_dir, + self._source_dir): + if not directory.is_dir(): + raise ValueError(f'No such directory "{directory}"') + + @property + def _cflags(self) -> List[str]: + cflags = [ + f'-target {self.target_platform}', + f'--sysroot={self._mingw_install_dir}', + ] + return cflags + + @property + def _ldflags(self) -> List[str]: + ldflags = [ + f'--sysroot={self._mingw_install_dir}', + f'-rtlib=compiler-rt', + f'-target {self.target_platform}', + f'-lucrt', + f'-lucrtbase', + f'-fuse-ld=lld', + ] + return ldflags + + @property + def _rcflags(self) -> List[str]: + return [ f'-I{self._mingw_install_dir}/include' ] + + def _configure(self) -> None: + subprocess.check_call(['autoreconf', '-vfi'], cwd=self._source_dir) + build_platform = subprocess.check_output( + ['./config.guess'], cwd=self._source_dir).decode().strip() + config_flags = [ + f'--prefix={self._install_dir}', + f'--build={build_platform}', + f'--host={self.target_platform}', + '--enable-shared', + '--without-ensurepip', + '--enable-loadable-sqlite-extensions', + ] + cmd = [str(self._source_dir / 'configure')] + config_flags + subprocess.check_call(cmd, env=self._env, cwd=self._build_dir) + def prepare_for_package(self) -> None: self._clean_bin_dir() self._clean_share_dir() @@ -215,6 +254,71 @@ class MinGWPythonBuilder: ] + [ f.name for f in self._install_dir.iterdir() ] subprocess.check_call(cmd, cwd=self._install_dir) + +class OHOSPythonBuilder(PythonBuilder): + def __init__(self, build_utils, target_platform) -> None: + super().__init__(build_utils.build_config) + + self.target_platform = target_platform + self.patches = ["cross_compile_support_ohos.patch"] + + self._build_dir = Path(build_utils.merge_python_build_dir(target_platform)) + self._install_dir = Path(build_utils.merge_python_install_dir(target_platform)) + + # This file is used to detect whether patches are applied + self._patch_ignore_file = self._source_dir / 'support_ohos_ignorefile.txt' + + self.build_utils = build_utils + return + @property - def install_dir(self) -> str: - return str(self._install_dir) + def _cflags(self) -> List[str]: + cflags = [ + f'--target={self.target_platform}', + '-nostdinc', + '-I%s' % str(self._out_dir / 'sysroot' / self.target_platform / 'usr' / 'include'), + ] + if str(self.target_platform).find("arm") > 0: + cflags.append('-march=armv7-a -mfloat-abi=soft') + return cflags + + @property + def _ldflags(self) -> List[str]: + ldflags = [ + f'-rtlib=compiler-rt', + f'--target={self.target_platform}', + f'-fuse-ld=lld', + '-L%s' % str(self._out_dir / 'sysroot' / self.target_platform / 'usr' / 'lib'), + '-lc', + '-Wl,-rpath,\\$$ORIGIN/../lib', + ] + return ldflags + + def _configure(self) -> None: + subprocess.check_call(['autoreconf', '-vfi'], cwd=self._source_dir) + build_platform = subprocess.check_output( + ['./config.guess'], cwd=self._source_dir).decode().strip() + config_flags = [ + f'--prefix={self._install_dir}', + f'--build={build_platform}', + f'--host={self.target_platform}', + '--enable-shared', + '--without-ensurepip', + '--enable-loadable-sqlite-extensions', + '--disable-ipv6', + 'ac_cv_file__dev_ptmx=no', + 'ac_cv_file__dev_ptc=no', + '--without-system-ffi', + '--enable-optimizations', + '--without-pydebug', + '--without-doc-strings', + '--without-dtrace', + ] + cmd = [str(self._source_dir / 'configure')] + config_flags + subprocess.check_call(cmd, env=self._env, cwd=self._build_dir) + + def copy_python_to_host(self, install_dir): + libpython = f'libpython{self.build_utils.build_config.LLDB_PY_VERSION}.so.1.0' + + shutil.copyfile(os.path.join(self._install_dir, "lib", libpython), os.path.join(install_dir, 'lib', libpython)) + self.build_utils.check_copy_tree(self._install_dir, os.path.join(install_dir, self.build_utils.build_config.LLDB_PYTHON)) diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst index 50c5bf88ec13042745ac75c6ef65fc9166d0dd1c..cae33b3bb7048c5a3e88ff29a28d36692e2483ad 100644 --- a/llvm/docs/BitCodeFormat.rst +++ b/llvm/docs/BitCodeFormat.rst @@ -807,9 +807,10 @@ function. The operand fields are: * ``arkfast3cc`` : code 25 * ``arkfast4cc`` : code 26 * ``arkfast5cc`` : code 27 - * ``arkmethodcc`` : code 28 - * ``arkresolvercc`` : code 29 - * ``arkpltcc`` : code 30 + * ``arkfast6cc`` : code 28 + * ``arkmethodcc`` : code 29 + * ``arkresolvercc`` : code 30 + * ``arkpltcc`` : code 31 .. OHOS_LOCAL end * ``x86_stdcallcc``: code 64 * ``x86_fastcallcc``: code 65 diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index e3cc48d7e9ca8ae1767c52678b2ce518da390580..060a765b9f091f1ac552fdd7900fddc0938aadc4 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -473,6 +473,8 @@ added in the future: Ark Itroc calling convention for FastPath handlers with four arguments "``arkfast5cc``" Ark Itroc calling convention for FastPath handlers with five arguments +"``arkfast6cc``" + Ark Itroc calling convention for FastPath handlers with six arguments "``arkmethodcc``" Ark AOT method calling convention with frame adaptation "``arkresolvercc``" diff --git a/llvm/include/llvm/AsmParser/LLToken.h b/llvm/include/llvm/AsmParser/LLToken.h index a0cb5168ed716d0415f5574e7aff1cece1de5bac..fe0e3f3a0460005dba4807c25e74aeec94cd57df 100644 --- a/llvm/include/llvm/AsmParser/LLToken.h +++ b/llvm/include/llvm/AsmParser/LLToken.h @@ -179,6 +179,7 @@ enum Kind { kw_arkfast3cc, kw_arkfast4cc, kw_arkfast5cc, + kw_arkfast6cc, kw_arkmethodcc, kw_arkresolvercc, kw_arkpltcc, diff --git a/llvm/include/llvm/BinaryFormat/ADLTSection.h b/llvm/include/llvm/BinaryFormat/ADLTSection.h new file mode 100644 index 0000000000000000000000000000000000000000..6d57903cdd09deae23b0790d0db0237e8b032713 --- /dev/null +++ b/llvm/include/llvm/BinaryFormat/ADLTSection.h @@ -0,0 +1,122 @@ +//===- ADLTSection.h - ADLT Section data types --------------------*- C -*-===// +// +// Copyright (C) 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. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_BINARYFORMAT_ADLTSECTION_H +#define LLVM_BINARYFORMAT_ADLTSECTION_H + +#ifdef __cplusplus +#include + +namespace llvm { +namespace adlt { + +#else // __cplusplus +#include +#endif // __cplusplus + +#ifndef _ELF_H +// part of #include +typedef uint16_t Elf64_Half; +typedef uint64_t Elf64_Off; +typedef uint64_t Elf64_Addr; +typedef uint32_t Elf64_Word; +typedef uint64_t Elf64_Xword; +typedef uint8_t Elf64_Byte; +#endif // _ELF_H + +typedef struct { + Elf64_Word secIndex; + Elf64_Off offset; // from section start +} adlt_cross_section_ref_t; + +typedef struct { + Elf64_Word secIndex; + Elf64_Off offset; // from section start + Elf64_Xword size; // size in bytes +} adlt_cross_section_array_t; + +typedef struct { + Elf64_Off offset; // relative to header.blobStart + Elf64_Xword size; // size in bytes, make convertions for data type +} adlt_blob_array_t; + +// plain-C has no strict typedefs, but aliases used to interpred underlying data +typedef adlt_blob_array_t adlt_blob_u8_array_t; // uint8_t[] +typedef adlt_blob_array_t adlt_blob_u16_array_t; // uint16_t[] +typedef adlt_blob_array_t adlt_blob_u32_array_t; // uint32_t[] +typedef adlt_blob_array_t adlt_blob_u64_array_t; // uint64_t[] + +typedef struct { + Elf64_Half major : 6; + Elf64_Half minor : 6; + Elf64_Half patch : 4; +} adlt_semver_t; + +// DT_NEEDED string index with embedded PSOD index if available +typedef struct { + Elf64_Off hasInternalPSOD : 1; // true if soname + Elf64_Off PSODindex : 16; // PSOD in the current ADLT image + Elf64_Off sonameOffset : 47; // string start in bound .adlt.strtab +} adlt_dt_needed_index_t; + +typedef enum { + ADLT_HASH_TYPE_NONE = 0, + ADLT_HASH_TYPE_GNU_HASH = 1, + ADLT_HASH_TYPE_SYSV_HASH = 2, + ADLT_HASH_TYPE_DEBUG_CONST = 0xfe, + ADLT_HASH_TYPE_MAX = 0xff, +} adlt_hash_type_enum_t; + +typedef uint8_t adlt_hash_type_t; + +// Serializable representation per-shared-object-data in .adlt section +typedef struct { + Elf64_Off soName; // offset in .adlt.strtab + Elf64_Xword soNameHash; // algorithm according to hdr.stringHashType value + adlt_cross_section_array_t initArray; + adlt_cross_section_array_t finiArray; + adlt_blob_array_t dtNeeded; // array of adlt_dt_needed_index_t[] elems + adlt_cross_section_ref_t sharedLocalSymbolIndex; + adlt_cross_section_ref_t sharedGlobalSymbolIndex; + adlt_blob_u16_array_t phIndexes; // program header indexes, typeof(e_phnum) + adlt_blob_u32_array_t relaDynIndx; // .rela.dyn dependent indexes, raw list + adlt_blob_u32_array_t relaPltIndx; // .rela.plt dependent indexes, raw list +} adlt_psod_t; + +typedef struct { + adlt_semver_t schemaVersion; // {major, minor, patch} + Elf64_Half schemaHeaderSize; // >= sizeof(adlt_section_header_t) if comp + Elf64_Half schemaPSODSize; // >= sizeof(adlt_psod_t) if compatible + Elf64_Half sharedObjectsNum; // number of PSOD entries + adlt_hash_type_t stringHashType; // contains adlt_hash_type_enum_t value + Elf64_Off blobStart; // offset of binary blob start relative to .adlt + Elf64_Xword blobSize; + Elf64_Xword overallMappedSize; // bytes, required to map the whole ADLT image + adlt_blob_u16_array_t phIndexes; // program header indexes, typeof(e_phnum) +} adlt_section_header_t; + +static const char adltBlobStartMark[4] = {0xA, 0xD, 0x1, 0x7}; + +static const adlt_semver_t adltSchemaVersion = {1, 1, 0}; + +#ifdef __cplusplus +} // namespace adlt +} // namespace llvm +#endif // __cplusplus + +#endif // LLVM_BINARYFORMAT_ADLTSECTION_H diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h index 234c946b2014b812c789004bf2c163b594371382..6a12c647f79fb4855b8925e65c4306412b9a3948 100644 --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -1391,6 +1391,8 @@ enum { PT_OPENBSD_BOOTDATA = 0x65a41be6, // Section for boot arguments. PT_OHOS_RANDOMDATA = 0x6788FC60, // Fill with random data. OHOS_LOCAL + // OHOS_LOCAL + PT_ADLT = 0x6788FC61, // Adlt information. // ARM program header types. PT_ARM_ARCHEXT = 0x70000000, // Platform architecture compatibility info diff --git a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h index 04369a5bfe0d563a8fb2931211c25224915380c5..c70fe7ce07cf6dc95281a6facf2fbae6906e5a74 100644 --- a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h @@ -23,6 +23,7 @@ #include "llvm/IR/CallingConv.h" #include "llvm/MC/LaneBitmask.h" #include "llvm/MC/MCRegisterInfo.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MachineValueType.h" #include "llvm/Support/MathExtras.h" @@ -30,6 +31,8 @@ #include #include +extern llvm::cl::opt SpillSlotMinSize; // OHOS_LOCAL + namespace llvm { class BitVector; @@ -287,7 +290,13 @@ public: /// Return the minimum required alignment in bytes for a spill slot for /// a register of this class. Align getSpillAlign(const TargetRegisterClass &RC) const { - return Align(getRegClassInfo(RC).SpillAlignment / 8); + // OHOS_LOCAL begin + auto align = getRegClassInfo(RC).SpillAlignment / 8; + if (align < SpillSlotMinSize) { + align = SpillSlotMinSize; + } + return Align(align); + // OHOS_LOCAL end } /// Return true if the given TargetRegisterClass has the ValueType T. diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h index 3221e5c9541d6e8c7d19d89829288f9053a63c3c..586ec1519840d380ff9effef914b0090936f54ca 100644 --- a/llvm/include/llvm/IR/CallingConv.h +++ b/llvm/include/llvm/IR/CallingConv.h @@ -115,14 +115,17 @@ namespace CallingConv { // Ark Itroc calling convention for FastPath handlers with five arguments ArkFast5 = 27, + // Ark Itroc calling convention for FastPath handlers with six arguments + ArkFast6 = 28, + // Ark AOT method calling convention with frame adaptation - ArkMethod = 28, + ArkMethod = 29, // Ark AOT calling convention for special class resolvers - ArkResolver = 29, + ArkResolver = 30, // Ark AOT calling convention for static calls through special PLT resolver - ArkPlt = 30, + ArkPlt = 31, // OHOS_LOCAL end // Target - This is the start of the target-specific calling conventions, diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp index a77f77c8e91ea0d3dd2970087262345f0cf4398c..509cda0cc738b252f2f1d8b248392ba59b35a418 100644 --- a/llvm/lib/AsmParser/LLLexer.cpp +++ b/llvm/lib/AsmParser/LLLexer.cpp @@ -637,6 +637,7 @@ lltok::Kind LLLexer::LexIdentifier() { KEYWORD(arkfast3cc); KEYWORD(arkfast4cc); KEYWORD(arkfast5cc); + KEYWORD(arkfast6cc); KEYWORD(arkmethodcc); KEYWORD(arkresolvercc); KEYWORD(arkpltcc); diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 6f270e0db471d82dd3677e8ac60cfc6cc54cef26..30b0d917b696e3ad09fb6473567122f7c44175fc 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1912,6 +1912,7 @@ void LLParser::parseOptionalDLLStorageClass(unsigned &Res) { /// ::= 'arkfast3cc' /// ::= 'arkfast4cc' /// ::= 'arkfast5cc' +/// ::= 'arkfast6cc' /// ::= 'arkmethodcc' /// ::= 'arkresolvercc' /// ::= 'arkpltcc' @@ -1976,6 +1977,7 @@ bool LLParser::parseOptionalCallingConv(unsigned &CC) { case lltok::kw_arkfast3cc: CC = CallingConv::ArkFast3; break; case lltok::kw_arkfast4cc: CC = CallingConv::ArkFast4; break; case lltok::kw_arkfast5cc: CC = CallingConv::ArkFast5; break; + case lltok::kw_arkfast6cc: CC = CallingConv::ArkFast6; break; case lltok::kw_arkmethodcc: CC = CallingConv::ArkMethod; break; case lltok::kw_arkresolvercc: CC = CallingConv::ArkResolver; break; case lltok::kw_arkpltcc: CC = CallingConv::ArkPlt; break; diff --git a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp index 961707a7fc9ecc5e59d4ce93c85c3b40e0aa6ed0..f047e80cd62f34bf050f10e331003d4712588022 100644 --- a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp @@ -78,14 +78,6 @@ cl::opt MaxRegistersForGCPointers( "max-registers-for-gc-values", cl::Hidden, cl::init(0), cl::desc("Max number of VRegs allowed to pass GC pointer meta args in")); -// OHOS_LOCAL begin -// Useful when gc managed references are 32-bit wide but runtime supports only -// 64-bit slots -cl::opt SpillSlotMinSize("spill-slot-min-size-bytes", cl::Hidden, - cl::init(1), - cl::desc("Minimum size of a spill slot")); -// OHOS_LOCAL end - typedef FunctionLoweringInfo::StatepointRelocationRecord RecordType; static void pushStackMapConstant(SmallVectorImpl& Ops, @@ -719,6 +711,11 @@ lowerStatepointMetaArgs(SmallVectorImpl &Ops, return !willLowerDirectly(SD); }; + // OHOS_LOCAL begin + auto StatepointInst = dyn_cast_or_null(SI.StatepointInstr); + auto AssignedArkSlots = tryAssignStackSlots(Builder, StatepointInst); + // OHOS_LOCAL end + auto processGCPtr = [&](const Value *V) { SDValue PtrSD = Builder.getValue(V); if (!LoweredGCPtrs.insert(PtrSD)) @@ -726,6 +723,10 @@ lowerStatepointMetaArgs(SmallVectorImpl &Ops, GCNodeToGCValue[PtrSD] = V; // OHOS_LOCAL GCPtrIndexMap[PtrSD] = LoweredGCPtrs.size() - 1; + // OHOS_LOCAL begin + if (AssignedArkSlots.count(V)) + return; // we need to assign these to stack + // OHOS_LOCAL end assert(!LowerAsVReg.count(PtrSD) && "must not have been seen"); if (LowerAsVReg.size() == MaxVRegPtrs) return; @@ -756,11 +757,6 @@ lowerStatepointMetaArgs(SmallVectorImpl &Ops, return !(LiveInDeopt || UseRegistersForDeoptValues); }; - // OHOS_LOCAL begin - auto StatepointInst = dyn_cast_or_null(SI.StatepointInstr); - auto AssignedArkSlots = tryAssignStackSlots(Builder, StatepointInst); - // OHOS_LOCAL end - // Before we actually start lowering (and allocating spill slots for values), // reserve any stack slots which we judge to be profitable to reuse for a // particular value. This is purely an optimization over the code below and diff --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp index ac346585b0f8fc82d97a263bf0e445cabf710c36..77e6c923e0364a41895ba312764a06fa08ebf452 100644 --- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp +++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp @@ -50,6 +50,14 @@ static cl::opt "high compile time cost in global splitting."), cl::init(5000)); +// OHOS_LOCAL begin +// Useful when gc managed references are 32-bit wide but runtime supports only +// 64-bit slots +cl::opt SpillSlotMinSize( + "spill-slot-min-size-bytes", cl::Hidden, cl::init(1), + cl::desc("Minimum size and alignment of a spill slot")); +// OHOS_LOCAL end + TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterInfoDesc *ID, regclass_iterator RCB, regclass_iterator RCE, const char *const *SRINames, diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index cc5e4f58671634e5e7db24000df1ad90d9cb03d1..2d6bb345e465d2aa3ab05b87767d12cc57881366 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -305,6 +305,7 @@ static void PrintCallingConv(unsigned cc, raw_ostream &Out) { case CallingConv::ArkFast3: Out << "arkfast3cc"; break; case CallingConv::ArkFast4: Out << "arkfast4cc"; break; case CallingConv::ArkFast5: Out << "arkfast5cc"; break; + case CallingConv::ArkFast6: Out << "arkfast6cc"; break; case CallingConv::ArkMethod: Out << "arkmethodcc"; break; case CallingConv::ArkResolver: Out << "arkresolvercc"; break; case CallingConv::ArkPlt: Out << "arkpltcc"; break; diff --git a/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td b/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td index 5485ac4c90da1d0b6242294ef40e35aebd688eab..1ace7ab7f19b79ed576171009a58cb9d79c04592 100644 --- a/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td +++ b/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td @@ -355,6 +355,13 @@ def CC_AArch64_ArkFast5 : CallingConv<[ CCIfType<[i64], CCAssignToRegWithShadow<[X0, X1, X2, X3, X4, X28, FP], [W0, W1, W2, W3, W4, W28, W29]>>, ]>; +let Entry = 1 in +def CC_AArch64_ArkFast6 : CallingConv<[ + CCIfType<[i1, i8, i16], CCPromoteToType>, + CCIfType<[i32], CCAssignToRegWithShadow<[W0, W1, W2, W3, W4, W5, W28, W29], [X0, X1, X2, X3, X4, X5, X28, FP]>>, + CCIfType<[i64], CCAssignToRegWithShadow<[X0, X1, X2, X3, X4, X5, X28, FP], [W0, W1, W2, W3, W4, W5, W28, W29]>>, +]>; + let Entry = 1 in def CC_AArch64_ArkResolver : CallingConv<[ CCIfType<[i1, i8, i16], CCPromoteToType>, @@ -504,9 +511,12 @@ def CSR_AArch64_StackProbe_Windows // OHOS_LOCAL begin def CSR_AArch64_ArkInt : CalleeSavedRegs<(add FP)>; -def CSR_AArch64_ArkFast5 - : CalleeSavedRegs<(add (sub (sequence "X%u", 5, 27), X16, X17), LR, +def CSR_AArch64_ArkFast6 + : CalleeSavedRegs<(add (sub (sequence "X%u", 6, 27), X16, X17), LR, (sequence "D%u", 0, 29))>; +def CSR_AArch64_ArkFast5 + : CalleeSavedRegs<(add CSR_AArch64_ArkFast6, X5)>; + def CSR_AArch64_ArkFast4 : CalleeSavedRegs<(add CSR_AArch64_ArkFast5, X4)>; diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.h b/llvm/lib/Target/AArch64/AArch64CallingConvention.h index 90e8be6eeee02a6cab6c72f11c4955bf0b499944..5af6876f85ba8287ab649f3fe62c56067c9a5457 100644 --- a/llvm/lib/Target/AArch64/AArch64CallingConvention.h +++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.h @@ -62,6 +62,9 @@ bool CC_AArch64_ArkFast4(unsigned ValNo, MVT ValVT, MVT LocVT, bool CC_AArch64_ArkFast5(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State); +bool CC_AArch64_ArkFast6(unsigned ValNo, MVT ValVT, MVT LocVT, + CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, + CCState &State); // OHOS_LOCAL end bool CC_AArch64_GHC(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.td b/llvm/lib/Target/AArch64/AArch64CallingConvention.td index 0094ee3e31290bd4f38376d2cda06c74e441a4b3..78e82cb3cc4d3a1d7c949e09d4e7aaa6efb1ceb3 100644 --- a/llvm/lib/Target/AArch64/AArch64CallingConvention.td +++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.td @@ -355,6 +355,13 @@ def CC_AArch64_ArkFast5 : CallingConv<[ CCIfType<[i64], CCAssignToRegWithShadow<[X0, X1, X2, X3, X4, X28, FP], [W0, W1, W2, W3, W4, W28, W29]>>, ]>; +let Entry = 1 in +def CC_AArch64_ArkFast6 : CallingConv<[ + CCIfType<[i1, i8, i16], CCPromoteToType>, + CCIfType<[i32], CCAssignToRegWithShadow<[W0, W1, W2, W3, W4, W5, W28, W29], [X0, X1, X2, X3, X4, X5, X28, FP]>>, + CCIfType<[i64], CCAssignToRegWithShadow<[X0, X1, X2, X3, X4, X5, X28, FP], [W0, W1, W2, W3, W4, W5, W28, W29]>>, +]>; + let Entry = 1 in def CC_AArch64_ArkResolver : CallingConv<[ CCIfType<[i1, i8, i16], CCPromoteToType>, @@ -503,9 +510,12 @@ def CSR_AArch64_StackProbe_Windows // OHOS_LOCAL begin def CSR_AArch64_ArkInt : CalleeSavedRegs<(add FP)>; -def CSR_AArch64_ArkFast5 - : CalleeSavedRegs<(add (sub (sequence "X%u", 5, 27), X16, X17), LR, +def CSR_AArch64_ArkFast6 + : CalleeSavedRegs<(add (sub (sequence "X%u", 6, 27), X16, X17), LR, (sequence "D%u", 0, 29))>; +def CSR_AArch64_ArkFast5 + : CalleeSavedRegs<(add CSR_AArch64_ArkFast6, X5)>; + def CSR_AArch64_ArkFast4 : CalleeSavedRegs<(add CSR_AArch64_ArkFast5, X4)>; diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp index 8856fe0ea5554f1bd17287b66a852da6b0b726fd..43ee70edcd2346fd76e5f85164a8fc163c3d13fa 100644 --- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp @@ -1525,7 +1525,8 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF, MF.getFunction().getCallingConv() == CallingConv::ArkFast2 || MF.getFunction().getCallingConv() == CallingConv::ArkFast3 || MF.getFunction().getCallingConv() == CallingConv::ArkFast4 || - MF.getFunction().getCallingConv() == CallingConv::ArkFast5)) { + MF.getFunction().getCallingConv() == CallingConv::ArkFast5 || + MF.getFunction().getCallingConv() == CallingConv::ArkFast6)) { report_fatal_error( "Implicit use of FP is forbidden for ArkFast conventions!"); } diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index a98f763143feec186b0ff2848b133c14925dea17..d742d87eca22abe737846dd3ce95b3a53d0fef7f 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -5750,6 +5750,8 @@ CCAssignFn *AArch64TargetLowering::CCAssignFnForCall(CallingConv::ID CC, return CC_AArch64_ArkFast4; case CallingConv::ArkFast5: return CC_AArch64_ArkFast5; + case CallingConv::ArkFast6: + return CC_AArch64_ArkFast6; case CallingConv::ArkResolver: return CC_AArch64_ArkResolver; // OHOS_LOCAL end @@ -6269,6 +6271,7 @@ static bool mayTailCallThisCC(CallingConv::ID CC) { case CallingConv::ArkFast3: case CallingConv::ArkFast4: case CallingConv::ArkFast5: + case CallingConv::ArkFast6: // OHOS_LOCAL end return true; default: diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp index 49c45cec1e911469029559c5a30c6f656d14a7b5..abcc0f749e6c15e6097620e847b6f487da9ff7ec 100644 --- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp @@ -89,6 +89,8 @@ AArch64RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { return CSR_AArch64_ArkFast4_SaveList; if (MF->getFunction().getCallingConv() == CallingConv::ArkFast5) return CSR_AArch64_ArkFast5_SaveList; + if (MF->getFunction().getCallingConv() == CallingConv::ArkFast6) + return CSR_AArch64_ArkFast6_SaveList; if (MF->getFunction().getCallingConv() == CallingConv::ArkMethod) return CSR_AArch64_ArkMethod_SaveList; // OHOS_LOCAL end @@ -245,6 +247,8 @@ AArch64RegisterInfo::getCallPreservedMask(const MachineFunction &MF, return CSR_AArch64_ArkFast4_RegMask; if (CC == CallingConv::ArkFast5) return CSR_AArch64_ArkFast5_RegMask; + if (CC == CallingConv::ArkFast6) + return CSR_AArch64_ArkFast6_RegMask; if (CC == CallingConv::ArkMethod) return CSR_AArch64_ArkMethod_RegMask; // OHOS_LOCAL end diff --git a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp index 5c3a2ee63d56d3d90f93063ce7e49faf3b2f6184..ff597e6605b01d46e7d20dc697ba8513c6678f9b 100644 --- a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp @@ -693,6 +693,7 @@ static bool mayTailCallThisCC(CallingConv::ID CC) { case CallingConv::ArkFast3: case CallingConv::ArkFast4: case CallingConv::ArkFast5: + case CallingConv::ArkFast6: // OHOS_LOCAL end return true; default: diff --git a/llvm/lib/Target/X86/X86CallingConv.td b/llvm/lib/Target/X86/X86CallingConv.td index 10f3ed29105f8c1f9e159d7e667c2dd113ef5ca4..43c8e5cd68ae7f69e58f5b05259aeea6b416e65b 100644 --- a/llvm/lib/Target/X86/X86CallingConv.td +++ b/llvm/lib/Target/X86/X86CallingConv.td @@ -505,6 +505,7 @@ def RetCC_X86_64 : CallingConv<[ CCIfCC<"CallingConv::ArkFast3", CCDelegateTo>, CCIfCC<"CallingConv::ArkFast4", CCDelegateTo>, CCIfCC<"CallingConv::ArkFast5", CCDelegateTo>, + CCIfCC<"CallingConv::ArkFast6", CCDelegateTo>, CCIfCC<"CallingConv::ArkMethod", CCDelegateTo>, CCIfCC<"CallingConv::ArkResolver", CCDelegateTo>, // OHOS_LOCAL end @@ -804,6 +805,10 @@ def CC_X86_64_ARK_FAST_5 : CallingConv<[ CCIfType<[i1, i8, i16, i32], CCPromoteToType>, CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8, R15, RBP]>> ]>; +def CC_X86_64_ARK_FAST_6 : CallingConv<[ + CCIfType<[i1, i8, i16, i32], CCPromoteToType>, + CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8, R9, R15, RBP]>> +]>; def CC_X86_64_ARK_RESOLVER : CallingConv<[ CCIfType<[i1, i8, i16, i32], CCPromoteToType>, @@ -1171,6 +1176,7 @@ def CC_X86_64 : CallingConv<[ CCIfCC<"CallingConv::ArkFast3", CCDelegateTo>, CCIfCC<"CallingConv::ArkFast4", CCDelegateTo>, CCIfCC<"CallingConv::ArkFast5", CCDelegateTo>, + CCIfCC<"CallingConv::ArkFast6", CCDelegateTo>, CCIfCC<"CallingConv::ArkMethod", CCDelegateTo>, CCIfCC<"CallingConv::ArkResolver", CCDelegateTo>, // OHOS_LOCAL end @@ -1306,9 +1312,9 @@ def CSR_ArkFast2 : CalleeSavedRegs<(sub CSR_ArkFast1, RSI)>; def CSR_ArkFast3 : CalleeSavedRegs<(sub CSR_ArkFast2, RDX)>; def CSR_ArkFast4 : CalleeSavedRegs<(sub CSR_ArkFast3, RCX)>; def CSR_ArkFast5 : CalleeSavedRegs<(sub CSR_ArkFast4, R8)>; +def CSR_ArkFast6 : CalleeSavedRegs<(sub CSR_ArkFast5, R9)>; def CSR_ArkMethod : CalleeSavedRegs<(add RBP)>; -// R12, R13, R14 may be used as temp registers. But we tight only really used temps. -def CSR_ArkResolver : CalleeSavedRegs<(sub CSR_64, R12, R13)>; -def CSR_ArkPlt : CalleeSavedRegs<(sub CSR_64, R12)>; +def CSR_ArkResolver : CalleeSavedRegs<(sub CSR_64, R12, R13, R14)>; +def CSR_ArkPlt : CalleeSavedRegs<(sub CSR_64, R12, R13, R14)>; // OHOS_LOCAL end diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 72eb76ae021203167e81ea08c3537d78f10310bf..3f8336b2590046f733ef3dbee4aa3c0f8f2343d2 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -3618,6 +3618,7 @@ static bool mayTailCallThisCC(CallingConv::ID CC) { case CallingConv::ArkFast3: case CallingConv::ArkFast4: case CallingConv::ArkFast5: + case CallingConv::ArkFast6: return true; // OHOS_LOCAL end default: diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp index f6f92bddeff6f9cc50f0c3b7df6ed198cd8a8484..6b0738266b62c2c1dd91023db245215b9a922fcb 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.cpp +++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp @@ -313,6 +313,8 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { return CSR_ArkFast4_SaveList; case CallingConv::ArkFast5: return CSR_ArkFast5_SaveList; + case CallingConv::ArkFast6: + return CSR_ArkFast6_SaveList; case CallingConv::ArkMethod: return CSR_ArkMethod_SaveList; case CallingConv::ArkResolver: @@ -458,6 +460,8 @@ X86RegisterInfo::getCallPreservedMask(const MachineFunction &MF, return CSR_ArkFast4_RegMask; case CallingConv::ArkFast5: return CSR_ArkFast5_RegMask; + case CallingConv::ArkFast6: + return CSR_ArkFast6_RegMask; case CallingConv::ArkMethod: return CSR_ArkMethod_RegMask; case CallingConv::ArkResolver: diff --git a/llvm/test/CodeGen/AArch64/implicit-null-check.ll b/llvm/test/CodeGen/AArch64/implicit-null-check.ll index 59bbfda757c8d8038de7dc7b8c09184cb57b5b91..5ed33a622439c607c33226c7f686663c4b1f1fec 100644 --- a/llvm/test/CodeGen/AArch64/implicit-null-check.ll +++ b/llvm/test/CodeGen/AArch64/implicit-null-check.ll @@ -436,12 +436,12 @@ define i32 @imp_null_check_neg_gep_load(i32* %x) { ;; The test must be fixed, when such is introduced define i64 @imp_null_check_load_pair(i64* %array) { ; CHECK-LABEL: imp_null_check_load_pair: -; CHECK: // %bb.0: // %entry -; CHECK-NEXT: cbz x0, .LBB17_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldp x8, x9, [x0] -; CHECK-NEXT: add x0, x9, x8 -; CHECK-NEXT: .LBB17_2: // %return +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: cbz x0, .LBB17_2 +; CHECK-NEXT: // %bb.1: // %if.end +; CHECK-NEXT: ldp x8, x9, [x0] +; CHECK-NEXT: add x0, x9, x8 +; CHECK-NEXT: .LBB17_2: // %return ; CHECK-NEXT: ret entry: %cmp = icmp eq i64* %array, null diff --git a/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll b/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll index dcecc92d5b7085fd27adf7840b2ecbe2adae84b1..fc15558caccc7844bfe53219411ab39affd802b3 100644 --- a/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll +++ b/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll @@ -3,18 +3,15 @@ target triple = "aarch64-unknown-linux-gnu" ; CHECK-LABEL: LoadI32FromPtr32: -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: -; CHECK-NEXT: str x30, [sp, #-16]! -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp0: -; CHECK-NEXT: ldr w0, [x0, #16] -; CHECK-NEXT: // %bb.1: -; CHECK-NEXT: ldr x30, [sp], #16 -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB0_2: -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp0: +; CHECK-NEXT: ldr w0, [x0, #16] // on-fault: .LBB0_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB0_2: +; CHECK-NEXT: bl ThrowNullPointerException define i32 @LoadI32FromPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -32,18 +29,15 @@ if.end: } ; CHECK-LABEL: LoadFloatFromPtr32: -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: -; CHECK-NEXT: str x30, [sp, #-16]! -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp1: -; CHECK-NEXT: ldr s0, [x0, #16] +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp1: +; CHECK-NEXT: ldr s0, [x0, #16] // on-fault: .LBB1_2 ; CHECK-NEXT: // %bb.1: -; CHECK-NEXT: ldr x30, [sp], #16 -; CHECK-NEXT: ret +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret ; CHECK-NEXT: .LBB1_2: -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-NEXT: bl ThrowNullPointerException define float @LoadFloatFromPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -61,18 +55,15 @@ if.end: ; preds = %entry } ; CHECK-LABEL: LoadDoubleFromPtr32: -; CHECK: .cfi_startproc -; CHECK: // %bb.0: // %entry -; CHECK: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK: .cfi_def_cfa_offset 16 -; CHECK: .cfi_offset w30, -16 +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! ; CHECK: .Ltmp2: -; CHECK: ldr d0, [x0, #64] // on-fault: .LBB2_2 -; CHECK: // %bb.1: // %if.end -; CHECK: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK: ret -; CHECK: .LBB2_2: // %if.then -; CHECK: bl ThrowNullPointerException +; CHECK-NEXT: ldr d0, [x0, #64] // on-fault: .LBB2_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB2_2: +; CHECK-NEXT: bl ThrowNullPointerException define double @LoadDoubleFromPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -89,19 +80,16 @@ if.end: ret double %1 } -; CHECK-LABEL: LoadPtr32FromPtr32: // @LoadPtr32FromPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp3: -; CHECK-NEXT: ldr w0, [x0, #16] // on-fault: .LBB3_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB3_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: LoadPtr32FromPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp3: +; CHECK-NEXT: ldr w0, [x0, #16] // on-fault: .LBB3_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB3_2: +; CHECK-NEXT: bl ThrowNullPointerException define ptr addrspace(271) @LoadPtr32FromPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -118,19 +106,16 @@ if.end: ; preds = %entry ret ptr addrspace(271) %1 } -; CHECK-LABEL: StoreI32ToPtr32: // @StoreI32ToPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp4: -; CHECK-NEXT: str w1, [x0, #32] // on-fault: .LBB4_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB4_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: StoreI32ToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp4: +; CHECK-NEXT: str w1, [x0, #32] // on-fault: .LBB4_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB4_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StoreI32ToPtr32(ptr addrspace(271) %object, i32 %value) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -147,19 +132,16 @@ if.end: ; preds = %entry ret void } -; CHECK-LABEL: StoreFloatToPtr32: // @StoreFloatToPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp5: -; CHECK-NEXT: str s0, [x0, #32] // on-fault: .LBB5_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB5_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: StoreFloatToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp5: +; CHECK-NEXT: str s0, [x0, #32] // on-fault: .LBB5_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB5_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StoreFloatToPtr32(ptr addrspace(271) %object, float %value) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -176,19 +158,16 @@ if.end: ; preds = %entry ret void } -; CHECK-LABEL: StoreDoubleToPtr32: // @StoreDoubleToPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp6: -; CHECK-NEXT: str d0, [x0, #32] // on-fault: .LBB6_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB6_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: StoreDoubleToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp6: +; CHECK-NEXT: str d0, [x0, #32] // on-fault: .LBB6_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB6_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StoreDoubleToPtr32(ptr addrspace(271) %object, double %value) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -208,24 +187,20 @@ if.end: ; preds = %entry ; Note LLVM does not support this case because ImplicitNullChecks does not hoist ; str x8, [x0, #32] above the moves to x8 because of the dependency on x8 ; The test should be enabled when such support is introduced -; StoreConstantDoubleToPtr32: // @StoreConstantDoubleToPtr32 -; // %bb.0: // %entry -; str x30, [sp, #-16]! // 8-byte Folded Spill -; cbz x0, .LBB7_2 -; // %bb.1: // %if.end -; mov x8, #55370 -; movk x8, #19730, lsl #16 -; movk x8, #8699, lsl #32 -; movk x8, #16393, lsl #48 -; str x8, [x0, #32] -; ldr x30, [sp], #16 // 8-byte Folded Reload -; ret -; .LBB7_2: // %if.then -; bl ThrowNullPointerException - -; COM: CHECK-LABEL: StoreConstantDoubleToPtr32: // @StoreConstantDoubleToPtr32 -; COM: CHECK-NOT: cbz x0, {{.*}} -; COM: CHECK: ret +; CHECK-LABEL: StoreConstantDoubleToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: cbz x0, .LBB7_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: mov x8, #55370 +; CHECK-NEXT: movk x8, #19730, lsl #16 +; CHECK-NEXT: movk x8, #8699, lsl #32 +; CHECK-NEXT: movk x8, #16393, lsl #48 +; CHECK-NEXT: str x8, [x0, #32] +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB7_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StoreConstantDoubleToPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -242,19 +217,16 @@ if.end: ; preds = %entry ret void } -; CHECK-LABEL: StorePtr32ToPtr32: // @StorePtr32ToPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp7: -; CHECK-NEXT: str w1, [x0, #32] // on-fault: .LBB8_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB8_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: StorePtr32ToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp7: +; CHECK-NEXT: str w1, [x0, #32] // on-fault: .LBB8_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB8_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StorePtr32ToPtr32(ptr addrspace(271) %object, ptr addrspace(271) %value) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index c9a239f785d2ebceeb33208d8eddf52032dae619..99aa24b6e6c564d8c17201864da1ac0c1921eb58 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -29,6 +29,8 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" +// OHOS_LOCAL +#include "llvm/BinaryFormat/ADLTSection.h" #include "llvm/BinaryFormat/AMDGPUMetadataVerifier.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/BinaryFormat/MsgPackDocument.h" @@ -353,6 +355,8 @@ protected: void loadDynamicTable(); void parseDynamicTable(); + Expected> findAdlt(); // OHOS_LOCAL + Expected getSymbolVersion(const Elf_Sym &Sym, bool &IsDefault) const; Expected, 0> *> getVersionMap() const; @@ -365,11 +369,16 @@ protected: DynRegionInfo DynSymTabShndxRegion; DynRegionInfo DynamicTable; StringRef DynamicStringTable; + StringRef AdltStringTable; // OHOS_LOCAL const Elf_Hash *HashTable = nullptr; const Elf_GnuHash *GnuHashTable = nullptr; const Elf_Shdr *DotSymtabSec = nullptr; const Elf_Shdr *DotDynsymSec = nullptr; const Elf_Shdr *DotAddrsigSec = nullptr; + // OHOS_LOCAL begin + const Elf_Shdr *DotAdlt = nullptr; + const Elf_Shdr *DotAdltStrtab = nullptr; + // OHOS_LOCAL end DenseMap> ShndxTables; Optional SONameOffset; Optional>> AddressToIndexMap; @@ -388,7 +397,11 @@ protected: Expected getSymbolSectionName(const Elf_Sym &Symbol, unsigned SectionIndex) const; std::string getStaticSymbolName(uint32_t Index) const; + // OHOS_LOCAL + StringRef getDynamicString(uint64_t Value, StringRef StringTable) const; StringRef getDynamicString(uint64_t Value) const; + // OHOS_LOCAL + StringRef getAdltDynamicString(uint64_t Value) const; void printSymbolsHelper(bool IsDynamic) const; std::string getDynamicEntry(uint64_t Type, uint64_t Value) const; @@ -572,6 +585,7 @@ public: void printVersionDefinitionSection(const Elf_Shdr *Sec) override; void printVersionDependencySection(const Elf_Shdr *Sec) override; void printHashHistograms() override; + void printAdltSection() override; // OHOS_LOCAL void printCGProfile() override; void printBBAddrMaps() override; void printAddrsig() override; @@ -676,6 +690,7 @@ public: void printVersionDefinitionSection(const Elf_Shdr *Sec) override; void printVersionDependencySection(const Elf_Shdr *Sec) override; void printHashHistograms() override; + void printAdltSection() override; // OHOS_LOCAL void printCGProfile() override; void printBBAddrMaps() override; void printAddrsig() override; @@ -1416,6 +1431,7 @@ static StringRef segmentTypeToString(unsigned Arch, unsigned Type) { LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_BOOTDATA); LLVM_READOBJ_ENUM_CASE(ELF, PT_OHOS_RANDOMDATA); // OHOS_LOCAL + LLVM_READOBJ_ENUM_CASE(ELF, PT_ADLT); // OHOS_LOCAL ADLT info default: return ""; } @@ -1705,6 +1721,48 @@ static const char *getElfMipsOptionsOdkType(unsigned Odk) { } } +// OHOS_LOCAL begin +const EnumEntry AdltHashTypes[] = { + {"None", "NONE", llvm::adlt::ADLT_HASH_TYPE_NONE}, + {"GnuHash", "GNU_HASH", llvm::adlt::ADLT_HASH_TYPE_GNU_HASH}, + {"SysvHash", "SYSV_HASH", llvm::adlt::ADLT_HASH_TYPE_SYSV_HASH}, + {"Debug", "DEBUG", llvm::adlt::ADLT_HASH_TYPE_DEBUG_CONST}, +}; + +template +Expected> ELFDumper::findAdlt() { + // Try to locate .adlt section in the sections table + typename ELFT::ShdrRange Sections = cantFail(Obj.sections()); + for (const Elf_Shdr &Sec : Sections) { + if (DotAdlt && DotAdltStrtab) + break; + + switch (Sec.sh_type) { + case ELF::SHT_STRTAB: + if (!DotAdltStrtab && getPrintableSectionName(Sec) == ".adlt.strtab") + DotAdltStrtab = &Sec; + break; + case ELF::SHT_PROGBITS: + if (!DotAdlt && getPrintableSectionName(Sec) == ".adlt") + DotAdlt = &Sec; + break; + } + } + + if (!DotAdlt) + return createError(".adlt section not found"); + if (!DotAdltStrtab) + return createError("has .adlt but .adlt.strtab section not found"); + + Expected StrTabOrErr = Obj.getStringTable(*DotAdltStrtab); + if (!StrTabOrErr) + return StrTabOrErr.takeError(); + AdltStringTable = *StrTabOrErr; + + return Obj.getSectionContents(*DotAdlt); +} +// OHOS_LOCAL end + template std::pair ELFDumper::findDynamic() { @@ -2399,6 +2457,20 @@ std::string ELFDumper::getDynamicEntry(uint64_t Type, template StringRef ELFDumper::getDynamicString(uint64_t Value) const { + // OHOS_LOCAL + return this->getDynamicString(Value, DynamicStringTable); +} + +// OHOS_LOCAL begin +template +StringRef ELFDumper::getAdltDynamicString(uint64_t Value) const { + return this->getDynamicString(Value, AdltStringTable); +} + +template +StringRef +ELFDumper::getDynamicString(uint64_t Value, + StringRef DynamicStringTable) const { if (DynamicStringTable.empty() && !DynamicStringTable.data()) { reportUniqueWarning("string table was not found"); return ""; @@ -2435,6 +2507,7 @@ StringRef ELFDumper::getDynamicString(uint64_t Value) const { return DynamicStringTable.data() + Value; } +// OHOS_LOCAL end template void ELFDumper::printUnwindInfo() { DwarfCFIEH::PrinterContext Ctx(W, ObjF); @@ -4822,6 +4895,12 @@ template void GNUELFDumper::printHashHistograms() { } } +// OHOS_LOCAL begin +template void GNUELFDumper::printAdltSection() { + OS << "GNUStyle::printAdltSection not implemented\n"; +} +// OHOS_LOCAL end + template void GNUELFDumper::printCGProfile() { OS << "GNUStyle::printCGProfile not implemented\n"; } @@ -6954,6 +7033,205 @@ template void LLVMELFDumper::printHashHistograms() { W.startLine() << "Hash Histogram not implemented!\n"; } +// OHOS_LOCAL begin +template void LLVMELFDumper::printAdltSection() { + using namespace llvm::adlt; + constexpr size_t kBinDumpLimit = sizeof(Elf64_Xword) * 0x80; + + Expected> ContentsOrErr = this->findAdlt(); + if (!ContentsOrErr) { + return this->reportUniqueWarning(ContentsOrErr.takeError()); + } + + ArrayRef adltRaw = ContentsOrErr.get(); + auto *header = + reinterpret_cast(adltRaw.data()); + const auto &ver = header->schemaVersion; + + ArrayRef psodsRaw; + ArrayRef blob; + + if (psodsRaw.data() + psodsRaw.size() > blob.data()) + return this->reportUniqueWarning("invalid .adlt section: " + "PSOD and blob entries are overlapped"); + if (blob.data() + blob.size() > adltRaw.data() + adltRaw.size()) + return this->reportUniqueWarning("invalid .adlt section: " + "blob is out of section range"); + + DictScope DSec(W, "ADLT"); + + do { + DictScope DHeader(W, "Header"); + W.printVersion("schema-version", ver.major, ver.minor, ver.patch); + + if (ver.major > 1) { + this->reportUniqueWarning(Twine("schema version not supported yet")); + return; + } + + W.printHex("schema-header-size", header->schemaHeaderSize); + W.printHex("schema-psod-size", header->schemaPSODSize); + W.printNumber("shared-objects-num", header->sharedObjectsNum); + W.printEnum("string-hash-type", header->stringHashType, + makeArrayRef(AdltHashTypes)); + W.printHex("blob-start", header->blobStart); + W.printHex("blob-size", header->blobSize); + W.printHex("overall-mapped-size", header->overallMappedSize); + + psodsRaw = adltRaw.slice(header->schemaHeaderSize, + header->sharedObjectsNum * header->schemaPSODSize); + blob = adltRaw.slice(header->blobStart, header->blobSize); + + if (psodsRaw.data() + psodsRaw.size() > blob.data()) + return this->reportUniqueWarning("invalid .adlt section: " + "PSOD and blob entries are overlapped"); + if (blob.data() + blob.size() > adltRaw.data() + adltRaw.size()) + return this->reportUniqueWarning("invalid .adlt section: " + "blob is out of section range"); + + if (ver.minor >= 1) { + DictScope PHEntry(W, "ph-indexes"); + const auto &arr = header->phIndexes; + W.printHex("size", arr.size); + W.printHex("offset", arr.offset); + + const auto chunk = blob.slice(arr.offset, arr.size); + if (!chunk.empty()) { + W.printBinary("raw", chunk); + ArrayRef phIdxs( + reinterpret_cast(chunk.data()), + chunk.size() / sizeof(uint16_t)); + W.printList("values", phIdxs); + } + } + } while (0); + + { + ListScope LPsods(W, "PSODs"); + + for (size_t psodIdx = 0; psodIdx < header->sharedObjectsNum; ++psodIdx) { + const adlt_psod_t &psod = *reinterpret_cast( + psodsRaw.data() + psodIdx * header->schemaPSODSize); + + auto psodName = Twine("psod-#") + Twine(psodIdx); + DictScope LEntry(W, psodName.str()); + + { + DictScope MetaEntry(W, "$-meta"); + auto psodSuffix = Twine("__") + Twine::utohexstr(psodIdx); + W.printNumber("$-order", psodIdx); + W.printString("$-symbol-suffix", psodSuffix.str()); + } + + W.printString("soname", this->getAdltDynamicString(psod.soName)); + W.printHex("soname-hash", psod.soNameHash); + { + DictScope IAEntry(W, "init-array"); + W.printHex("size", psod.initArray.size); + W.printNumber("sec-index", psod.initArray.secIndex); + W.printHex("offset", psod.initArray.offset); + } + { + DictScope IAEntry(W, "fini-array"); + W.printHex("size", psod.finiArray.size); + W.printNumber("sec-index", psod.finiArray.secIndex); + W.printHex("offset", psod.finiArray.offset); + } + { + DictScope DNEntry(W, "dt-needed"); + const auto &arr = psod.dtNeeded; + W.printHex("size", arr.size); + W.printHex("offset", arr.offset); + + const auto chunk = blob.slice(arr.offset, arr.size); + if (!chunk.empty()) { + W.printBinary("raw", chunk); + + ArrayRef deps( + reinterpret_cast(chunk.data()), + chunk.size() / sizeof(adlt_dt_needed_index_t)); + + ListScope NeedList(W, "needed-libs"); + for (const auto &need : deps) { + DictScope DepEntry(W, + this->getAdltDynamicString(need.sonameOffset)); + W.printBoolean("is-internal", need.hasInternalPSOD); + if (need.hasInternalPSOD) + W.printNumber("psod-id", need.PSODindex); + } + } + } + { + DictScope SLEntry(W, "shared-local-symbol"); + const auto &csref = psod.sharedLocalSymbolIndex; + W.printNumber("sec-index", csref.secIndex); + W.printHex("offset", csref.offset); + } + { + DictScope SGEntry(W, "shared-global-symbol"); + const auto &csref = psod.sharedGlobalSymbolIndex; + W.printNumber("sec-index", csref.secIndex); + W.printHex("offset", csref.offset); + } + { + DictScope PHEntry(W, "ph-indexes"); + const auto &arr = psod.phIndexes; + W.printHex("size", arr.size); + W.printHex("offset", arr.offset); + + const auto chunk = blob.slice(arr.offset, arr.size); + if (!chunk.empty()) { + W.printBinary("raw", chunk); + ArrayRef phIdxs( + reinterpret_cast(chunk.data()), + chunk.size() / sizeof(uint16_t)); + W.printList("values", phIdxs); + } + } + { + DictScope RDEntry(W, "rela-dyn-idxs"); + const auto &arr = psod.relaDynIndx; + W.printHex("size", arr.size); + W.printHex("offset", arr.offset); + + const auto chunk = blob.slice(arr.offset, arr.size); + if (!chunk.empty()) { + if (chunk.size() > kBinDumpLimit) + W.printString("raw", ""); + else + W.printBinary("raw", chunk); + } + } + { + DictScope RPEntry(W, "rela-plt-idsx"); + const auto &arr = psod.relaPltIndx; + W.printHex("size", arr.size); + W.printHex("offset", arr.offset); + + const auto chunk = blob.slice(arr.offset, arr.size); + if (!chunk.empty()) { + if (chunk.size() > kBinDumpLimit) + W.printString("raw", ""); + else + W.printBinary("raw", chunk); + } + } + } + } + + { + DictScope DBlob(W, "Blob"); + W.printHex("start", header->blobStart); + W.printHex("size", header->blobSize); + + if (blob.size() > kBinDumpLimit * 50) + W.printString("raw", ""); + else + W.printBinaryBlock("raw", blob); + } +} +// OHOS_LOCAL end + // Returns true if rel/rela section exists, and populates SymbolIndices. // Otherwise returns false. template diff --git a/llvm/tools/llvm-readobj/ObjDumper.h b/llvm/tools/llvm-readobj/ObjDumper.h index 292efd2ae350a77cda3cc50fb0c1a7d1c6201f28..bad21cc732b21e0542f1b0bdd6fa9af549380dbd 100644 --- a/llvm/tools/llvm-readobj/ObjDumper.h +++ b/llvm/tools/llvm-readobj/ObjDumper.h @@ -129,6 +129,7 @@ public: virtual void printVersionInfo() {} virtual void printGroupSections() {} virtual void printHashHistograms() {} + virtual void printAdltSection() {} // OHOS_LOCAL virtual void printCGProfile() {} virtual void printBBAddrMaps() {} virtual void printAddrsig() {} diff --git a/llvm/tools/llvm-readobj/Opts.td b/llvm/tools/llvm-readobj/Opts.td index 4687fc71245f8478e6f0f25b3fa2e5dcc16b3b77..2abd661af548b7c91f49d1b86bace658ac139594 100644 --- a/llvm/tools/llvm-readobj/Opts.td +++ b/llvm/tools/llvm-readobj/Opts.td @@ -55,6 +55,8 @@ def section_groups : FF<"section-groups", "Display section groups">, Group, Group; def hash_symbols : FF<"hash-symbols", "Display the dynamic symbols derived from the hash section">, Group; def hash_table : FF<"hash-table", "Display .hash section">, Group; +// OHOS_LOCAL +def adlt_section: FF<"adlt-section", "Display .adlt section in a pretty format">, Group; def needed_libs : FF<"needed-libs", "Display the needed libraries">, Group; def notes : FF<"notes", "Display notes">, Group; def program_headers : FF<"program-headers", "Display program headers">, Group; diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp index e1ebbeb41f28b02e31ef3f28fbdfed6e687cff01..b4c1d7dd94b7953bfaf24f3f73b48ef146a51171 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -125,6 +125,7 @@ static cl::boolOrDefault SectionMapping; static SmallVector SortKeys; // ELF specific options. +static bool AdltSection; // OHOS_LOCAL static bool DynamicTable; static bool ELFLinkerOptions; static bool GnuHashTable; @@ -253,6 +254,8 @@ static void parseOptions(const opt::InputArgList &Args) { OutputStyleChoice + "'"); } } + // OHOS_LOCAL + opts::AdltSection = Args.hasArg(OPT_adlt_section); opts::GnuHashTable = Args.hasArg(OPT_gnu_hash_table); opts::HashSymbols = Args.hasArg(OPT_hash_symbols); opts::HashTable = Args.hasArg(OPT_hash_table); @@ -449,6 +452,10 @@ static void dumpObject(ObjectFile &Obj, ScopedPrinter &Writer, Dumper->printGroupSections(); if (opts::HashHistogram) Dumper->printHashHistograms(); + // OHOS_LOCAL begin + if (opts::AdltSection) + Dumper->printAdltSection(); + // OHOS_LOCAL end if (opts::CGProfile) Dumper->printCGProfile(); if (opts::BBAddrMap) diff --git a/llvm/utils/emacs/llvm-mode.el b/llvm/utils/emacs/llvm-mode.el index c4def25469f21f5f6b81d6b63120868cc0082b94..2b335ac76fdb7146c0350875f36f5be599258f62 100644 --- a/llvm/utils/emacs/llvm-mode.el +++ b/llvm/utils/emacs/llvm-mode.el @@ -59,7 +59,7 @@ "ccc" "fastcc" "coldcc" "webkit_jscc" "anyregcc" "preserve_mostcc" "preserve_allcc" ;; OHOS_LOCAL begin "cxx_fast_tlscc" "swiftcc" "tailcc" "swifttailcc" "cfguard_checkcc" "arkintcc" - "arkfast0cc" "arkfast1cc" "arkfast2cc" "arkfast3cc" "arkfast4cc" "arkfast5cc" + "arkfast0cc" "arkfast1cc" "arkfast2cc" "arkfast3cc" "arkfast4cc" "arkfast5cc" "arkfast6cc" "arkmethodcc" "arkresolvercc" "arkpltcc" ;; OHOS_LOCAL end ;; Visibility styles diff --git a/llvm/utils/vim/syntax/llvm.vim b/llvm/utils/vim/syntax/llvm.vim index 5b333a8b5bbc4542391aea419473969613706201..a2f58f8b472eb582a0a1d9c8630e4c2115433930 100644 --- a/llvm/utils/vim/syntax/llvm.vim +++ b/llvm/utils/vim/syntax/llvm.vim @@ -55,6 +55,7 @@ syn keyword llvmKeyword \ arkfast3cc \ arkfast4cc \ arkfast5cc + \ arkfast6cc \ arkintccx \ arkmethodcc \ arkpltcc