From 7f8878bb02eaaae89cbf0dabba15888f8c4add98 Mon Sep 17 00:00:00 2001 From: Nikolai Kholiavin Date: Sat, 30 Mar 2024 01:07:09 +0000 Subject: [PATCH 01/13] [IR] Check for implicit 0 from Min module flag behavior in requirements This fixes combination of Min IR module flag behavior and a module flag requirement to work in the case where the flag is missing in one of the modules. Previously this caused the requirement check to erroneously succeed in IRLinker, but verifier would catch the problem and crash. Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I9LG51 Signed-off-by: Nikolai Kholiavin --- llvm/lib/Linker/IRMover.cpp | 4 +++- .../Linker/module-flags-min-0-required.ll | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Linker/module-flags-min-0-required.ll diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index e31faf6422ed..ab960e021d4d 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -1487,7 +1487,9 @@ Error IRLinker::linkModuleFlagsMetadata() { Metadata *FlagOps[] = { Op->getOperand(0), ID, ConstantAsMetadata::get(ConstantInt::get(V->getType(), 0))}; - DstModFlags->setOperand(Idx, MDNode::get(DstM.getContext(), FlagOps)); + MDNode *Flag = MDNode::get(DstM.getContext(), FlagOps); + DstModFlags->setOperand(Idx, Flag); + Flags[ID].first = Flag; } } diff --git a/llvm/test/Linker/module-flags-min-0-required.ll b/llvm/test/Linker/module-flags-min-0-required.ll new file mode 100644 index 000000000000..b8c9406be2a7 --- /dev/null +++ b/llvm/test/Linker/module-flags-min-0-required.ll @@ -0,0 +1,20 @@ +; RUN: rm -rf %t && split-file %s %t && cd %t +; RUN: not llvm-link a.ll b.ll -S -o - 2>&1 | FileCheck %s + +; CHECK: error: linking module flags 'required_in_b': does not have the required value + +;--- a.ll +!0 = !{ i32 8, !"foo", i16 2 } +!1 = !{ i32 8, !"bar", i64 4 } +!2 = !{ i32 8, !"only_in_a", i32 4 } + +!llvm.module.flags = !{ !0, !1, !2 } + +;--- b.ll +!0 = !{ i32 8, !"foo", i16 3 } +!1 = !{ i32 8, !"bar", i64 3 } +!2 = !{ i32 8, !"only_in_b", i32 3 } +!3 = !{ i32 8, !"required_in_b", i32 3 } +!4 = !{ i32 3, !"require", !{!"required_in_b", i32 3} } + +!llvm.module.flags = !{ !0, !1, !2, !3, !4 } -- Gitee From c13eb3b50980712bcb374a8fe48bfaaf9c2c18e8 Mon Sep 17 00:00:00 2001 From: Nikolai Kholiavin Date: Sat, 30 Mar 2024 01:11:58 +0000 Subject: [PATCH 02/13] [CFI][clang][Driver][CodeGen] Introduce option to catch mixed CFI code Introduce an option to check that all of the IR modules participating in the IR link have cross-DSO CFI enabled. Option should be specified to the compilation stage, and will fail the link stage if: - all of the CFI-enabled modules were compiled with -fsanitize-cfi-cross-dso-req clang option - at least one of the IR modules was generated with -fsanitize-cfi-cross-dso -fsanitize-cfi-cross-dso-req clang options - at least one of the IR modules was generated without cross-DSO CFI. Note that this doesn't catch CFI/cross-DSO CFI or non-LTO/any CFI code mixes. Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I9LG51 Signed-off-by: Nikolai Kholiavin --- clang/docs/ClangCommandLineReference.rst | 4 ++ clang/include/clang/Basic/CodeGenOptions.def | 1 + clang/include/clang/Driver/Options.td | 5 ++ clang/include/clang/Driver/SanitizerArgs.h | 1 + clang/lib/CodeGen/CodeGenModule.cpp | 14 +++++- clang/lib/Driver/SanitizerArgs.cpp | 8 ++++ clang/test/CodeGen/cfi-cross-dso-req.c | 13 ++++++ compiler-rt/test/cfi/cross-dso/required.cpp | 48 ++++++++++++++++++++ 8 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGen/cfi-cross-dso-req.c create mode 100644 compiler-rt/test/cfi/cross-dso/required.cpp diff --git a/clang/docs/ClangCommandLineReference.rst b/clang/docs/ClangCommandLineReference.rst index 41fb8f7259eb..d82f716fbafe 100644 --- a/clang/docs/ClangCommandLineReference.rst +++ b/clang/docs/ClangCommandLineReference.rst @@ -999,6 +999,10 @@ Make the jump table addresses canonical in the symbol table Enable control flow integrity (CFI) checks for cross-DSO calls. +.. option:: -fsanitize-cfi-cross-dso-req, -fno-sanitize-cfi-cross-dso-req + +Enable the requirement for cross-DSO control flow integrity (CFI) checks for all LTO modules. + .. option:: -fsanitize-cfi-icall-generalize-pointers Generalize pointers in CFI indirect call type signature checks diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 5d4aec842db3..eb136624bb34 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -253,6 +253,7 @@ CODEGENOPT(SanitizeMemoryParamRetval, 1, 0) ///< Enable detection of uninitializ CODEGENOPT(SanitizeMemoryUseAfterDtor, 1, 0) ///< Enable use-after-delete detection ///< in MemorySanitizer CODEGENOPT(SanitizeCfiCrossDso, 1, 0) ///< Enable cross-dso support in CFI. +CODEGENOPT(SanitizeCfiCrossDsoReq, 1, 0) ///< Require cross-dso CFI support in all modules. CODEGENOPT(SanitizeMinimalRuntime, 1, 0) ///< Use "_minimal" sanitizer runtime for ///< diagnostics. CODEGENOPT(SanitizeCfiICallGeneralizePointers, 1, 0) ///< Generalize pointer types in diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 97433f169d14..b6a1636aa84a 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1822,6 +1822,11 @@ defm sanitize_cfi_cross_dso : BoolOption<"f", "sanitize-cfi-cross-dso", PosFlag, NegFlag, BothFlags<[], " control flow integrity (CFI) checks for cross-DSO calls.">>, Group; +defm sanitize_cfi_cross_dso_req : BoolOption<"f", "sanitize-cfi-cross-dso-req", + CodeGenOpts<"SanitizeCfiCrossDsoReq">, DefaultFalse, + PosFlag, NegFlag, + BothFlags<[], " the requirement for cross-DSO control flow integrity (CFI) checks for all LTO modules.">>, + Group; def fsanitize_cfi_icall_generalize_pointers : Flag<["-"], "fsanitize-cfi-icall-generalize-pointers">, Group, HelpText<"Generalize pointers in CFI indirect call type signature checks">, diff --git a/clang/include/clang/Driver/SanitizerArgs.h b/clang/include/clang/Driver/SanitizerArgs.h index 1b29b1151224..18d0a9892e8e 100644 --- a/clang/include/clang/Driver/SanitizerArgs.h +++ b/clang/include/clang/Driver/SanitizerArgs.h @@ -35,6 +35,7 @@ class SanitizerArgs { bool MsanUseAfterDtor = true; bool MsanParamRetval = false; bool CfiCrossDso = false; + bool CfiCrossDsoReq = false; bool CfiICallGeneralizePointers = false; bool CfiCanonicalJumpTables = false; int AsanFieldPadding = 0; diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index a6144180f9c9..e9635356e26f 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -741,7 +741,19 @@ void CodeGenModule::Release() { if (CodeGenOpts.SanitizeCfiCrossDso) { // Indicate that we want cross-DSO control flow integrity checks. - getModule().addModuleFlag(llvm::Module::Override, "Cross-DSO CFI", 1); + if (CodeGenOpts.SanitizeCfiCrossDsoReq) { + getModule().addModuleFlag(llvm::Module::Min, "Cross-DSO CFI", 1); + + llvm::Metadata *Ops[2] = { + llvm::MDString::get(VMContext, "Cross-DSO CFI"), + llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( + llvm::Type::getInt32Ty(VMContext), 1))}; + getModule().addModuleFlag(llvm::Module::Require, + "Cross-DSO CFI Requirement", + llvm::MDNode::get(VMContext, Ops)); + } else { + getModule().addModuleFlag(llvm::Module::Override, "Cross-DSO CFI", 1); + } } if (CodeGenOpts.WholeProgramVTables) { diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index 20c93c03a4c0..d52afc636445 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -699,6 +699,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, // Without PIE, external function address may resolve to a PLT record, which // can not be verified by the target module. NeedPIE |= CfiCrossDso; + + CfiCrossDsoReq = + Args.hasFlag(options::OPT_fsanitize_cfi_cross_dso_req, + options::OPT_fno_sanitize_cfi_cross_dso_req, false); + CfiICallGeneralizePointers = Args.hasArg(options::OPT_fsanitize_cfi_icall_generalize_pointers); @@ -1161,6 +1166,9 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, if (CfiCrossDso) CmdArgs.push_back("-fsanitize-cfi-cross-dso"); + if (CfiCrossDsoReq) + CmdArgs.push_back("-fsanitize-cfi-cross-dso-req"); + if (CfiICallGeneralizePointers) CmdArgs.push_back("-fsanitize-cfi-icall-generalize-pointers"); diff --git a/clang/test/CodeGen/cfi-cross-dso-req.c b/clang/test/CodeGen/cfi-cross-dso-req.c new file mode 100644 index 000000000000..42be04605765 --- /dev/null +++ b/clang/test/CodeGen/cfi-cross-dso-req.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \ +// RUN: -fsanitize=cfi-icall,cfi-nvcall,cfi-vcall,cfi-unrelated-cast,cfi-derived-cast \ +// RUN: -fsanitize-trap=cfi-icall,cfi-nvcall -fsanitize-recover=cfi-vcall,cfi-unrelated-cast \ +// RUN: -fsanitize-cfi-cross-dso-req \ +// RUN: -emit-llvm -o - %s | FileCheck %s + +void caller(void (*f)(void)) { + f(); +} + +// CHECK: ![[#]] = !{i32 8, !"Cross-DSO CFI", i32 1} +// CHECK: ![[#]] = !{i32 3, !"Cross-DSO CFI Requirement", ![[#FLAG:]]} +// CHECK: ![[#FLAG]] = !{!"Cross-DSO CFI", i32 1} diff --git a/compiler-rt/test/cfi/cross-dso/required.cpp b/compiler-rt/test/cfi/cross-dso/required.cpp new file mode 100644 index 000000000000..90bd4c11bcbe --- /dev/null +++ b/compiler-rt/test/cfi/cross-dso/required.cpp @@ -0,0 +1,48 @@ +// RUN: %clangxx_cfi_dso -g -DSRC_A -fPIC -c %s -o %t.a.o -fsplit-lto-unit -fsanitize-cfi-cross-dso-req +// RUN: %clangxx_cfi_dso -g -DSRC_B -fPIC -c %s -o %t.b.nocfi.o -fno-sanitize=cfi -fsplit-lto-unit +// RUN: not %clangxx_cfi_dso %t.a.o %t.b.nocfi.o -shared -o %dynamiclib %ld_flags_rpath_so 2>&1 | FileCheck --check-prefix=FAIL-REQ %s + +// RUN: %clangxx_cfi_dso -g -DSRC_B -fPIC -c %s -o %t.b.o -fsplit-lto-unit -fsanitize-cfi-cross-dso-req +// RUN: %clangxx_cfi_dso %t.a.o %t.b.o -shared -o %dynamiclib %ld_flags_rpath_so +// RUN: %clangxx_cfi_dso %s -o %t %ld_flags_rpath_exe +// RUN: %t 2>&1 | FileCheck --check-prefix=CFI %s + +// FAIL-REQ: linking module flags 'Cross-DSO CFI': does not have the required value + +#include + +struct A { + virtual void f(); +}; + +A *create_B(); + +#ifdef SRC_B + +struct B : A { + void f() override; +}; +void B::f() { + puts("B"); +} + +A *create_B() { + return new B(); +} + +#elif defined SRC_A + +void A::f() { + puts("A"); +} + +#else + +int main() { + A *ptr = create_B(); + ptr->f(); + // CFI: B + return 0; +} + +#endif -- Gitee From 209995d62b18e121b35107eb2edf9ca16d511df8 Mon Sep 17 00:00:00 2001 From: liujia178 Date: Fri, 26 Apr 2024 16:14:31 +0800 Subject: [PATCH 03/13] [LLDB] Adapt LLDB for the arm/arm64 platform of the OHOS. Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I9GMT2 Signed-off-by: liujia178 Change-Id: If5c89d5bcc74ff43051b89c9efb3d38e042a9a1f --- llvm-build/README.md | 33 +++- llvm-build/build-ohos-aarch64.py | 229 +++++++-------------- llvm-build/build-ohos-arm.py | 80 ++++++++ llvm-build/build.py | 202 ++++++++++--------- llvm-build/build_libedit.sh | 61 ++++-- llvm-build/build_ncurses.sh | 61 ++++-- llvm-build/ohos_toolchain_builder.py | 286 +++++++++++++++++++++++++++ llvm-build/python_builder.py | 210 +++++++++++++++----- 8 files changed, 822 insertions(+), 340 deletions(-) create mode 100755 llvm-build/build-ohos-arm.py create mode 100644 llvm-build/ohos_toolchain_builder.py diff --git a/llvm-build/README.md b/llvm-build/README.md index 407b4b4c1871..469398843e41 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 @@ -145,6 +145,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 +158,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 dd8fec1d54cc..bd4828ec5184 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 000000000000..27931c07287d --- /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 ee12969b8e24..f6e465e41f14 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -216,7 +216,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', @@ -588,6 +588,18 @@ class BuildUtils(object): return None + 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 +616,26 @@ 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 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): @@ -674,10 +698,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 +710,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 +741,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 +760,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 +804,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 +813,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' @@ -909,8 +943,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 +1001,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 +1017,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, @@ -1695,11 +1727,10 @@ class LlvmLibs(BuildUtils): lldb_target.append('lldb') 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 +1795,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) @@ -1784,12 +1815,12 @@ class LlvmLibs(BuildUtils): ncurses_version = self.get_ncurses_version() if ncurses_version is not None: 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] 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) + 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 +1858,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 +1871,17 @@ 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] + args = ['./build_libedit.sh', libedit_src_dir, libedit_build_path , libedit_install_path, libncurses_path, prebuilts_path, clang_version, platform_triple] 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) + self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_make) + self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_install) def build_libxml2_defines(self): libxml2_defines = {} @@ -1862,7 +1893,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 +1904,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 +1931,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 +1940,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 +2369,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 +2379,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 +2407,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 +2432,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 +2442,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 +2452,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 +2543,6 @@ class LlvmPackage(BuildUtils): return - def main(): build_config = BuildConfig() build_utils = BuildUtils(build_config) @@ -2560,13 +2578,13 @@ 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()) 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: diff --git a/llvm-build/build_libedit.sh b/llvm-build/build_libedit.sh index 5d046197a887..357ebea76022 100755 --- a/llvm-build/build_libedit.sh +++ b/llvm-build/build_libedit.sh @@ -47,34 +47,57 @@ 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} + cd ${LIBEDIT_SRC_DIR} 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 < $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 [[ ${7} != *${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_SRC_DIR}/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 [[ $7 =~ 'arm' ]]; then + C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" + fi + ${LIBEDIT_SRC_DIR}/configure \ + --prefix=${LIBEDIT_INSTALL_PATH} \ + --host="$7" \ + CC="${PREBUILT_PATH}/../out/llvm-install/bin/clang --target=$7" \ + CFLAGS="${C_FLAGS}" \ + LDFLAGS="-L${NCURSES_PATH}/lib" + + make -j$(nproc --all) install | tee build_libedit_$7.log + fi fi diff --git a/llvm-build/build_ncurses.sh b/llvm-build/build_ncurses.sh index df4f7b1ed45c..91a995440498 100755 --- a/llvm-build/build_ncurses.sh +++ b/llvm-build/build_ncurses.sh @@ -60,31 +60,50 @@ 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_SRC_DIR}/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_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 + fi + else + C_FLAGS="--target=$7 -fPIC" + if [[ $7 =~ 'arm' ]]; then + C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" + fi ${NCURSES_SRC_DIR}/configure \ + --host="$7" \ --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" \ + 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_$7.log fi fi diff --git a/llvm-build/ohos_toolchain_builder.py b/llvm-build/ohos_toolchain_builder.py new file mode 100644 index 000000000000..f8a586f90c9d --- /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 7ca5426987ee..1663b5916875 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)) -- Gitee From 2b4699bcca683c9aca7eef5fdf81cfbebbc63cc4 Mon Sep 17 00:00:00 2001 From: Pavel Kosov Date: Wed, 15 May 2024 10:39:00 +0300 Subject: [PATCH 04/13] [ADLT][Build] Add options to build adlt-related components Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I9LH37 Signed-off-by: Pavel Kosov --- llvm-build/Makefile | 6 ++ llvm-build/README.md | 7 ++ llvm-build/build.py | 214 +++++++++++++++++++++++++++++++++++--- llvm-build/env_prepare.sh | 2 + 4 files changed, 214 insertions(+), 15 deletions(-) diff --git a/llvm-build/Makefile b/llvm-build/Makefile index ecb982228b0e..79c3c413ccb9 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 469398843e41..fbf67c6362eb 100644 --- a/llvm-build/README.md +++ b/llvm-build/README.md @@ -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. ```
diff --git a/llvm-build/build.py b/llvm-build/build.py index f6e465e41f14..f792ccb5edf6 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() @@ -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', @@ -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)) @@ -647,6 +696,7 @@ class LlvmCore(BuildUtils): build_dir, install_dir, build_name, + build_target=None, extra_defines=None, extra_env=None): @@ -677,6 +727,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, @@ -686,8 +737,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(): @@ -828,6 +899,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, @@ -885,6 +957,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) @@ -1093,12 +1166,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', @@ -1294,7 +1370,7 @@ class LlvmLibs(BuildUtils): ldflags.extend(ldflag) cflag = [ - '-fstack-protector-strong', + '-fstack-protector-strong', '--target=%s' % llvm_triple, '-ffunction-sections', '-fdata-sections', @@ -1350,6 +1426,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' @@ -1391,8 +1469,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: @@ -1400,6 +1478,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) @@ -1495,10 +1576,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, @@ -1883,6 +1964,66 @@ class LlvmLibs(BuildUtils): 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 = {} libxml2_defines['LIBXML2_WITH_PYTHON'] = 'OFF' @@ -2553,12 +2694,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: @@ -2593,20 +2736,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 @@ -2615,7 +2759,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) @@ -2634,6 +2778,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: @@ -2674,6 +2856,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/env_prepare.sh b/llvm-build/env_prepare.sh index 6614f8c2fc6f..e2111ee61d68 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 ... -- Gitee From 69c4ab1ebf2f552aad18ab55ce17d4ecf09a773b Mon Sep 17 00:00:00 2001 From: yanpeng Date: Mon, 13 May 2024 16:13:51 +0800 Subject: [PATCH 05/13] [build][lldb] enable libedit and ncurses for lldb standalone Issue:https://gitee.com/openharmony/third_party_llvm-project/issues/I9KBCT Test: run lldb on arm-linux-ohos, support for automatic command line associative completion, and support gui debugging Signed-off-by: yanpeng --- llvm-build/build.py | 48 +++++++++++++++++++++++++++++++++---- llvm-build/build_libedit.sh | 25 +++++++++++-------- llvm-build/build_ncurses.sh | 28 +++++++++++++++------- 3 files changed, 78 insertions(+), 23 deletions(-) diff --git a/llvm-build/build.py b/llvm-build/build.py index f6e465e41f14..c3784098eb18 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -622,6 +622,20 @@ class BuildUtils(object): def merge_libxml2_build_dir(self, platform_triple, *args): return self.merge_out_path('third_party', 'libxml2', 'build', platform_triple, *args) + 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) @@ -1726,6 +1740,27 @@ 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, True) lldb_defines['LLDB_ENABLE_LIBXML2'] = 'ON' @@ -1814,11 +1849,14 @@ 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, platform_triple] + 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) + 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) @@ -1876,12 +1914,14 @@ class LlvmLibs(BuildUtils): 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, platform_triple] + 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(platform_triple, llvm_make) - self.llvm_package.copy_libedit_to_llvm(platform_triple, 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 build_libxml2_defines(self): libxml2_defines = {} diff --git a/llvm-build/build_libedit.sh b/llvm-build/build_libedit.sh index 357ebea76022..becfc48fb969 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,8 +48,11 @@ 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} - cd ${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} @@ -56,13 +61,13 @@ if [ -e ${libedit_package} ]; then # Apply patches in order for patch in "${patches[@]}" do - patch -Np1 < $patch + patch -Np1 < ${LIBEDIT_SRC_DIR}/$patch done # build libedit cd ${LIBEDIT_BUILD_PATH} ohos_suffix='-ohos' - if [[ ${7} != *${ohos_suffix} ]]; then + if [[ ${TARGET} != *${ohos_suffix} ]]; then ldflags="-L${NCURSES_PATH}/lib" ncuses_flags="-I${NCURSES_PATH}/include" if [ "${host_platform}" = "darwin" ]; then @@ -79,24 +84,24 @@ if [ -e ${libedit_package} ]; then export CFLAGS="$CFLAGS $ncuses_flags" fi - ${LIBEDIT_SRC_DIR}/configure \ + ${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 [[ $7 =~ 'arm' ]]; then + if [[ ${TARGET} =~ 'arm' ]]; then C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" fi - ${LIBEDIT_SRC_DIR}/configure \ + ${LIBEDIT_UNTAR_PATH}/configure \ --prefix=${LIBEDIT_INSTALL_PATH} \ - --host="$7" \ - CC="${PREBUILT_PATH}/../out/llvm-install/bin/clang --target=$7" \ + --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_$7.log + 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 91a995440498..e97163f64fb8 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 @@ -69,7 +74,7 @@ if [ -e ${ncurses_package} ]; then export CPPFLAGS="$CPPFALGS -I${SDKROOT}/usr/include -I${SDKROOT}/usr/include/i368" export CFLAGS="$CFLAGS -isysroot${SDKROOT} $flags" - ${NCURSES_SRC_DIR}/configure \ + ${NCURSES_UNTAR_PATH}/configure \ --with-shared \ --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ --disable-mixed-case \ @@ -80,7 +85,7 @@ if [ -e ${ncurses_package} ]; then fi if [ "${host_platform}" == "linux" ]; then export LDFLAGS="-Wl,-rpath,\$$ORIGIN/../lib" - ${NCURSES_SRC_DIR}/configure \ + ${NCURSES_UNTAR_PATH}/configure \ --with-shared \ --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ --prefix=${NCURSES_INSTALL_PATH} \ @@ -89,21 +94,26 @@ if [ -e ${ncurses_package} ]; then make -j$(nproc --all) install | tee build_ncurses.log fi else - C_FLAGS="--target=$7 -fPIC" - if [[ $7 =~ 'arm' ]]; then + 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="$7" \ + --host="${TARGET}" \ --with-shared \ --prefix=${NCURSES_INSTALL_PATH} \ --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_$7.log + make -j$(nproc --all) install | tee build_ncurses_${TARGET}.log fi fi -- Gitee From c6158f0642514fca34c7ed401e5d45c95ad81150 Mon Sep 17 00:00:00 2001 From: Pavel Kosov Date: Wed, 15 May 2024 09:59:16 +0300 Subject: [PATCH 06/13] [ADLT][llvm-readelf] Parse ADLT section in llvm-readelf Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I9NJ2P Signed-off-by: Pavel Kosov --- llvm/include/llvm/BinaryFormat/ADLTSection.h | 122 ++++++++ llvm/include/llvm/BinaryFormat/ELF.h | 2 + llvm/tools/llvm-readobj/ELFDumper.cpp | 278 +++++++++++++++++++ llvm/tools/llvm-readobj/ObjDumper.h | 1 + llvm/tools/llvm-readobj/Opts.td | 2 + llvm/tools/llvm-readobj/llvm-readobj.cpp | 7 + 6 files changed, 412 insertions(+) create mode 100644 llvm/include/llvm/BinaryFormat/ADLTSection.h diff --git a/llvm/include/llvm/BinaryFormat/ADLTSection.h b/llvm/include/llvm/BinaryFormat/ADLTSection.h new file mode 100644 index 000000000000..6d57903cdd09 --- /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 234c946b2014..6a12c647f79f 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/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index c9a239f785d2..99aa24b6e6c5 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 292efd2ae350..bad21cc732b2 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 4687fc71245f..2abd661af548 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 e1ebbeb41f28..b4c1d7dd94b7 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) -- Gitee From 790ec6cc1897437433db67f69f4ae2bb6cc5efe1 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Sat, 9 Mar 2024 13:59:49 +0300 Subject: [PATCH 07/13] [ArkRuntime] Support to keep GC objects on callee-saved registers * x86_64: adjust ArkResolver and ArkPlt conventions * Make spill size option more powerfull * Do not assign arguments to vregs * Add ArkFast6 convention * Whitespace changes in tests Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I9LCDT Signed-off-by: Roman Zhuykov --- llvm/docs/BitCodeFormat.rst | 7 +- llvm/docs/LangRef.rst | 2 + llvm/include/llvm/AsmParser/LLToken.h | 1 + .../include/llvm/CodeGen/TargetRegisterInfo.h | 11 +- llvm/include/llvm/IR/CallingConv.h | 9 +- llvm/lib/AsmParser/LLLexer.cpp | 1 + llvm/lib/AsmParser/LLParser.cpp | 2 + .../SelectionDAG/StatepointLowering.cpp | 22 +- llvm/lib/CodeGen/TargetRegisterInfo.cpp | 8 + llvm/lib/IR/AsmWriter.cpp | 1 + .../AArch64/AArch64ArkGcCallingConvention.td | 14 +- .../Target/AArch64/AArch64CallingConvention.h | 3 + .../AArch64/AArch64CallingConvention.td | 14 +- .../Target/AArch64/AArch64FrameLowering.cpp | 3 +- .../Target/AArch64/AArch64ISelLowering.cpp | 3 + .../Target/AArch64/AArch64RegisterInfo.cpp | 4 + .../AArch64/GISel/AArch64CallLowering.cpp | 1 + llvm/lib/Target/X86/X86CallingConv.td | 12 +- llvm/lib/Target/X86/X86ISelLowering.cpp | 1 + llvm/lib/Target/X86/X86RegisterInfo.cpp | 4 + .../CodeGen/AArch64/implicit-null-check.ll | 12 +- .../AArch64/ptr32-implicit-null-checks.ll | 204 ++++++++---------- llvm/utils/emacs/llvm-mode.el | 2 +- llvm/utils/vim/syntax/llvm.vim | 1 + 24 files changed, 191 insertions(+), 151 deletions(-) diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst index 50c5bf88ec13..cae33b3bb704 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 e3cc48d7e9ca..060a765b9f09 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 a0cb5168ed71..fe0e3f3a0460 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/CodeGen/TargetRegisterInfo.h b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h index 04369a5bfe0d..c70fe7ce07cf 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 3221e5c9541d..586ec1519840 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 a77f77c8e91e..509cda0cc738 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 6f270e0db471..30b0d917b696 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 961707a7fc9e..f047e80cd62f 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 ac346585b0f8..77e6c923e036 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 cc5e4f586716..2d6bb345e465 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 5485ac4c90da..1ace7ab7f19b 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 90e8be6eeee0..5af6876f85ba 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 0094ee3e3129..78e82cb3cc4d 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 8856fe0ea555..43ee70edcd23 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 a98f763143fe..d742d87eca22 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 49c45cec1e91..abcc0f749e6c 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 5c3a2ee63d56..ff597e6605b0 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 10f3ed29105f..43c8e5cd68ae 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 72eb76ae0212..3f8336b25900 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 f6f92bddeff6..6b0738266b62 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 59bbfda757c8..5ed33a622439 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 dcecc92d5b70..fc15558caccc 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/utils/emacs/llvm-mode.el b/llvm/utils/emacs/llvm-mode.el index c4def25469f2..2b335ac76fdb 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 5b333a8b5bbc..a2f58f8b472e 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 -- Gitee From 9af7ceee54af2a2c3aeec2a1a5e35635b50fe1bf Mon Sep 17 00:00:00 2001 From: yinchuang Date: Thu, 16 May 2024 11:33:39 +0800 Subject: [PATCH 08/13] [Sanitizer] Fix buf of tsan log Issue:I9PQUL Signed-off-by: yinchuang --- compiler-rt/lib/tsan/rtl/tsan_report.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cpp b/compiler-rt/lib/tsan/rtl/tsan_report.cpp index b5481eb8b340..ae59355b7f58 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 -- Gitee From a368cf69fbc69e636ee9cd160e529b269652e910 Mon Sep 17 00:00:00 2001 From: xwx1135370 Date: Wed, 15 May 2024 16:01:46 +0800 Subject: [PATCH 09/13] [LLDB]Upgrade lzma23.01 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue:https://gitee.com/openharmony/third_party_llvm-project/issues/I9KP7J?from=project-issue Test:LLVM Toolchain Compilation Signed-off-by: xwx1135370 --- llvm-build/MakeLiblzma | 2 +- llvm-build/build.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/llvm-build/MakeLiblzma b/llvm-build/MakeLiblzma index 4f4ceff1e6c3..4970b9f98033 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/build.py b/llvm-build/build.py index f6e465e41f14..d2d2e05be881 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -89,7 +89,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 @@ -574,20 +574,26 @@ 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) @@ -2580,6 +2586,9 @@ def main(): if build_config.build_ncurses: 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) -- Gitee From b5d6d1f01a251dbe77c56c38f4f1162db7577d5c Mon Sep 17 00:00:00 2001 From: yinchuang Date: Fri, 17 May 2024 15:36:19 +0800 Subject: [PATCH 10/13] [Sanitizer] Add ohos log init for tsan Issue:I9Q57D Signed-off-by: yinchuang --- compiler-rt/lib/tsan/rtl/tsan_rtl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp index f3702a52f6c5..646dec64864b 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp @@ -707,6 +707,7 @@ void Initialize(ThreadState *thr) { const char *options = GetEnv(env_name); CacheBinaryName(); CheckASLR(); + OhosLogInit(); // OHOS_LOCAL InitializeFlags(&ctx->flags, options, env_name); AvoidCVE_2016_2143(); __sanitizer::InitializePlatformEarly(); -- Gitee From fde3e027e022b17668d0c94b04348ca380bfa6da Mon Sep 17 00:00:00 2001 From: likholatovevgeny Date: Fri, 17 May 2024 13:06:01 +0300 Subject: [PATCH 11/13] Changed name of llvm install method. Signed-off-by: likholatovevgeny --- llvm-build/build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm-build/build.py b/llvm-build/build.py index 76b1b941c583..9b9d6fefdf04 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -760,9 +760,9 @@ class LlvmCore(BuildUtils): target=build_target, install=install) if not install: - self.llvm_install(build_dir, install_dir) + self.llvm_manual_install(build_dir, install_dir) - def llvm_install(self, build_dir, install_dir): + def llvm_manual_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}" -- Gitee From 46175aff185f0a190f5dc9296b0aa6e1b5a5047f Mon Sep 17 00:00:00 2001 From: gaohongtao Date: Thu, 23 May 2024 12:20:15 +0800 Subject: [PATCH 12/13] Enable frame headers cache for unwinding Set LIBUNWIND_USE_FRAME_HEADER_CACHE option to ON for ohos Issue: I9RDEB Signed-off-by: gaohongtao --- llvm-build/build.py | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm-build/build.py b/llvm-build/build.py index 76b1b941c583..b378ac12cc9e 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -600,6 +600,7 @@ class BuildUtils(object): 'lib', 'libpython%s.so' % self.build_config.LLDB_PY_VERSION) defines['COMPILER_RT_BUILD_XRAY'] = 'OFF' + defines['LIBUNWIND_USE_FRAME_HEADER_CACHE'] = 'ON' return defines def get_python_dir(self): -- Gitee From 955a57a526231c7fb10d8a79b2fb9700b2138af5 Mon Sep 17 00:00:00 2001 From: Khomutov Nikita Date: Mon, 27 May 2024 03:47:23 +0000 Subject: [PATCH 13/13] [llvm-readobj] fix build on darwin platform - on the dawrin platform: size_t has ambiguous resolution when converting to exact interger types - note: https://github.com/dmlc/HalideIR/issues/17 Signed-off-by: Khomutov Nikita --- llvm/tools/llvm-readobj/ELFDumper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 99aa24b6e6c5..7dd345a6f2ff 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -7109,7 +7109,7 @@ template void LLVMELFDumper::printAdltSection() { { ListScope LPsods(W, "PSODs"); - for (size_t psodIdx = 0; psodIdx < header->sharedObjectsNum; ++psodIdx) { + for (Elf64_Half psodIdx = 0; psodIdx < header->sharedObjectsNum; ++psodIdx) { const adlt_psod_t &psod = *reinterpret_cast( psodsRaw.data() + psodIdx * header->schemaPSODSize); -- Gitee