diff --git a/clang/docs/ClangCommandLineReference.rst b/clang/docs/ClangCommandLineReference.rst index 41fb8f7259eb4c90575b0335ce91704baa9241bd..d82f716fbafeb47eea0bdc1c0d0df7874a6e7ae3 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 5d4aec842db3f5ad4fb552348ce31a852d30e7c2..eb136624bb34e5cad7c5f1b8ff97a5186a932404 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 97433f169d1434c4e6a10bbc0ce41d4d4129eeff..b6a1636aa84a61b00981ab30e2b3f4ec2fbaf45c 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 1b29b1151224fd2073a98d47db0854c0bcabc164..18d0a9892e8ed21cd3439f4ac03febd976740da9 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 a6144180f9c906c78551b7145964f5838890768b..e9635356e26f267248ced7f1bd5303ee1905bdcd 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 20c93c03a4c0728bd1b4c54c439f9ee7e3b3c83e..d52afc636445f176adedc138430a9b87ada0a29a 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 0000000000000000000000000000000000000000..42be04605765f487e73c54dadbf30110ca8ecfd3 --- /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/lib/tsan/rtl/tsan_report.cpp b/compiler-rt/lib/tsan/rtl/tsan_report.cpp index b5481eb8b340c3367ae549d93570ebc409000642..ae59355b7f582bec814ecb0375047123254e3e9c 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_report.cpp @@ -376,6 +376,7 @@ void PrintReport(const ReportDesc *rep) { DumpProcessMap(); Printf("==================\n"); + Printf("End Tsan report\n"); // OHOS_LOCAL } #else // #if !SANITIZER_GO diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp index f3702a52f6c517a43530b44ae5a481d5ae5c4286..646dec64864b0f211c71dade824914c19ebd32b6 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(); 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 0000000000000000000000000000000000000000..90bd4c11bcbe6478ec897caf72d151924d5fab74 --- /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 diff --git a/llvm-build/MakeLiblzma b/llvm-build/MakeLiblzma index 4f4ceff1e6c3f9da51c886fef158b0495e8a91ce..4970b9f9803323e8fd6deabe642bef9712eb1a70 100644 --- a/llvm-build/MakeLiblzma +++ b/llvm-build/MakeLiblzma @@ -15,7 +15,7 @@ SYSROOT := INSTALL_DIR := TARGET_TRIPLE := CC := -SRCS := 7zAlloc.c 7zArcIn.c 7zBuf2.c 7zBuf.c 7zCrc.c 7zCrcOpt.c 7zDec.c 7zFile.c 7zStream.c Aes.c AesOpt.c Alloc.c Bcj2.c Bra86.c Bra.c BraIA64.c CpuArch.c Delta.c LzFind.c Lzma2Dec.c Lzma2Enc.c Lzma86Dec.c Lzma86Enc.c LzmaDec.c LzmaEnc.c LzmaLib.c Ppmd7.c Ppmd7Dec.c Ppmd7Enc.c Sha256.c Sha256Opt.c Sort.c Xz.c XzCrc64.c XzCrc64Opt.c XzDec.c XzEnc.c XzIn.c +SRCS := 7zAlloc.c 7zArcIn.c 7zBuf2.c 7zBuf.c 7zCrc.c 7zCrcOpt.c 7zDec.c 7zFile.c 7zStream.c Aes.c AesOpt.c Alloc.c Bcj2.c Bra86.c Bra.c BraIA64.c CpuArch.c Delta.c LzFind.c Lzma2Dec.c Lzma2Enc.c Lzma86Dec.c Lzma86Enc.c LzmaDec.c LzmaEnc.c LzmaLib.c Ppmd7.c Ppmd7Dec.c Ppmd7Enc.c Sha256.c Sha256Opt.c Sort.c Xz.c XzCrc64.c XzCrc64Opt.c XzDec.c XzEnc.c XzIn.c MtDec.c MtCoder.c LzFindMt.c LzFindOpt.c Threads.c SRC_PREFIX := LIB_VERSION := diff --git a/llvm-build/README.md b/llvm-build/README.md index 39842b084ad58bbd436235f67588eb92f23ea0dd..fbf67c6362eb3e57431e0ab3838e4c30c69440b9 100644 --- a/llvm-build/README.md +++ b/llvm-build/README.md @@ -75,7 +75,7 @@ build.py options: --build-instrumented # enable instrument pgo when build toolchain --xunit-xml-output # specify LLVM unit test XML report path --build-lldb-static # build statically lldb tool for ARM and AARCH64 ---build-python # build python (not using prebuilt one, currently effective for Windows) +--build-python # build python (not using prebuilt one, currently effective for Windows and OHOS) --build-ncurses # build ncurses tool for linux, Mac x86-64 or M1 --build-libedit # build libedit tool for linux, Mac x86-64 or M1 --build-libxml2 # build libxml2 tool for linux, windows, Mac x86_64 or M1 @@ -152,6 +152,10 @@ build-ohos-aarch64.py options: --enable-assertions # enable assertion when compiling --debug # build debug version llvm toolchain --strip # strip llvm toolchain binaries +--build-python # build python and enable script in debugger +--build-ncurses # build ncurses and enable ncurses in debugger +--build-libedit # build libedit and enable libedit in debugger +--build-libxml2 # build libxml2 and enable libxml in debugger ```
@@ -161,6 +165,33 @@ When build successfully completed, artifacts will be available in `out/ohos-aarc ## Function Introduction
+### Build process of Arm debugger + +First build toolchain on Linux. +Here is an example of starting build process on Linux: +``` +# build +python3 ./toolchain/llvm-project/llvm-build/build-ohos-arm.py +``` + +
+ +build-ohos-arm.py options: + +``` +--build-python # build python and enable script in debugger +--build-ncurses # build ncurses and enable ncurses in debugger +--build-libedit # build libedit and enable libedit in debugger +--build-libxml2 # build libxml2 and enable libxml in debugger +``` +
+ +When build successfully completed, artifacts will be available in `out/ohos-arm-install` directory, including lldb for arm. + + +## Function Introduction +
+ ### Functionality The LLVM toolchain is built based on LLVM 15.0.4. It is used to provide capability of building ohos image. For detailed information about LLVM 15.0.4, please refer to [LLVM 15.0.4](https://discourse.llvm.org/t/llvm-15-0-4-released/66337). diff --git a/llvm-build/build-ohos-aarch64.py b/llvm-build/build-ohos-aarch64.py index dd8fec1d54cc063e54a377764b86980e0badcb1d..bd4828ec51840b3b879dc3b5be506623b43b2876 100755 --- a/llvm-build/build-ohos-aarch64.py +++ b/llvm-build/build-ohos-aarch64.py @@ -14,163 +14,84 @@ # limitations under the License. import os +from ohos_toolchain_builder import OHOSToolchainBuilder + + +class Aarch64ToolchainBuilder(OHOSToolchainBuilder): + def __init__(self) -> None: + super().__init__("aarch64-linux-ohos") + + def _update_build_args(self): + self._cflags.extend( + [ + "-v", + "-funwind-tables", + "-no-canonical-prefixes", + "-D__MUSL__", + ] + ) + + cflags_debug = "-O0 -g -fno-limit-debug-info" + cflags_release = "-O2 -DNDEBUG" + + self._ldflags.extend(["-static-libstdc++"]) + + llvm_extra_env = {} + llvm_extra_env["LD_LIBRARY_PATH"] = os.path.join(self._llvm_root, "lib") + env = dict(self._build_config.ORIG_ENV) + if llvm_extra_env is not None: + env.update(llvm_extra_env) + + # We do not build runtimes, since they will be copied from main toolchain build + self._llvm_defines.update( + { + "CMAKE_C_FLAGS_DEBUG": cflags_debug, + "CMAKE_CXX_FLAGS_DEBUG": cflags_debug, + "CMAKE_ASM_FLAGS_DEBUG": cflags_debug, + "CMAKE_C_FLAGS_RELEASE": cflags_release, + "CMAKE_CXX_FLAGS_RELEASE": cflags_release, + "CMAKE_ASM_FLAGS_RELEASE": cflags_release, + "OPENMP_STANDALONE_BUILD": "ON", + "LLVM_DIR": os.path.join(self._llvm_root, "lib", "cmake", "llvm"), + "LLVM_ENABLE_FFI": "OFF", + "LLVM_BUILD_LLVM_DYLIB": "ON", + "CMAKE_LIBRARY_ARCHITECTURE": self._llvm_triple, + "LLVM_INCLUDE_BENCHMARKS": "OFF", + "LLVM_INCLUDE_EXAMPLES": "OFF", + "LLVM_INCLUDE_TESTS": "OFF", + "LLVM_BUILD_TOOLS": "ON", + "LLVM_INSTALL_UTILS": "ON", + "LLVM_ENABLE_ZLIB": "OFF", + "LLVM_ENABLE_PROJECTS": ";".join(self._build_config.host_projects), + "CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN": self._llvm_root, + "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN": self._llvm_root, + "CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN": self._llvm_root, + "CMAKE_NM": os.path.join(self._llvm_root, "bin", "llvm-nm"), + "CMAKE_RANLIB": os.path.join(self._llvm_root, "bin", "llvm-ranlib"), + "CMAKE_OBJCOPY": os.path.join(self._llvm_root, "bin", "llvm-objcopy"), + "CMAKE_OBJDUMP": os.path.join(self._llvm_root, "bin", "llvm-objdump"), + "CMAKE_READELF": os.path.join(self._llvm_root, "bin", "llvm-readelf"), + "CMAKE_STRIP": os.path.join(self._llvm_root, "bin", "llvm-strip"), + "CMAKE_LINKER": os.path.join(self._llvm_root, "bin", "ld.lld"), + "CMAKE_POSITION_INDEPENDENT_CODE": "True", + "CMAKE_CXX_FLAGS": " ".join(self._cflags) + " -stdlib=libc++", + "CMAKE_ASM_FLAGS": " ".join(self._cflags), + "CMAKE_C_FLAGS": " ".join(self._cflags), + "CMAKE_SHARED_LINKER_FLAGS": " ".join(self._ldflags), + "CMAKE_MODULE_LINKER_FLAGS": " ".join(self._ldflags), + "CMAKE_EXE_LINKER_FLAGS": " ".join(self._ldflags) + + " -Wl,--gc-sections", + } + ) + + if self._build_config.enable_assertions: + self._llvm_defines["LLVM_ENABLE_ASSERTIONS"] = "ON" -from build import BuildConfig, BuildUtils def main(): - print('Start cross-compiling LLVM toolchain for OHOS AArch64 host on linux') - build_config = BuildConfig() - build_utils = BuildUtils(build_config) + print("Start cross-compiling LLVM toolchain for OHOS AArch64 host on linux") + Aarch64ToolchainBuilder().build() - llvm_project_path = os.path.abspath(os.path.join(build_config.LLVM_PROJECT_DIR, 'llvm')) - llvm_path = build_utils.merge_out_path('ohos-aarch64') - llvm_install = build_utils.merge_out_path('ohos-aarch64-install') - llvm_root = build_utils.merge_out_path('llvm-install') - sysroot = build_utils.merge_out_path('sysroot') - llvm_triple = 'aarch64-linux-ohos' - - cflags = [ '-v', - '-fstack-protector-strong', - '-fdata-sections', - '-ffunction-sections', - '-funwind-tables', - '-no-canonical-prefixes', - '-D__MUSL__', - '-target %s' % llvm_triple, - ] - - cflags_debug = '-O0 -g -fno-limit-debug-info' - cflags_release = '-O2 -DNDEBUG' - - ldflags = [ '-fuse-ld=lld', - '--rtlib=compiler-rt', - '-lunwind', - '-stdlib=libc++', - '-static-libstdc++', - '-pie', - '-Wl,--build-id=sha1', - '-Wl,-z,relro,-z,now', - ] - - if build_config.strip: - ldflags.append('-s') - - llvm_extra_env = {} - llvm_extra_env['LD_LIBRARY_PATH'] = os.path.join(llvm_root, 'lib') - env = dict(build_config.ORIG_ENV) - if llvm_extra_env is not None: - env.update(llvm_extra_env) - - llvm_defines = {} - llvm_defines['CMAKE_SYSTEM_NAME'] = 'OHOS' - llvm_defines['CMAKE_CROSSCOMPILING'] = 'True' - llvm_defines['CMAKE_INSTALL_PREFIX'] = llvm_install - llvm_defines['CMAKE_SYSROOT'] = sysroot - llvm_defines['CMAKE_LIBRARY_ARCHITECTURE'] = llvm_triple - llvm_defines['LLVM_HOST_TRIPLE'] = llvm_triple - llvm_defines['LLVM_TARGETS_TO_BUILD'] = build_config.TARGETS - llvm_defines['LLVM_TARGET_ARCH'] = 'AArch64' - llvm_defines['LLVM_DEFAULT_TARGET_TRIPLE'] = llvm_triple - llvm_defines['LLVM_BUILD_LLVM_DYLIB'] = 'ON' - llvm_defines['LLVM_ENABLE_FFI'] = 'OFF' - llvm_defines['LLVM_ENABLE_TERMINFO'] = 'OFF' - llvm_defines['LLVM_INCLUDE_BENCHMARKS'] = 'OFF' - llvm_defines['LLVM_INCLUDE_EXAMPLES'] = 'OFF' - llvm_defines['LLVM_INCLUDE_TESTS'] = 'OFF' - llvm_defines['LLVM_BUILD_TOOLS'] = 'ON' - llvm_defines['LLVM_INSTALL_UTILS'] = 'ON' - llvm_defines['LLVM_ENABLE_ZLIB'] = 'OFF' - llvm_defines['LLVM_ENABLE_PROJECTS'] = ';'.join(build_config.host_projects) - # We do not build runtimes, since they will be copied from main toolchain build - llvm_defines['LLVM_CONFIG_PATH'] = os.path.join(llvm_root, 'bin', 'llvm-config') - llvm_defines['LLVM_TABLEGEN'] = os.path.join(llvm_root, 'bin', 'llvm-tblgen') - llvm_defines['CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN'] = llvm_root - llvm_defines['CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN'] = llvm_root - llvm_defines['CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN'] = llvm_root - llvm_defines['CMAKE_C_COMPILER'] = os.path.join(llvm_root, 'bin', 'clang') - llvm_defines['CMAKE_CXX_COMPILER'] = os.path.join(llvm_root, 'bin', 'clang++') - llvm_defines['CMAKE_AR'] = os.path.join(llvm_root, 'bin', 'llvm-ar') - llvm_defines['CMAKE_NM'] = os.path.join(llvm_root, 'bin', 'llvm-nm') - llvm_defines['CMAKE_RANLIB'] = os.path.join(llvm_root, 'bin', 'llvm-ranlib') - llvm_defines['CMAKE_OBJCOPY'] = os.path.join(llvm_root, 'bin', 'llvm-objcopy') - llvm_defines['CMAKE_OBJDUMP'] = os.path.join(llvm_root, 'bin', 'llvm-objdump') - llvm_defines['CMAKE_READELF'] = os.path.join(llvm_root, 'bin', 'llvm-readelf') - llvm_defines['CMAKE_STRIP'] = os.path.join(llvm_root, 'bin', 'llvm-strip') - llvm_defines['CMAKE_LINKER'] = os.path.join(llvm_root, 'bin', 'ld.lld') - llvm_defines['CMAKE_ASM_FLAGS'] = ' '.join(cflags) - llvm_defines['CMAKE_C_FLAGS'] = ' '.join(cflags) - llvm_defines['CMAKE_CXX_FLAGS'] = ' '.join(cflags) + ' -stdlib=libc++' - llvm_defines['CMAKE_EXE_LINKER_FLAGS'] = ' '.join(ldflags) + ' -Wl,--gc-sections' - llvm_defines['CMAKE_SHARED_LINKER_FLAGS'] = ' '.join(ldflags) - llvm_defines['CMAKE_MODULE_LINKER_FLAGS'] = ' '.join(ldflags) - llvm_defines['CMAKE_FIND_ROOT_PATH_MODE_INCLUDE'] = 'ONLY' - llvm_defines['CMAKE_FIND_ROOT_PATH_MODE_LIBRARY'] = 'ONLY' - llvm_defines['CMAKE_FIND_ROOT_PATH_MODE_PACKAGE'] = 'ONLY' - llvm_defines['CMAKE_FIND_ROOT_PATH_MODE_PROGRAM'] = 'NEVER' - llvm_defines['CMAKE_POSITION_INDEPENDENT_CODE'] = 'True' - llvm_defines['Python3_EXECUTABLE'] = os.path.join(build_utils.get_python_dir(), 'bin', build_config.LLDB_PYTHON) - llvm_defines['CMAKE_C_FLAGS_DEBUG'] = cflags_debug - llvm_defines['CMAKE_CXX_FLAGS_DEBUG'] = cflags_debug - llvm_defines['CMAKE_ASM_FLAGS_DEBUG'] = cflags_debug - llvm_defines['CMAKE_C_FLAGS_RELEASE'] = cflags_release - llvm_defines['CMAKE_CXX_FLAGS_RELEASE'] = cflags_release - llvm_defines['CMAKE_ASM_FLAGS_RELEASE'] = cflags_release - llvm_defines['OPENMP_STANDALONE_BUILD'] = 'ON' - llvm_defines['LLVM_DIR'] = os.path.join(llvm_root, 'lib', 'cmake', 'llvm') - - lldb_defines = set_lldb_defines() - llvm_defines.update(lldb_defines) - - if build_config.enable_assertions: - llvm_defines['LLVM_ENABLE_ASSERTIONS'] = 'ON' - - if build_config.debug: - llvm_defines['CMAKE_BUILD_TYPE'] = 'Debug' - else: - llvm_defines['CMAKE_BUILD_TYPE'] = 'Release' - - build_utils.invoke_cmake(llvm_project_path, llvm_path, llvm_defines, env=env) - - build_utils.invoke_ninja(out_path=llvm_path, env=env, target=None, install=True) - - # Copy required aarch64-linux-ohos libs from main toolchain build. - arch_list = [build_utils.liteos_triple('arm'), build_utils.open_ohos_triple('arm'), - build_utils.open_ohos_triple('aarch64'), build_utils.open_ohos_triple('riscv64'), - build_utils.open_ohos_triple('mipsel'), build_utils.open_ohos_triple('x86_64')] - for arch in arch_list: - build_utils.check_copy_tree(os.path.join(llvm_root, 'lib', arch), - os.path.join(llvm_install, 'lib', arch)) - build_utils.check_copy_tree(os.path.join(llvm_root, 'lib', 'clang', '15.0.4', 'lib', arch), - os.path.join(llvm_install, 'lib', 'clang', '15.0.4', 'lib', arch)) - - #Copy required c++ headerfiles from main toolchain build. - build_utils.check_copy_tree(os.path.join(llvm_root, 'include', 'c++'), os.path.join(llvm_install, 'include', 'c++')) - build_utils.check_copy_tree(os.path.join(llvm_root, 'include', 'libcxx-ohos'), os.path.join(llvm_install, 'include', 'libcxx-ohos')) - - # Package ohos-aarch64 toolchain. - if build_config.do_package: - tarball_name = 'clang-%s-ohos-aarch64' % (build_config.build_name) - package_path = '%s%s' % (build_utils.merge_packages_path(tarball_name), build_config.ARCHIVE_EXTENSION) - build_utils.logger().info('Packaging %s', package_path) - args = ['tar', build_config.ARCHIVE_OPTION, '-h', '-C', build_config.OUT_PATH, '-f', package_path, 'ohos-aarch64-install'] - build_utils.check_create_dir(build_config.PACKAGES_PATH) - build_utils.check_call(args) - -def set_lldb_defines(): - lldb_defines = {} - lldb_defines['LLDB_INCLUDE_TESTS'] = 'OFF' - lldb_defines['LLDB_ENABLE_TIMEOUT'] = 'False' - # Optional Dependencies - lldb_defines['LLDB_ENABLE_LIBEDIT'] = 'OFF' - lldb_defines['LLDB_ENABLE_CURSE'] = 'OFF' - lldb_defines['LLDB_ENABLE_LIBXML2'] = 'OFF' - lldb_defines['LLDB_ENABLE_LZMA'] = 'OFF' - lldb_defines['LLDB_ENABLE_PYTHON'] = 'OFF' - # Debug & Tuning - lldb_defines['LLDB_ENABLE_PERFORMANCE'] = 'OFF' - - return lldb_defines - -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/llvm-build/build-ohos-arm.py b/llvm-build/build-ohos-arm.py new file mode 100755 index 0000000000000000000000000000000000000000..27931c07287d2951fe1f21049e727ba743546e53 --- /dev/null +++ b/llvm-build/build-ohos-arm.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# Copyright (C) 2024 Huawei Device Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from ohos_toolchain_builder import OHOSToolchainBuilder + + +class ArmToolchainBuilder(OHOSToolchainBuilder): + def __init__(self) -> None: + super().__init__("arm-linux-ohos") + self._llvm_prebuilt_path = self._build_utils.merge_out_path("llvm_make") + + def _update_build_args(self): + self._cflags.extend( + [ + "-march=armv7-a -mfloat-abi=soft", + ] + ) + + self._ldflags.extend( + [ + "-Wl,-rpath,'$ORIGIN/../lib'", + ] + ) + + self._llvm_defines.update( + { + "CMAKE_CXX_FLAGS": " ".join(self._cflags), + "CMAKE_ASM_FLAGS": " ".join(self._cflags), + "CMAKE_C_FLAGS": " ".join(self._cflags), + "CMAKE_SHARED_LINKER_FLAGS": " ".join(self._ldflags), + "CMAKE_MODULE_LINKER_FLAGS": " ".join(self._ldflags), + "CMAKE_EXE_LINKER_FLAGS": " ".join(self._ldflags), + "LLVM_ENABLE_ASSERTIONS": "OFF", + "LLVM_USE_NEWPM": "ON", + "LLVM_ENABLE_BINDINGS": "OFF", + "CLANG_REPOSITORY_STRING": "llvm-project", + "COMPILER_RT_BUILD_XRAY": "OFF", + "CMAKE_POSITION_INDEPENDENT_CODE": "ON", + "LLVM_ENABLE_PER_TARGET_RUNTIME_DIR": "ON", + "COMPILER_RT_USE_BUILTINS_LIBRARY": "ON", + "LLVM_ENABLE_LIBCXX": "ON", + "LLVM_ENABLE_PROJECTS": "clang;lldb", + "CLANG_TABLEGEN": os.path.join( + self._llvm_root, + "..", + self._llvm_prebuilt_path, + "bin", + "clang-tblgen", + ), + "LLDB_TABLEGEN": os.path.join( + self._llvm_root, + "..", + self._llvm_prebuilt_path, + "bin", + "lldb-tblgen", + ), + } + ) + + +def main(): + print("Start building LLDB tools for OHOS ARM host") + ArmToolchainBuilder().build(build_target=["lldb", "lldb-server"]) + + +if __name__ == "__main__": + main() diff --git a/llvm-build/build.py b/llvm-build/build.py index 978cf38a05e0730f1fa68e90becf8bd95b85666b..5920898845d59318909698e533b773d8e8d6f912 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -98,7 +98,7 @@ class BuildConfig(): self.ARCHIVE_EXTENSION = '.tar.' + self.compression_format self.ARCHIVE_OPTION = '-c' + ('j' if self.compression_format == "bz2" else 'z') self.LIBXML2_VERSION = None - self.LZMA_VERSION = '22.0' + self.LZMA_VERSION = None logging.basicConfig(level=logging.INFO) self.host_projects = args.host_build_projects @@ -231,7 +231,7 @@ class BuildConfig(): '--build-python', action='store_true', default=False, - help='Build Python (not using prebuilt one, currently effective for Windows)') + help='Build Python (not using prebuilt one, currently effective for Windows and OHOS)') parser.add_argument( '--build-ncurses', @@ -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): @@ -623,20 +624,38 @@ class BuildUtils(object): def get_mingw_python_dir(self): return self._mingw_python_dir - def get_ncurses_version(self): - ncurses_spec = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'ncurses', 'ncurses.spec') - if os.path.exists(ncurses_spec): - with open(ncurses_spec, 'r') as file: + def get_version(self, fileName, prog): + if os.path.exists(fileName): + with open(fileName, 'r') as file: lines = file.readlines() - - prog = re.compile(r'Version:\s*(\S+)') for line in lines: version_match = prog.match(line) if version_match: return version_match.group(1) - return None + def get_ncurses_version(self): + ncurses_spec = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'ncurses', 'ncurses.spec') + prog = re.compile(r'Version:\s*(\S+)') + return self.get_version(ncurses_spec, prog) + + def get_lzma_version(self): + lzma_version_file = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'lzma', 'C', '7zVersion.h') + prog = re.compile(r'#define MY_VERSION_NUMBERS "(.*?)"') + return self.get_version(lzma_version_file, prog) + + def merge_ncurses_install_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'ncurses', 'install', platform_triple, *args) + + def get_ncurses_dependence_libs(self, platform_triple): + ncurses_libs = ['libncurses', 'libpanel', 'libform'] + if self.use_platform() != platform_triple: + ncurses_libs.append('libtinfo') + return ncurses_libs + + def merge_ncurses_build_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'ncurses', 'build', platform_triple, *args) + def get_libxml2_version(self): version_file = os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'libxml2', 'libxml2.spec') if os.path.isfile(version_file): @@ -653,14 +672,40 @@ class BuildUtils(object): return None - def get_libxml2_source_path(self): - return self.merge_out_path('third_party', 'libxml2', ('libxml2-' + self.build_config.LIBXML2_VERSION)) + def merge_libxml2_install_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'libxml2', 'install', platform_triple, *args) + + def 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) + + def merge_libedit_build_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'libedit', 'build', platform_triple, *args) - def get_libxml2_install_path(self, triple): - return self.merge_out_path('third_party', 'libxml2', 'install', triple) + def merge_python_install_dir(self, platform_triple, *args): + return self.merge_out_path('third_party', 'python', 'install', platform_triple, *args) - def get_libxml2_build_path(self, triple): - return self.merge_out_path('third_party', 'libxml2', 'build', triple) + 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): @@ -716,9 +761,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}" @@ -745,10 +790,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 @@ -756,11 +802,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, @@ -786,12 +833,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 @@ -799,13 +852,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) @@ -841,7 +896,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' @@ -850,11 +905,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' @@ -982,8 +1037,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' @@ -1040,7 +1095,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') @@ -1057,7 +1111,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, @@ -1140,7 +1193,7 @@ class SysrootComposer(BuildUtils): 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.debug): + 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) @@ -1775,12 +1828,32 @@ class LlvmLibs(BuildUtils): lldb_defines['LIBLLDB_BUILD_STATIC'] = 'ON' lldb_target.append('lldb') + if self.build_config.build_ncurses: + self.build_ncurses(None, llvm_install, llvm_triple) + lldb_defines['LLDB_ENABLE_CURSES'] = 'ON' + ncurses_install_path = self.merge_ncurses_install_dir(llvm_triple) + lldb_defines['CURSES_INCLUDE_DIRS'] = os.path.join(ncurses_install_path, 'include') + lldb_defines['CURSES_HAVE_NCURSES_CURSES_H'] = 'ON' + ncurses_lib_path = os.path.join(ncurses_install_path, 'lib') + ncurses_libs = [] + for library in self.get_ncurses_dependence_libs(llvm_triple): + ncurses_libs.append(os.path.join(ncurses_lib_path, f'{library}.a')) + ncurses_libs = ';'.join(ncurses_libs) + lldb_defines['CURSES_LIBRARIES'] = ncurses_libs + lldb_defines['PANEL_LIBRARIES'] = ncurses_libs + + if self.build_config.build_libedit: + self.build_libedit(None, llvm_install, llvm_triple) + lldb_defines['LLDB_ENABLE_LIBEDIT'] = 'ON' + libedit_install_path = self.merge_libedit_install_dir(llvm_triple) + lldb_defines['LibEdit_INCLUDE_DIRS'] = os.path.join(libedit_install_path, 'include') + lldb_defines['LibEdit_LIBRARIES'] = os.path.join(libedit_install_path, 'lib', 'libedit.a') + if self.build_config.build_libxml2: - self.build_libxml2(llvm_triple, None, llvm_install) + self.build_libxml2(llvm_triple, None, llvm_install, True) lldb_defines['LLDB_ENABLE_LIBXML2'] = 'ON' - libxml2_install_path = self.get_libxml2_install_path(llvm_triple) - lldb_defines['LIBXML2_INCLUDE_DIR'] = os.path.join(libxml2_install_path, 'include', 'libxml2') - lldb_defines['LIBXML2_LIBRARY'] = os.path.join(libxml2_install_path, 'lib', 'libxml2.a') + lldb_defines['LIBXML2_INCLUDE_DIR'] = self.merge_libxml2_install_dir(llvm_triple, 'include', 'libxml2') + lldb_defines['LIBXML2_LIBRARY'] = self.merge_libxml2_install_dir(llvm_triple, 'lib', 'libxml2.a') if self.build_config.lldb_timeout: lldb_defines['LLDB_ENABLE_TIMEOUT'] = 'True' @@ -1845,12 +1918,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) @@ -1864,13 +1937,16 @@ class LlvmLibs(BuildUtils): ncurses_version = self.get_ncurses_version() if ncurses_version is not None: + libncurses_untar_path = self.merge_out_path('third_party', 'ncurses', 'ncurses-' + ncurses_version) args = ['./build_ncurses.sh', libncurses_src_dir, libncurses_build_path, libncurses_install_path, - prebuilts_path, clang_version, ncurses_version] + prebuilts_path, clang_version, ncurses_version, platform_triple, libncurses_untar_path, + self.merge_ncurses_install_dir(self.use_platform())] self.check_call(args) os.chdir(cur_dir) - self.llvm_package.copy_ncurses_to_llvm(llvm_make) - self.llvm_package.copy_ncurses_to_llvm(llvm_install) + if platform_triple == self.use_platform(): + self.llvm_package.copy_ncurses_to_llvm(platform_triple, llvm_make) + self.llvm_package.copy_ncurses_to_llvm(platform_triple, llvm_install) def build_lzma(self, llvm_make, llvm_install): self.logger().info('Building lzma') @@ -1908,12 +1984,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) @@ -1921,17 +1997,79 @@ class LlvmLibs(BuildUtils): self.check_rm_tree(libedit_install_path) self.rm_cmake_cache(libedit_install_path) - libncurses_path = self.get_prebuilts_dir('ncurses') + libncurses_path = self.merge_ncurses_install_dir(platform_triple) cur_dir = os.getcwd() os.chdir(self.build_config.LLVM_BUILD_DIR) clang_version = self.build_config.CLANG_VERSION - args = ['./build_libedit.sh', libedit_src_dir, libedit_build_path , libedit_install_path, libncurses_path, prebuilts_path, clang_version] + libedit_untar_path = self.merge_out_path('third_party', 'libedit', 'libedit-' + self.get_libedit_version()) + args = ['./build_libedit.sh', libedit_src_dir, libedit_build_path , libedit_install_path, libncurses_path, prebuilts_path, clang_version, platform_triple, libedit_untar_path] self.check_call(args) os.chdir(cur_dir) - self.llvm_package.copy_libedit_to_llvm(llvm_make) - self.llvm_package.copy_libedit_to_llvm(llvm_install) + if platform_triple == self.use_platform(): + self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_make) + self.llvm_package.copy_libedit_to_llvm(platform_triple, llvm_install) + + def copy_gtest_to_sysroot(self, build_dir): + build_lib_dir = os.path.join(build_dir, 'lib') + self.logger().info('LlvmPackage copy_gtest_to_sysroot from %s', build_lib_dir) + libs = [ "libLLVMSupport.so", "libLLVMDemangle.so", "libllvm_gtest.so" ] + sysroot_lib_dir = self.merge_out_path('sysroot', 'aarch64-linux-ohos', 'usr', 'lib') + + os.chdir(build_lib_dir) + for f in libs: + self.check_copy_file(f'{f}.15', sysroot_lib_dir) + os.chdir(sysroot_lib_dir) + self.force_symlink(f'{f}.15', f) + os.chdir(build_lib_dir) + + def build_gtest_defines(self, llvm_install): + sysroot = self.merge_out_path('sysroot', 'aarch64-linux-ohos', 'usr') + common_flags = f'--target=aarch64-linux-ohos -B{sysroot}/lib -L{sysroot}/lib' + libcxx = self.merge_out_path('llvm-install', 'include', 'libcxx-ohos', 'include', 'c++', 'v1') + libc = os.path.join(sysroot, "include") + + gtest_defines = {} + gtest_defines['BUILD_SHARED_LIBS'] = 'YES' + gtest_defines['CMAKE_BUILD_TYPE'] = 'Release' + gtest_defines['CMAKE_C_COMPILER'] = os.path.join(llvm_install, 'bin', 'clang') + gtest_defines['CMAKE_CXX_COMPILER'] = os.path.join(llvm_install, 'bin', 'clang++') + gtest_defines['LLVM_TABLEGEN'] = os.path.join(llvm_install, 'bin', 'llvm-tblgen') + gtest_defines['CMAKE_LINKER'] = os.path.join(llvm_install, 'bin', 'ld.lld') + gtest_defines['CMAKE_EXE_LINKER_FLAGS'] = f'{common_flags}' + gtest_defines['CMAKE_C_FLAGS'] = f'{common_flags} -I{libc}' + gtest_defines['CMAKE_CXX_FLAGS'] = f'{common_flags} -I{libcxx} -I{libc}' + + return gtest_defines + + def build_gtest(self, compiler_path, llvm_install): + gtest_defines = self.build_gtest_defines(compiler_path) + gtest_cmake_path = os.path.abspath(os.path.join(self.build_config.LLVM_PROJECT_DIR, 'llvm')) + + gtest_build_path = self.merge_out_path('gtest') + + self.rm_cmake_cache(gtest_build_path) + + self.invoke_cmake(gtest_cmake_path, + gtest_build_path, + gtest_defines, + env=dict(self.build_config.ORIG_ENV)) + + self.invoke_ninja(out_path=gtest_build_path, + env=dict(self.build_config.ORIG_ENV), + target=[ "LLVMSupport", "LLVMDemangle", "llvm_gtest" ], + install=False) + + self.copy_gtest_to_sysroot(gtest_build_path) + shutil.copytree( + os.path.join(self.build_config.LLVM_PROJECT_DIR, 'llvm', 'utils', 'unittest', 'googlemock', 'include', 'gmock'), + os.path.join(llvm_install, 'include', 'gmock'), + dirs_exist_ok = True) + shutil.copytree( + os.path.join(self.build_config.LLVM_PROJECT_DIR, 'llvm', 'utils', 'unittest', 'googletest', 'include', 'gtest'), + os.path.join(llvm_install, 'include', 'gtest'), + dirs_exist_ok = True) def copy_gtest_to_sysroot(self, build_dir): build_lib_dir = os.path.join(build_dir, 'lib') @@ -2003,7 +2141,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() @@ -2014,31 +2152,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, @@ -2049,8 +2179,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) @@ -2059,8 +2188,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'))) @@ -2488,7 +2617,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(): @@ -2498,30 +2627,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(): @@ -2529,7 +2655,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') @@ -2554,7 +2680,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() @@ -2564,8 +2690,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') @@ -2574,7 +2700,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): @@ -2702,13 +2828,16 @@ def main(): configs.append(('x86_64', build_utils.open_ohos_triple('x86_64'))) if build_config.build_ncurses: - llvm_libs.build_ncurses(llvm_make, llvm_install) + llvm_libs.build_ncurses(llvm_make, llvm_install, build_utils.use_platform()) + build_config.LZMA_VERSION = build_utils.get_lzma_version() + if build_config.LZMA_VERSION is None: + raise Exception('Lzma version information not found, please check if the 7zVersion.h file exists') if build_config.enable_lzma_7zip: llvm_libs.build_lzma(llvm_make, llvm_install) if build_config.build_libedit: - llvm_libs.build_libedit(llvm_make, llvm_install) + llvm_libs.build_libedit(llvm_make, llvm_install, build_utils.use_platform()) build_config.LIBXML2_VERSION = build_utils.get_libxml2_version() if build_config.LIBXML2_VERSION is None: diff --git a/llvm-build/build_libedit.sh b/llvm-build/build_libedit.sh index 5d046197a8874edd4ee453928fa8e68c72edd108..becfc48fb9699fe4566d01d793114586b06f150d 100755 --- a/llvm-build/build_libedit.sh +++ b/llvm-build/build_libedit.sh @@ -10,6 +10,8 @@ LIBEDIT_INSTALL_PATH=$3 NCURSES_PATH=$4 PREBUILT_PATH=$5 CLANG_VERSION=$6 +TARGET=$7 +LIBEDIT_UNTAR_PATH=$8 # Get version and date form libedit.spec (Compatible with Linux and Mac) # The format in the libedit.spec is as follows: @@ -46,35 +48,61 @@ CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_ libedit_package=${LIBEDIT_SRC_DIR}/libedit-${DATE}-${LIBEDIT_VERSION}.tar.gz if [ -e ${libedit_package} ]; then - tar -xzvf ${libedit_package} --strip-components 1 -C ${LIBEDIT_SRC_DIR} + if [ ! -b ${LIBEDIT_UNTAR_PATH} ]; then + mkdir -p ${LIBEDIT_UNTAR_PATH} + fi + tar -xzvf ${libedit_package} --strip-components 1 -C ${LIBEDIT_UNTAR_PATH} + cd ${LIBEDIT_UNTAR_PATH} if [ ! -b ${LIBEDIT_BUILD_PATH} ]; then mkdir -p ${LIBEDIT_BUILD_PATH} fi + patches=($(grep -E '^Patch[0-9]+:' "${SPECFILE}" | sed 's/^[^:]*: *//')) + # Apply patches in order + for patch in "${patches[@]}" + do + patch -Np1 < ${LIBEDIT_SRC_DIR}/$patch + done # build libedit cd ${LIBEDIT_BUILD_PATH} - ldflags="-L${NCURSES_PATH}/lib" - ncuses_flags="-I${NCURSES_PATH}/include" - if [ "${host_platform}" = "darwin" ]; then - ncurses_libs="-Wl,-rpath,@loader_path/../lib:${NCURSES_PATH}/lib" - SDKROOT=$(xcrun --sdk macosx --show-sdk-path) - sdk_flags="-I${SDKROOT}/usr/include" - export LDFLAGS="$LDFLAGS $sdk_flags $ldflags $ncurses_libs" - export CFLAGS="$CFLAGS -isysroot$SDKROOT $ncuses_flags" - fi + ohos_suffix='-ohos' + if [[ ${TARGET} != *${ohos_suffix} ]]; then + ldflags="-L${NCURSES_PATH}/lib" + ncuses_flags="-I${NCURSES_PATH}/include" + if [ "${host_platform}" = "darwin" ]; then + ncurses_libs="-Wl,-rpath,@loader_path/../lib:${NCURSES_PATH}/lib" + SDKROOT=$(xcrun --sdk macosx --show-sdk-path) + sdk_flags="-I${SDKROOT}/usr/include" + export LDFLAGS="$LDFLAGS $sdk_flags $ldflags $ncurses_libs" + export CFLAGS="$CFLAGS -isysroot$SDKROOT $ncuses_flags" + fi - if [ "${host_platform}" = "linux" ]; then - ncurses_libs="-Wl,-rpath,\$$ORIGIN/../lib:${NCURSES_PATH}/lib" - export LDFLAGS="$LDFLAGS $ldflags $ncuses_flags $ncurses_libs" - export CFLAGS="$CFLAGS $ncuses_flags" - fi + if [ "${host_platform}" = "linux" ]; then + ncurses_libs="-Wl,-rpath,\$$ORIGIN/../lib:${NCURSES_PATH}/lib" + export LDFLAGS="$LDFLAGS $ldflags $ncuses_flags $ncurses_libs" + export CFLAGS="$CFLAGS $ncuses_flags" + fi - ${LIBEDIT_SRC_DIR}/configure \ - --prefix=${LIBEDIT_INSTALL_PATH} \ - CC=${CC_PATH} \ - CXX=${CXX_PATH} - make -j$(nproc --all) install | tee build_libedit.log + ${LIBEDIT_UNTAR_PATH}/configure \ + --prefix=${LIBEDIT_INSTALL_PATH} \ + CC=${CC_PATH} \ + CXX=${CXX_PATH} + make -j$(nproc --all) install | tee build_libedit.log + else + C_FLAGS="-I${NCURSES_PATH}/include/ -I${NCURSES_PATH}/include/ncurses -D__STDC_ISO_10646__=201103L -fPIC" + if [[ ${TARGET} =~ 'arm' ]]; then + C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" + fi + ${LIBEDIT_UNTAR_PATH}/configure \ + --prefix=${LIBEDIT_INSTALL_PATH} \ + --host="${TARGET}" \ + CC="${PREBUILT_PATH}/../out/llvm-install/bin/clang --target=${TARGET}" \ + CFLAGS="${C_FLAGS}" \ + LDFLAGS="-L${NCURSES_PATH}/lib" + + make -j$(nproc --all) install | tee build_libedit_${TARGET}.log + fi fi diff --git a/llvm-build/build_ncurses.sh b/llvm-build/build_ncurses.sh index df4f7b1ed45cf568f7c9e49d325186f0aa16b77e..e97163f64fb8cc3a14dc1aa5db5b643ac102ba3b 100755 --- a/llvm-build/build_ncurses.sh +++ b/llvm-build/build_ncurses.sh @@ -10,6 +10,8 @@ NCURSES_INSTALL_PATH=$3 PREBUILT_PATH=$4 CLANG_VERSION=$5 NCURSES_VERSION=$6 +TARGET=$7 +NCURSES_UNTAR_PATH=$8 SPECFILE="${NCURSES_SRC_DIR}/ncurses.spec" @@ -40,8 +42,11 @@ CXX_PATH=${PREBUILT_PATH}/clang/ohos/${host_platform}-${host_cpu}/clang-${CLANG_ ncurses_package=${NCURSES_SRC_DIR}/ncurses-${NCURSES_VERSION}.tar.gz if [ -e ${ncurses_package} ]; then - tar -xvzf ${ncurses_package} --strip-components 1 -C ${NCURSES_SRC_DIR} - cd ${NCURSES_SRC_DIR} + if [ ! -b ${NCURSES_UNTAR_PATH} ]; then + mkdir -p ${NCURSES_UNTAR_PATH} + fi + tar -xvzf ${ncurses_package} --strip-components 1 -C ${NCURSES_UNTAR_PATH} + cd ${NCURSES_UNTAR_PATH} # Get the list of patch files for ncurses.spec # The format in the ncurses.spec is as follows: @@ -52,7 +57,7 @@ if [ -e ${ncurses_package} ]; then # Apply patches in order for patch in "${patches[@]}" do - patch -Np1 < $patch + patch -Np1 < ${NCURSES_SRC_DIR}/$patch done if [ ! -b ${NCURSES_BUILD_PATH} ]; then @@ -60,31 +65,55 @@ if [ -e ${ncurses_package} ]; then fi cd ${NCURSES_BUILD_PATH} # build ncurses - if [ "${host_platform}" == "darwin" ]; then - export LDFLAGS="-Wl,-rpath,@loader_path/../lib" - SDKROOT=$(xcrun --sdk macosx --show-sdk-path) - flags="-Wl,-syslibroot,${SDKROOT}" - export CPPFLAGS="$CPPFALGS -I${SDKROOT}/usr/include -I${SDKROOT}/usr/include/i368" - export CFLAGS="$CFLAGS -isysroot${SDKROOT} $flags" + ohos_suffix='-ohos' + if [[ ${7} != *${ohos_suffix} ]]; then + if [ "${host_platform}" == "darwin" ]; then + export LDFLAGS="-Wl,-rpath,@loader_path/../lib" + SDKROOT=$(xcrun --sdk macosx --show-sdk-path) + flags="-Wl,-syslibroot,${SDKROOT}" + export CPPFLAGS="$CPPFALGS -I${SDKROOT}/usr/include -I${SDKROOT}/usr/include/i368" + export CFLAGS="$CFLAGS -isysroot${SDKROOT} $flags" + ${NCURSES_UNTAR_PATH}/configure \ + --with-shared \ + --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ + --disable-mixed-case \ + --prefix=${NCURSES_INSTALL_PATH} \ + CC=${CC_PATH} \ + CXX=${CXX_PATH} + make -j$(nproc --all) install | tee build_ncurses.log + fi + if [ "${host_platform}" == "linux" ]; then + export LDFLAGS="-Wl,-rpath,\$$ORIGIN/../lib" + ${NCURSES_UNTAR_PATH}/configure \ + --with-shared \ + --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ + --prefix=${NCURSES_INSTALL_PATH} \ + CC=${CC_PATH} \ + CXX=${CXX_PATH} + make -j$(nproc --all) install | tee build_ncurses.log + fi + else + C_FLAGS="--target=${TARGET} -fPIC" + if [[ ${TARGET} =~ 'arm' ]]; then + C_FLAGS="$C_FLAGS -march=armv7-a -mfloat-abi=soft" + fi + NCURSES_HOST_INSTALL_PATH=$9 + export LD_LIBRARY_PATH="${NCURSES_HOST_INSTALL_PATH}/lib:$LD_LIBRARY_PATH" ${NCURSES_SRC_DIR}/configure \ + --host="${TARGET}" \ --with-shared \ - --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ - --disable-mixed-case \ - --prefix=${NCURSES_INSTALL_PATH} \ - CC=${CC_PATH} \ - CXX=${CXX_PATH} - make -j$(nproc --all) install | tee build_ncurses.log - fi - if [ "${host_platform}" == "linux" ]; then - export LDFLAGS="-Wl,-rpath,\$$ORIGIN/../lib" - ${NCURSES_SRC_DIR}/configure \ - --with-shared \ - --with-default-terminfo-dir=/usr/lib/terminfo:/lib/terminfo:/usr/share/terminfo \ --prefix=${NCURSES_INSTALL_PATH} \ - CC=${CC_PATH} \ - CXX=${CXX_PATH} - make -j$(nproc --all) install | tee build_ncurses.log + --with-termlib \ + --without-manpages \ + --with-strip-program="${PREBUILT_PATH}/../out/llvm-install/bin/llvm-strip" \ + --with-fallbacks=linux,vt100,xterm \ + --with-tic-path=${NCURSES_HOST_INSTALL_PATH}/bin/tic \ + --with-infocmp-path=${NCURSES_HOST_INSTALL_PATH}/bin/infocmp \ + CC=${PREBUILT_PATH}/../out/llvm-install/bin/clang \ + CXX=${PREBUILT_PATH}/../out/llvm-install/bin/clang++ \ + CFLAGS="${C_FLAGS}" + make -j$(nproc --all) install | tee build_ncurses_${TARGET}.log fi fi diff --git a/llvm-build/ohos_toolchain_builder.py b/llvm-build/ohos_toolchain_builder.py new file mode 100644 index 0000000000000000000000000000000000000000..f8a586f90c9d71b30cd879ea811064cb19517cd0 --- /dev/null +++ b/llvm-build/ohos_toolchain_builder.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python3 +# Copyright (C) 2024 Huawei Device Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from typing import List +from build import BuildConfig, BuildUtils, LlvmLibs, SysrootComposer, LlvmPackage +from python_builder import OHOSPythonBuilder + + +class OHOSToolchainBuilder: + def __init__(self, llvm_triple) -> None: + self._llvm_triple = llvm_triple + self._platform = llvm_triple.split("-")[0] + self._build_config = BuildConfig() + self._build_utils = BuildUtils(self._build_config) + self._sysroot_composer = SysrootComposer(self._build_config) + self._llvm_package = LlvmPackage(self._build_config) + self._llvm_libs = LlvmLibs( + self._build_config, self._sysroot_composer, self._llvm_package + ) + self._python_builder = OHOSPythonBuilder(self._build_utils, self._llvm_triple) + self._llvm_project_path = os.path.abspath( + os.path.join(self._build_config.LLVM_PROJECT_DIR, "llvm") + ) + self._llvm_path = self._build_utils.merge_out_path(f"ohos-{self._platform}") + self._llvm_install = self._build_utils.merge_out_path( + f"ohos-{self._platform}-install" + ) + self._llvm_root = self._build_utils.merge_out_path("llvm-install") + self._sysroot = self._build_utils.merge_out_path("sysroot") + + self._cflags = self._init_cflags() + self._ldflags = self._init_ldflags() + self._llvm_defines = self._init_llvm_defines() + + def _init_cflags(self) -> List[str]: + cflags = [ + "-fstack-protector-strong", + "--target=%s" % self._llvm_triple, + "-ffunction-sections", + "-fdata-sections", + ] + return cflags + + def _init_ldflags(self) -> List[str]: + ldflags = [ + "-fuse-ld=lld", + "-Wl,--gc-sections", + "-Wl,--build-id=sha1", + "--rtlib=compiler-rt", + "-stdlib=libc++", + "-Wl,-z,relro,-z,now", + "-pie", + "-lunwind", + ] + return ldflags + + def _init_llvm_defines(self): + llvm_defines = {} + llvm_defines["LLVM_TARGET_ARCH"] = self._platform + llvm_defines["OHOS"] = "1" + llvm_defines["CMAKE_SYSTEM_NAME"] = "OHOS" + llvm_defines["CMAKE_CROSSCOMPILING"] = "True" + llvm_defines["CMAKE_INSTALL_PREFIX"] = self._llvm_install + llvm_defines["CMAKE_SYSROOT"] = self._sysroot + llvm_defines["LLVM_HOST_TRIPLE"] = self._llvm_triple + llvm_defines["LLVM_TARGETS_TO_BUILD"] = self._build_config.TARGETS + llvm_defines["LLVM_DEFAULT_TARGET_TRIPLE"] = self._llvm_triple + llvm_defines["LLVM_ENABLE_TERMINFO"] = "OFF" + llvm_defines["LLVM_CONFIG_PATH"] = os.path.join( + self._llvm_root, "bin", "llvm-config" + ) + llvm_defines["LLVM_TABLEGEN"] = os.path.join( + self._llvm_root, "bin", "llvm-tblgen" + ) + llvm_defines["CMAKE_C_COMPILER"] = os.path.join(self._llvm_root, "bin", "clang") + llvm_defines["CMAKE_CXX_COMPILER"] = os.path.join( + self._llvm_root, "bin", "clang++" + ) + llvm_defines["CMAKE_AR"] = os.path.join(self._llvm_root, "bin", "llvm-ar") + llvm_defines["CMAKE_FIND_ROOT_PATH_MODE_INCLUDE"] = "ONLY" + llvm_defines["CMAKE_FIND_ROOT_PATH_MODE_LIBRARY"] = "ONLY" + llvm_defines["CMAKE_FIND_ROOT_PATH_MODE_PACKAGE"] = "ONLY" + llvm_defines["CMAKE_FIND_ROOT_PATH_MODE_PROGRAM"] = "NEVER" + llvm_defines["Python3_EXECUTABLE"] = os.path.join( + self._build_utils.get_python_dir(), "bin", self._build_config.LLDB_PYTHON + ) + + if self._build_config.debug: + llvm_defines["CMAKE_BUILD_TYPE"] = "Debug" + else: + llvm_defines["CMAKE_BUILD_TYPE"] = "Release" + + llvm_defines.update(self._init_lldb_defines()) + + return llvm_defines + + def _init_lldb_defines(self): + lldb_defines = {} + lldb_defines["LLDB_INCLUDE_TESTS"] = "OFF" + if self._build_config.lldb_timeout: + lldb_defines["LLDB_ENABLE_TIMEOUT"] = "True" + # Optional Dependencies + if self._build_config.build_ncurses: + lldb_defines["LLDB_ENABLE_CURSES"] = "ON" + lldb_defines["CURSES_INCLUDE_DIRS"] = ";".join( + [ + self._build_utils.merge_ncurses_install_dir( + self._llvm_triple, "include" + ), + self._build_utils.merge_ncurses_install_dir( + self._llvm_triple, "include", "ncurses" + ), + ] + ) + ncurses_libs = [] + for library in self._build_utils.get_ncurses_dependence_libs(self._llvm_triple): + library_path = self._build_utils.merge_ncurses_install_dir( + self._llvm_triple, + "lib", + f"{library}.so.%s" % self._build_utils.get_ncurses_version(), + ) + ncurses_libs.append(library_path) + lldb_defines["CURSES_LIBRARIES"] = ";".join(ncurses_libs) + lldb_defines["PANEL_LIBRARIES"] = ";".join(ncurses_libs) + + if self._build_config.build_libxml2: + self._build_config.LIBXML2_VERSION = self._build_utils.get_libxml2_version() + + lldb_defines["LLDB_ENABLE_LIBXML2"] = "ON" + lldb_defines["LIBXML2_INCLUDE_DIR"] = ( + self._build_utils.merge_libxml2_install_dir( + self._llvm_triple, "include", "libxml2" + ) + ) + lldb_defines["LIBXML2_LIBRARY"] = ( + self._build_utils.merge_libxml2_install_dir( + self._llvm_triple, + "lib", + "libxml2.so.%s" % self._build_utils.get_libxml2_version(), + ) + ) + + if self._build_config.build_libedit: + lldb_defines["LLDB_ENABLE_LIBEDIT"] = "ON" + lldb_defines["LibEdit_INCLUDE_DIRS"] = ( + self._build_utils.merge_libedit_install_dir( + self._llvm_triple, "include" + ) + ) + lldb_defines["LibEdit_LIBRARIES"] = ( + self._build_utils.merge_libedit_install_dir( + self._llvm_triple, "lib", "libedit.so.0.0.68" + ) + ) + + if self._build_config.build_python: + lldb_defines["LLDB_ENABLE_PYTHON"] = "ON" + lldb_defines["LLDB_EMBED_PYTHON_HOME"] = "ON" + lldb_defines["LLDB_PYTHON_HOME"] = f"../{self._build_config.LLDB_PYTHON}" + lldb_defines["LLDB_PYTHON_RELATIVE_PATH"] = "bin/python/lib/python%s" % ( + self._build_config.LLDB_PY_VERSION + ) + lldb_defines["LLDB_PYTHON_EXE_RELATIVE_PATH"] = "bin/python" + lldb_defines["LLDB_PYTHON_EXT_SUFFIX"] = ".so" + lldb_defines["Python3_INCLUDE_DIRS"] = ( + self._build_utils.merge_python_install_dir( + self._llvm_triple, + "include", + f"python{self._build_config.LLDB_PY_VERSION}", + ) + ) + lldb_defines["Python3_LIBRARIES"] = self._build_utils.merge_python_install_dir( + self._llvm_triple, + "lib", + "libpython%s.so" % self._build_config.LLDB_PY_VERSION, + ) + + lldb_defines["LLDB_ENABLE_LZMA"] = "OFF" + # Debug & Tuning + if self._build_config.enable_monitoring: + lldb_defines["LLDB_ENABLE_PERFORMANCE"] = "ON" + + return lldb_defines + + def _build_and_install(self, build_target): + if self._build_config.build_ncurses: + self._llvm_libs.build_ncurses("", self._llvm_install, self._llvm_triple) + if self._build_config.build_libxml2: + self._llvm_libs.build_libxml2(self._llvm_triple, "", self._llvm_install) + if self._build_config.build_libedit: + self._llvm_libs.build_libedit("", self._llvm_install, self._llvm_triple) + if self._build_config.build_python: + self._python_builder.build() + + self._build_utils.invoke_cmake( + self._llvm_project_path, + self._llvm_path, + self._llvm_defines, + env=dict(self._build_config.ORIG_ENV), + ) + + self._build_utils.invoke_ninja( + out_path=self._llvm_path, + env=dict(self._build_config.ORIG_ENV), + target=build_target, + install=True, + ) + + if self._build_config.build_python: + self._python_builder.copy_python_to_host(self._llvm_install) + + # Copy required arm-linux-ohos libs from main toolchain build. + arch_list = [ + self._build_utils.liteos_triple("arm"), + self._build_utils.open_ohos_triple("arm"), + self._build_utils.open_ohos_triple("aarch64"), + self._build_utils.open_ohos_triple("riscv64"), + self._build_utils.open_ohos_triple("mipsel"), + self._build_utils.open_ohos_triple("x86_64"), + ] + for arch in arch_list: + self._build_utils.check_copy_tree( + os.path.join(self._llvm_root, "lib", arch), + os.path.join(self._llvm_install, "lib", arch), + ) + self._build_utils.check_copy_tree( + os.path.join(self._llvm_root, "lib", "clang", "15.0.4", "lib", arch), + os.path.join(self._llvm_install, "lib", "clang", "15.0.4", "lib", arch), + ) + + # Copy required c++ headerfiles from main toolchain build. + self._build_utils.check_copy_tree( + os.path.join(self._llvm_root, "include", "c++"), + os.path.join(self._llvm_install, "include", "c++"), + ) + self._build_utils.check_copy_tree( + os.path.join(self._llvm_root, "include", "libcxx-ohos"), + os.path.join(self._llvm_install, "include", "libcxx-ohos"), + ) + + def _package_if_need(self): + if self._build_config.do_package: + tarball_name = ( + f"clang-{self._build_config.build_name}-ohos-{self._platform}" + ) + package_path = "%s%s" % ( + self._build_utils.merge_packages_path(tarball_name), + self._build_config.ARCHIVE_EXTENSION, + ) + self._build_utils.logger().info("Packaging %s", package_path) + args = [ + "tar", + self._build_config.ARCHIVE_OPTION, + "-h", + "-C", + self._build_config.OUT_PATH, + "-f", + package_path, + f"ohos-{self._platform}-install", + ] + self._build_utils.check_create_dir(self._build_config.PACKAGES_PATH) + self._build_utils.check_call(args) + + # virtual function + def _update_build_args(self): + return + + def build(self, build_target=None): + self._update_build_args() + + self._build_and_install(build_target) + + self._package_if_need() diff --git a/llvm-build/python_builder.py b/llvm-build/python_builder.py index 7ca5426987ee9b781fbc404ec7765ab1d7bb0337..1663b59168753e7aedeff266b9e073f77d427566 100755 --- a/llvm-build/python_builder.py +++ b/llvm-build/python_builder.py @@ -18,28 +18,22 @@ import shutil import subprocess from typing import List, Mapping -class MinGWPythonBuilder: - target_platform = "x86_64-w64-mingw32" +class PythonBuilder: + target_platform = "" + patches = [] def __init__(self, build_config) -> None: - repo_root = Path(build_config.REPOROOT_DIR).resolve() + self.repo_root = Path(build_config.REPOROOT_DIR).resolve() self._out_dir = Path(build_config.OUT_PATH).resolve() self._clang_toolchain_dir = self._out_dir / 'llvm-install' - self._mingw_install_dir = self._out_dir / 'mingw' / build_config.MINGW_TRIPLE - self._source_dir = repo_root / 'third_party' / 'python' - self._build_dir = self._out_dir / 'python-windows-build' - self._install_dir = self._out_dir / 'python-windows-install' self._version = build_config.LLDB_PY_DETAILED_VERSION version_parts = self._version.split('.') self._major_version = version_parts[0] + '.' + version_parts[1] - # This file is used to detect whether patches are applied - self._mingw_ignore_file = self._source_dir / 'mingw_ignorefile.txt' + self._source_dir = self.repo_root / 'third_party' / 'python' self._patch_dir = self._source_dir / 'patches' + self._install_dir = "" - for directory in (self._clang_toolchain_dir, self._mingw_install_dir, - self._source_dir): - if not directory.is_dir(): - raise ValueError(f'No such directory "{directory}"') + self._clean_patches() @property def _logger(self) -> logging.Logger: @@ -49,6 +43,14 @@ class MinGWPythonBuilder: def _cc(self) -> Path: return self._clang_toolchain_dir/ 'bin' / 'clang' + @property + def _cflags(self) -> List[str]: + return [] + + @property + def _ldflags(self) -> List[str]: + return [] + @property def _cxx(self) -> Path: return self._clang_toolchain_dir / 'bin' / 'clang++' @@ -57,33 +59,13 @@ class MinGWPythonBuilder: def _strip(self) -> Path: return self._clang_toolchain_dir / 'bin' / 'llvm-strip' - @property - def _cflags(self) -> List[str]: - cflags = [ - f'-target {self.target_platform}', - f'--sysroot={self._mingw_install_dir}', - ] - return cflags - @property def _cxxflags(self) -> List[str]: return self._cflags.copy() - @property - def _ldflags(self) -> List[str]: - ldflags = [ - f'--sysroot={self._mingw_install_dir}', - f'-rtlib=compiler-rt', - f'-target {self.target_platform}', - f'-lucrt', - f'-lucrtbase', - f'-fuse-ld=lld', - ] - return ldflags - @property def _rcflags(self) -> List[str]: - return [ f'-I{self._mingw_install_dir}/include' ] + return [] @property def _env(self) -> Mapping[str, str]: @@ -104,26 +86,19 @@ class MinGWPythonBuilder: 'CXXFLAGS': ' '.join(self._cxxflags), 'LDFLAGS': ' '.join(self._ldflags), 'RCFLAGS': ' '.join(self._rcflags), + 'CPPFLAGS': ' '.join(self._cflags), }) return env def _configure(self) -> None: - subprocess.check_call(['autoreconf', '-vfi'], cwd=self._source_dir) - build_platform = subprocess.check_output( - ['./config.guess'], cwd=self._source_dir).decode().strip() - config_flags = [ - f'--prefix={self._install_dir}', - f'--build={build_platform}', - f'--host={self.target_platform}', - '--enable-shared', - '--without-ensurepip', - '--enable-loadable-sqlite-extensions', - ] - cmd = [str(self._source_dir / 'configure')] + config_flags - subprocess.check_call(cmd, env=self._env, cwd=self._build_dir) + return + + def _clean_patches(self) -> None: + subprocess.check_call(['git', 'reset', '--hard', 'HEAD'], cwd=self._source_dir) + subprocess.check_call(['git', 'clean', '-df'], cwd=self._source_dir) def _pre_build(self) -> None: - if self._mingw_ignore_file.is_file(): + if self._patch_ignore_file.is_file(): self._logger.warning('Patches for Python have being applied, skip patching') return @@ -132,7 +107,7 @@ class MinGWPythonBuilder: return for patch in self._patch_dir.iterdir(): - if patch.is_file(): + if patch.is_file() and patch.name in self.patches: cmd = [ 'git', 'apply', str(patch) ] subprocess.check_call(cmd, cwd=self._source_dir) @@ -142,8 +117,8 @@ class MinGWPythonBuilder: shutil.rmtree(self._build_dir) if self._install_dir.exists(): shutil.rmtree(self._install_dir) - self._build_dir.mkdir() - self._install_dir.mkdir() + self._build_dir.mkdir(parents=True) + self._install_dir.mkdir(parents=True) self._configure() self._install() @@ -194,6 +169,70 @@ class MinGWPythonBuilder: for cache_dir in pycaches: shutil.rmtree(cache_dir) + @property + def install_dir(self) -> str: + return str(self._install_dir) + + +class MinGWPythonBuilder(PythonBuilder): + def __init__(self, build_config) -> None: + super().__init__(build_config) + + self.target_platform = "x86_64-w64-mingw32" + self.patches = ["cpython_mingw_v3.10.2.patch"] + + self._mingw_install_dir = self._out_dir / 'mingw' / build_config.MINGW_TRIPLE + self._build_dir = self._out_dir / 'python-windows-build' + self._install_dir = self._out_dir / 'python-windows-install' + + # This file is used to detect whether patches are applied + self._patch_ignore_file = self._source_dir / 'mingw_ignorefile.txt' + + + for directory in (self._clang_toolchain_dir, self._mingw_install_dir, + self._source_dir): + if not directory.is_dir(): + raise ValueError(f'No such directory "{directory}"') + + @property + def _cflags(self) -> List[str]: + cflags = [ + f'-target {self.target_platform}', + f'--sysroot={self._mingw_install_dir}', + ] + return cflags + + @property + def _ldflags(self) -> List[str]: + ldflags = [ + f'--sysroot={self._mingw_install_dir}', + f'-rtlib=compiler-rt', + f'-target {self.target_platform}', + f'-lucrt', + f'-lucrtbase', + f'-fuse-ld=lld', + ] + return ldflags + + @property + def _rcflags(self) -> List[str]: + return [ f'-I{self._mingw_install_dir}/include' ] + + def _configure(self) -> None: + subprocess.check_call(['autoreconf', '-vfi'], cwd=self._source_dir) + build_platform = subprocess.check_output( + ['./config.guess'], cwd=self._source_dir).decode().strip() + config_flags = [ + f'--prefix={self._install_dir}', + f'--build={build_platform}', + f'--host={self.target_platform}', + '--enable-shared', + '--without-ensurepip', + '--enable-loadable-sqlite-extensions', + ] + cmd = [str(self._source_dir / 'configure')] + config_flags + subprocess.check_call(cmd, env=self._env, cwd=self._build_dir) + def prepare_for_package(self) -> None: self._clean_bin_dir() self._clean_share_dir() @@ -215,6 +254,71 @@ class MinGWPythonBuilder: ] + [ f.name for f in self._install_dir.iterdir() ] subprocess.check_call(cmd, cwd=self._install_dir) + +class OHOSPythonBuilder(PythonBuilder): + def __init__(self, build_utils, target_platform) -> None: + super().__init__(build_utils.build_config) + + self.target_platform = target_platform + self.patches = ["cross_compile_support_ohos.patch"] + + self._build_dir = Path(build_utils.merge_python_build_dir(target_platform)) + self._install_dir = Path(build_utils.merge_python_install_dir(target_platform)) + + # This file is used to detect whether patches are applied + self._patch_ignore_file = self._source_dir / 'support_ohos_ignorefile.txt' + + self.build_utils = build_utils + return + @property - def install_dir(self) -> str: - return str(self._install_dir) + def _cflags(self) -> List[str]: + cflags = [ + f'--target={self.target_platform}', + '-nostdinc', + '-I%s' % str(self._out_dir / 'sysroot' / self.target_platform / 'usr' / 'include'), + ] + if str(self.target_platform).find("arm") > 0: + cflags.append('-march=armv7-a -mfloat-abi=soft') + return cflags + + @property + def _ldflags(self) -> List[str]: + ldflags = [ + f'-rtlib=compiler-rt', + f'--target={self.target_platform}', + f'-fuse-ld=lld', + '-L%s' % str(self._out_dir / 'sysroot' / self.target_platform / 'usr' / 'lib'), + '-lc', + '-Wl,-rpath,\\$$ORIGIN/../lib', + ] + return ldflags + + def _configure(self) -> None: + subprocess.check_call(['autoreconf', '-vfi'], cwd=self._source_dir) + build_platform = subprocess.check_output( + ['./config.guess'], cwd=self._source_dir).decode().strip() + config_flags = [ + f'--prefix={self._install_dir}', + f'--build={build_platform}', + f'--host={self.target_platform}', + '--enable-shared', + '--without-ensurepip', + '--enable-loadable-sqlite-extensions', + '--disable-ipv6', + 'ac_cv_file__dev_ptmx=no', + 'ac_cv_file__dev_ptc=no', + '--without-system-ffi', + '--enable-optimizations', + '--without-pydebug', + '--without-doc-strings', + '--without-dtrace', + ] + cmd = [str(self._source_dir / 'configure')] + config_flags + subprocess.check_call(cmd, env=self._env, cwd=self._build_dir) + + def copy_python_to_host(self, install_dir): + libpython = f'libpython{self.build_utils.build_config.LLDB_PY_VERSION}.so.1.0' + + shutil.copyfile(os.path.join(self._install_dir, "lib", libpython), os.path.join(install_dir, 'lib', libpython)) + self.build_utils.check_copy_tree(self._install_dir, os.path.join(install_dir, self.build_utils.build_config.LLDB_PYTHON)) diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst index 50c5bf88ec13042745ac75c6ef65fc9166d0dd1c..cae33b3bb7048c5a3e88ff29a28d36692e2483ad 100644 --- a/llvm/docs/BitCodeFormat.rst +++ b/llvm/docs/BitCodeFormat.rst @@ -807,9 +807,10 @@ function. The operand fields are: * ``arkfast3cc`` : code 25 * ``arkfast4cc`` : code 26 * ``arkfast5cc`` : code 27 - * ``arkmethodcc`` : code 28 - * ``arkresolvercc`` : code 29 - * ``arkpltcc`` : code 30 + * ``arkfast6cc`` : code 28 + * ``arkmethodcc`` : code 29 + * ``arkresolvercc`` : code 30 + * ``arkpltcc`` : code 31 .. OHOS_LOCAL end * ``x86_stdcallcc``: code 64 * ``x86_fastcallcc``: code 65 diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index e3cc48d7e9ca8ae1767c52678b2ce518da390580..060a765b9f091f1ac552fdd7900fddc0938aadc4 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -473,6 +473,8 @@ added in the future: Ark Itroc calling convention for FastPath handlers with four arguments "``arkfast5cc``" Ark Itroc calling convention for FastPath handlers with five arguments +"``arkfast6cc``" + Ark Itroc calling convention for FastPath handlers with six arguments "``arkmethodcc``" Ark AOT method calling convention with frame adaptation "``arkresolvercc``" diff --git a/llvm/include/llvm/AsmParser/LLToken.h b/llvm/include/llvm/AsmParser/LLToken.h index a0cb5168ed716d0415f5574e7aff1cece1de5bac..fe0e3f3a0460005dba4807c25e74aeec94cd57df 100644 --- a/llvm/include/llvm/AsmParser/LLToken.h +++ b/llvm/include/llvm/AsmParser/LLToken.h @@ -179,6 +179,7 @@ enum Kind { kw_arkfast3cc, kw_arkfast4cc, kw_arkfast5cc, + kw_arkfast6cc, kw_arkmethodcc, kw_arkresolvercc, kw_arkpltcc, diff --git a/llvm/include/llvm/BinaryFormat/ADLTSection.h b/llvm/include/llvm/BinaryFormat/ADLTSection.h index 073f24573768b362940f0f249d28de995a22ed26..6d57903cdd09deae23b0790d0db0237e8b032713 100644 --- a/llvm/include/llvm/BinaryFormat/ADLTSection.h +++ b/llvm/include/llvm/BinaryFormat/ADLTSection.h @@ -36,81 +36,81 @@ 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; +typedef uint8_t Elf64_Byte; #endif // _ELF_H typedef struct { - Elf64_Word secIndex; - Elf64_Off offset; // from section start + 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 + 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 + 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 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; + 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 + 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_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 + 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_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_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 char adltBlobStartMark[4] = {0xA, 0xD, 0x1, 0x7}; static const adlt_semver_t adltSchemaVersion = {1, 1, 0}; diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h index d060bda15a32cf9529b74f639643d21feff56f91..6a12c647f79fb4855b8925e65c4306412b9a3948 100644 --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -1391,7 +1391,8 @@ enum { PT_OPENBSD_BOOTDATA = 0x65a41be6, // Section for boot arguments. PT_OHOS_RANDOMDATA = 0x6788FC60, // Fill with random data. OHOS_LOCAL - PT_ADLT = 0x6788FC61, // Adlt information. + // OHOS_LOCAL + PT_ADLT = 0x6788FC61, // Adlt information. // ARM program header types. PT_ARM_ARCHEXT = 0x70000000, // Platform architecture compatibility info diff --git a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h index 04369a5bfe0d563a8fb2931211c25224915380c5..c70fe7ce07cf6dc95281a6facf2fbae6906e5a74 100644 --- a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h @@ -23,6 +23,7 @@ #include "llvm/IR/CallingConv.h" #include "llvm/MC/LaneBitmask.h" #include "llvm/MC/MCRegisterInfo.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MachineValueType.h" #include "llvm/Support/MathExtras.h" @@ -30,6 +31,8 @@ #include #include +extern llvm::cl::opt SpillSlotMinSize; // OHOS_LOCAL + namespace llvm { class BitVector; @@ -287,7 +290,13 @@ public: /// Return the minimum required alignment in bytes for a spill slot for /// a register of this class. Align getSpillAlign(const TargetRegisterClass &RC) const { - return Align(getRegClassInfo(RC).SpillAlignment / 8); + // OHOS_LOCAL begin + auto align = getRegClassInfo(RC).SpillAlignment / 8; + if (align < SpillSlotMinSize) { + align = SpillSlotMinSize; + } + return Align(align); + // OHOS_LOCAL end } /// Return true if the given TargetRegisterClass has the ValueType T. diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h index 3221e5c9541d6e8c7d19d89829288f9053a63c3c..586ec1519840d380ff9effef914b0090936f54ca 100644 --- a/llvm/include/llvm/IR/CallingConv.h +++ b/llvm/include/llvm/IR/CallingConv.h @@ -115,14 +115,17 @@ namespace CallingConv { // Ark Itroc calling convention for FastPath handlers with five arguments ArkFast5 = 27, + // Ark Itroc calling convention for FastPath handlers with six arguments + ArkFast6 = 28, + // Ark AOT method calling convention with frame adaptation - ArkMethod = 28, + ArkMethod = 29, // Ark AOT calling convention for special class resolvers - ArkResolver = 29, + ArkResolver = 30, // Ark AOT calling convention for static calls through special PLT resolver - ArkPlt = 30, + ArkPlt = 31, // OHOS_LOCAL end // Target - This is the start of the target-specific calling conventions, diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp index a77f77c8e91ea0d3dd2970087262345f0cf4398c..509cda0cc738b252f2f1d8b248392ba59b35a418 100644 --- a/llvm/lib/AsmParser/LLLexer.cpp +++ b/llvm/lib/AsmParser/LLLexer.cpp @@ -637,6 +637,7 @@ lltok::Kind LLLexer::LexIdentifier() { KEYWORD(arkfast3cc); KEYWORD(arkfast4cc); KEYWORD(arkfast5cc); + KEYWORD(arkfast6cc); KEYWORD(arkmethodcc); KEYWORD(arkresolvercc); KEYWORD(arkpltcc); diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 6f270e0db471d82dd3677e8ac60cfc6cc54cef26..30b0d917b696e3ad09fb6473567122f7c44175fc 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1912,6 +1912,7 @@ void LLParser::parseOptionalDLLStorageClass(unsigned &Res) { /// ::= 'arkfast3cc' /// ::= 'arkfast4cc' /// ::= 'arkfast5cc' +/// ::= 'arkfast6cc' /// ::= 'arkmethodcc' /// ::= 'arkresolvercc' /// ::= 'arkpltcc' @@ -1976,6 +1977,7 @@ bool LLParser::parseOptionalCallingConv(unsigned &CC) { case lltok::kw_arkfast3cc: CC = CallingConv::ArkFast3; break; case lltok::kw_arkfast4cc: CC = CallingConv::ArkFast4; break; case lltok::kw_arkfast5cc: CC = CallingConv::ArkFast5; break; + case lltok::kw_arkfast6cc: CC = CallingConv::ArkFast6; break; case lltok::kw_arkmethodcc: CC = CallingConv::ArkMethod; break; case lltok::kw_arkresolvercc: CC = CallingConv::ArkResolver; break; case lltok::kw_arkpltcc: CC = CallingConv::ArkPlt; break; diff --git a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp index 961707a7fc9ecc5e59d4ce93c85c3b40e0aa6ed0..f047e80cd62f34bf050f10e331003d4712588022 100644 --- a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp @@ -78,14 +78,6 @@ cl::opt MaxRegistersForGCPointers( "max-registers-for-gc-values", cl::Hidden, cl::init(0), cl::desc("Max number of VRegs allowed to pass GC pointer meta args in")); -// OHOS_LOCAL begin -// Useful when gc managed references are 32-bit wide but runtime supports only -// 64-bit slots -cl::opt SpillSlotMinSize("spill-slot-min-size-bytes", cl::Hidden, - cl::init(1), - cl::desc("Minimum size of a spill slot")); -// OHOS_LOCAL end - typedef FunctionLoweringInfo::StatepointRelocationRecord RecordType; static void pushStackMapConstant(SmallVectorImpl& Ops, @@ -719,6 +711,11 @@ lowerStatepointMetaArgs(SmallVectorImpl &Ops, return !willLowerDirectly(SD); }; + // OHOS_LOCAL begin + auto StatepointInst = dyn_cast_or_null(SI.StatepointInstr); + auto AssignedArkSlots = tryAssignStackSlots(Builder, StatepointInst); + // OHOS_LOCAL end + auto processGCPtr = [&](const Value *V) { SDValue PtrSD = Builder.getValue(V); if (!LoweredGCPtrs.insert(PtrSD)) @@ -726,6 +723,10 @@ lowerStatepointMetaArgs(SmallVectorImpl &Ops, GCNodeToGCValue[PtrSD] = V; // OHOS_LOCAL GCPtrIndexMap[PtrSD] = LoweredGCPtrs.size() - 1; + // OHOS_LOCAL begin + if (AssignedArkSlots.count(V)) + return; // we need to assign these to stack + // OHOS_LOCAL end assert(!LowerAsVReg.count(PtrSD) && "must not have been seen"); if (LowerAsVReg.size() == MaxVRegPtrs) return; @@ -756,11 +757,6 @@ lowerStatepointMetaArgs(SmallVectorImpl &Ops, return !(LiveInDeopt || UseRegistersForDeoptValues); }; - // OHOS_LOCAL begin - auto StatepointInst = dyn_cast_or_null(SI.StatepointInstr); - auto AssignedArkSlots = tryAssignStackSlots(Builder, StatepointInst); - // OHOS_LOCAL end - // Before we actually start lowering (and allocating spill slots for values), // reserve any stack slots which we judge to be profitable to reuse for a // particular value. This is purely an optimization over the code below and diff --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp index ac346585b0f8fc82d97a263bf0e445cabf710c36..77e6c923e0364a41895ba312764a06fa08ebf452 100644 --- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp +++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp @@ -50,6 +50,14 @@ static cl::opt "high compile time cost in global splitting."), cl::init(5000)); +// OHOS_LOCAL begin +// Useful when gc managed references are 32-bit wide but runtime supports only +// 64-bit slots +cl::opt SpillSlotMinSize( + "spill-slot-min-size-bytes", cl::Hidden, cl::init(1), + cl::desc("Minimum size and alignment of a spill slot")); +// OHOS_LOCAL end + TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterInfoDesc *ID, regclass_iterator RCB, regclass_iterator RCE, const char *const *SRINames, diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index cc5e4f58671634e5e7db24000df1ad90d9cb03d1..2d6bb345e465d2aa3ab05b87767d12cc57881366 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -305,6 +305,7 @@ static void PrintCallingConv(unsigned cc, raw_ostream &Out) { case CallingConv::ArkFast3: Out << "arkfast3cc"; break; case CallingConv::ArkFast4: Out << "arkfast4cc"; break; case CallingConv::ArkFast5: Out << "arkfast5cc"; break; + case CallingConv::ArkFast6: Out << "arkfast6cc"; break; case CallingConv::ArkMethod: Out << "arkmethodcc"; break; case CallingConv::ArkResolver: Out << "arkresolvercc"; break; case CallingConv::ArkPlt: Out << "arkpltcc"; break; diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index e31faf6422eddb7daecec957c3a1d9c4fb5b0a76..ab960e021d4da11be65607ad3b1cca03f072b58e 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/lib/Target/AArch64/AArch64ArkGcCallingConvention.td b/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td index 5485ac4c90da1d0b6242294ef40e35aebd688eab..1ace7ab7f19b79ed576171009a58cb9d79c04592 100644 --- a/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td +++ b/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td @@ -355,6 +355,13 @@ def CC_AArch64_ArkFast5 : CallingConv<[ CCIfType<[i64], CCAssignToRegWithShadow<[X0, X1, X2, X3, X4, X28, FP], [W0, W1, W2, W3, W4, W28, W29]>>, ]>; +let Entry = 1 in +def CC_AArch64_ArkFast6 : CallingConv<[ + CCIfType<[i1, i8, i16], CCPromoteToType>, + CCIfType<[i32], CCAssignToRegWithShadow<[W0, W1, W2, W3, W4, W5, W28, W29], [X0, X1, X2, X3, X4, X5, X28, FP]>>, + CCIfType<[i64], CCAssignToRegWithShadow<[X0, X1, X2, X3, X4, X5, X28, FP], [W0, W1, W2, W3, W4, W5, W28, W29]>>, +]>; + let Entry = 1 in def CC_AArch64_ArkResolver : CallingConv<[ CCIfType<[i1, i8, i16], CCPromoteToType>, @@ -504,9 +511,12 @@ def CSR_AArch64_StackProbe_Windows // OHOS_LOCAL begin def CSR_AArch64_ArkInt : CalleeSavedRegs<(add FP)>; -def CSR_AArch64_ArkFast5 - : CalleeSavedRegs<(add (sub (sequence "X%u", 5, 27), X16, X17), LR, +def CSR_AArch64_ArkFast6 + : CalleeSavedRegs<(add (sub (sequence "X%u", 6, 27), X16, X17), LR, (sequence "D%u", 0, 29))>; +def CSR_AArch64_ArkFast5 + : CalleeSavedRegs<(add CSR_AArch64_ArkFast6, X5)>; + def CSR_AArch64_ArkFast4 : CalleeSavedRegs<(add CSR_AArch64_ArkFast5, X4)>; diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.h b/llvm/lib/Target/AArch64/AArch64CallingConvention.h index 90e8be6eeee02a6cab6c72f11c4955bf0b499944..5af6876f85ba8287ab649f3fe62c56067c9a5457 100644 --- a/llvm/lib/Target/AArch64/AArch64CallingConvention.h +++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.h @@ -62,6 +62,9 @@ bool CC_AArch64_ArkFast4(unsigned ValNo, MVT ValVT, MVT LocVT, bool CC_AArch64_ArkFast5(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State); +bool CC_AArch64_ArkFast6(unsigned ValNo, MVT ValVT, MVT LocVT, + CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, + CCState &State); // OHOS_LOCAL end bool CC_AArch64_GHC(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.td b/llvm/lib/Target/AArch64/AArch64CallingConvention.td index 0094ee3e31290bd4f38376d2cda06c74e441a4b3..78e82cb3cc4d3a1d7c949e09d4e7aaa6efb1ceb3 100644 --- a/llvm/lib/Target/AArch64/AArch64CallingConvention.td +++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.td @@ -355,6 +355,13 @@ def CC_AArch64_ArkFast5 : CallingConv<[ CCIfType<[i64], CCAssignToRegWithShadow<[X0, X1, X2, X3, X4, X28, FP], [W0, W1, W2, W3, W4, W28, W29]>>, ]>; +let Entry = 1 in +def CC_AArch64_ArkFast6 : CallingConv<[ + CCIfType<[i1, i8, i16], CCPromoteToType>, + CCIfType<[i32], CCAssignToRegWithShadow<[W0, W1, W2, W3, W4, W5, W28, W29], [X0, X1, X2, X3, X4, X5, X28, FP]>>, + CCIfType<[i64], CCAssignToRegWithShadow<[X0, X1, X2, X3, X4, X5, X28, FP], [W0, W1, W2, W3, W4, W5, W28, W29]>>, +]>; + let Entry = 1 in def CC_AArch64_ArkResolver : CallingConv<[ CCIfType<[i1, i8, i16], CCPromoteToType>, @@ -503,9 +510,12 @@ def CSR_AArch64_StackProbe_Windows // OHOS_LOCAL begin def CSR_AArch64_ArkInt : CalleeSavedRegs<(add FP)>; -def CSR_AArch64_ArkFast5 - : CalleeSavedRegs<(add (sub (sequence "X%u", 5, 27), X16, X17), LR, +def CSR_AArch64_ArkFast6 + : CalleeSavedRegs<(add (sub (sequence "X%u", 6, 27), X16, X17), LR, (sequence "D%u", 0, 29))>; +def CSR_AArch64_ArkFast5 + : CalleeSavedRegs<(add CSR_AArch64_ArkFast6, X5)>; + def CSR_AArch64_ArkFast4 : CalleeSavedRegs<(add CSR_AArch64_ArkFast5, X4)>; diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp index 8856fe0ea5554f1bd17287b66a852da6b0b726fd..43ee70edcd2346fd76e5f85164a8fc163c3d13fa 100644 --- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp @@ -1525,7 +1525,8 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF, MF.getFunction().getCallingConv() == CallingConv::ArkFast2 || MF.getFunction().getCallingConv() == CallingConv::ArkFast3 || MF.getFunction().getCallingConv() == CallingConv::ArkFast4 || - MF.getFunction().getCallingConv() == CallingConv::ArkFast5)) { + MF.getFunction().getCallingConv() == CallingConv::ArkFast5 || + MF.getFunction().getCallingConv() == CallingConv::ArkFast6)) { report_fatal_error( "Implicit use of FP is forbidden for ArkFast conventions!"); } diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index a98f763143feec186b0ff2848b133c14925dea17..d742d87eca22abe737846dd3ce95b3a53d0fef7f 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -5750,6 +5750,8 @@ CCAssignFn *AArch64TargetLowering::CCAssignFnForCall(CallingConv::ID CC, return CC_AArch64_ArkFast4; case CallingConv::ArkFast5: return CC_AArch64_ArkFast5; + case CallingConv::ArkFast6: + return CC_AArch64_ArkFast6; case CallingConv::ArkResolver: return CC_AArch64_ArkResolver; // OHOS_LOCAL end @@ -6269,6 +6271,7 @@ static bool mayTailCallThisCC(CallingConv::ID CC) { case CallingConv::ArkFast3: case CallingConv::ArkFast4: case CallingConv::ArkFast5: + case CallingConv::ArkFast6: // OHOS_LOCAL end return true; default: diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp index 49c45cec1e911469029559c5a30c6f656d14a7b5..abcc0f749e6c15e6097620e847b6f487da9ff7ec 100644 --- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp @@ -89,6 +89,8 @@ AArch64RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { return CSR_AArch64_ArkFast4_SaveList; if (MF->getFunction().getCallingConv() == CallingConv::ArkFast5) return CSR_AArch64_ArkFast5_SaveList; + if (MF->getFunction().getCallingConv() == CallingConv::ArkFast6) + return CSR_AArch64_ArkFast6_SaveList; if (MF->getFunction().getCallingConv() == CallingConv::ArkMethod) return CSR_AArch64_ArkMethod_SaveList; // OHOS_LOCAL end @@ -245,6 +247,8 @@ AArch64RegisterInfo::getCallPreservedMask(const MachineFunction &MF, return CSR_AArch64_ArkFast4_RegMask; if (CC == CallingConv::ArkFast5) return CSR_AArch64_ArkFast5_RegMask; + if (CC == CallingConv::ArkFast6) + return CSR_AArch64_ArkFast6_RegMask; if (CC == CallingConv::ArkMethod) return CSR_AArch64_ArkMethod_RegMask; // OHOS_LOCAL end diff --git a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp index 5c3a2ee63d56d3d90f93063ce7e49faf3b2f6184..ff597e6605b01d46e7d20dc697ba8513c6678f9b 100644 --- a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp @@ -693,6 +693,7 @@ static bool mayTailCallThisCC(CallingConv::ID CC) { case CallingConv::ArkFast3: case CallingConv::ArkFast4: case CallingConv::ArkFast5: + case CallingConv::ArkFast6: // OHOS_LOCAL end return true; default: diff --git a/llvm/lib/Target/X86/X86CallingConv.td b/llvm/lib/Target/X86/X86CallingConv.td index 10f3ed29105f8c1f9e159d7e667c2dd113ef5ca4..43c8e5cd68ae7f69e58f5b05259aeea6b416e65b 100644 --- a/llvm/lib/Target/X86/X86CallingConv.td +++ b/llvm/lib/Target/X86/X86CallingConv.td @@ -505,6 +505,7 @@ def RetCC_X86_64 : CallingConv<[ CCIfCC<"CallingConv::ArkFast3", CCDelegateTo>, CCIfCC<"CallingConv::ArkFast4", CCDelegateTo>, CCIfCC<"CallingConv::ArkFast5", CCDelegateTo>, + CCIfCC<"CallingConv::ArkFast6", CCDelegateTo>, CCIfCC<"CallingConv::ArkMethod", CCDelegateTo>, CCIfCC<"CallingConv::ArkResolver", CCDelegateTo>, // OHOS_LOCAL end @@ -804,6 +805,10 @@ def CC_X86_64_ARK_FAST_5 : CallingConv<[ CCIfType<[i1, i8, i16, i32], CCPromoteToType>, CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8, R15, RBP]>> ]>; +def CC_X86_64_ARK_FAST_6 : CallingConv<[ + CCIfType<[i1, i8, i16, i32], CCPromoteToType>, + CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8, R9, R15, RBP]>> +]>; def CC_X86_64_ARK_RESOLVER : CallingConv<[ CCIfType<[i1, i8, i16, i32], CCPromoteToType>, @@ -1171,6 +1176,7 @@ def CC_X86_64 : CallingConv<[ CCIfCC<"CallingConv::ArkFast3", CCDelegateTo>, CCIfCC<"CallingConv::ArkFast4", CCDelegateTo>, CCIfCC<"CallingConv::ArkFast5", CCDelegateTo>, + CCIfCC<"CallingConv::ArkFast6", CCDelegateTo>, CCIfCC<"CallingConv::ArkMethod", CCDelegateTo>, CCIfCC<"CallingConv::ArkResolver", CCDelegateTo>, // OHOS_LOCAL end @@ -1306,9 +1312,9 @@ def CSR_ArkFast2 : CalleeSavedRegs<(sub CSR_ArkFast1, RSI)>; def CSR_ArkFast3 : CalleeSavedRegs<(sub CSR_ArkFast2, RDX)>; def CSR_ArkFast4 : CalleeSavedRegs<(sub CSR_ArkFast3, RCX)>; def CSR_ArkFast5 : CalleeSavedRegs<(sub CSR_ArkFast4, R8)>; +def CSR_ArkFast6 : CalleeSavedRegs<(sub CSR_ArkFast5, R9)>; def CSR_ArkMethod : CalleeSavedRegs<(add RBP)>; -// R12, R13, R14 may be used as temp registers. But we tight only really used temps. -def CSR_ArkResolver : CalleeSavedRegs<(sub CSR_64, R12, R13)>; -def CSR_ArkPlt : CalleeSavedRegs<(sub CSR_64, R12)>; +def CSR_ArkResolver : CalleeSavedRegs<(sub CSR_64, R12, R13, R14)>; +def CSR_ArkPlt : CalleeSavedRegs<(sub CSR_64, R12, R13, R14)>; // OHOS_LOCAL end diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 72eb76ae021203167e81ea08c3537d78f10310bf..3f8336b2590046f733ef3dbee4aa3c0f8f2343d2 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -3618,6 +3618,7 @@ static bool mayTailCallThisCC(CallingConv::ID CC) { case CallingConv::ArkFast3: case CallingConv::ArkFast4: case CallingConv::ArkFast5: + case CallingConv::ArkFast6: return true; // OHOS_LOCAL end default: diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp index f6f92bddeff6f9cc50f0c3b7df6ed198cd8a8484..6b0738266b62c2c1dd91023db245215b9a922fcb 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.cpp +++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp @@ -313,6 +313,8 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { return CSR_ArkFast4_SaveList; case CallingConv::ArkFast5: return CSR_ArkFast5_SaveList; + case CallingConv::ArkFast6: + return CSR_ArkFast6_SaveList; case CallingConv::ArkMethod: return CSR_ArkMethod_SaveList; case CallingConv::ArkResolver: @@ -458,6 +460,8 @@ X86RegisterInfo::getCallPreservedMask(const MachineFunction &MF, return CSR_ArkFast4_RegMask; case CallingConv::ArkFast5: return CSR_ArkFast5_RegMask; + case CallingConv::ArkFast6: + return CSR_ArkFast6_RegMask; case CallingConv::ArkMethod: return CSR_ArkMethod_RegMask; case CallingConv::ArkResolver: diff --git a/llvm/test/CodeGen/AArch64/implicit-null-check.ll b/llvm/test/CodeGen/AArch64/implicit-null-check.ll index 59bbfda757c8d8038de7dc7b8c09184cb57b5b91..5ed33a622439c607c33226c7f686663c4b1f1fec 100644 --- a/llvm/test/CodeGen/AArch64/implicit-null-check.ll +++ b/llvm/test/CodeGen/AArch64/implicit-null-check.ll @@ -436,12 +436,12 @@ define i32 @imp_null_check_neg_gep_load(i32* %x) { ;; The test must be fixed, when such is introduced define i64 @imp_null_check_load_pair(i64* %array) { ; CHECK-LABEL: imp_null_check_load_pair: -; CHECK: // %bb.0: // %entry -; CHECK-NEXT: cbz x0, .LBB17_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldp x8, x9, [x0] -; CHECK-NEXT: add x0, x9, x8 -; CHECK-NEXT: .LBB17_2: // %return +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: cbz x0, .LBB17_2 +; CHECK-NEXT: // %bb.1: // %if.end +; CHECK-NEXT: ldp x8, x9, [x0] +; CHECK-NEXT: add x0, x9, x8 +; CHECK-NEXT: .LBB17_2: // %return ; CHECK-NEXT: ret entry: %cmp = icmp eq i64* %array, null diff --git a/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll b/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll index dcecc92d5b7085fd27adf7840b2ecbe2adae84b1..fc15558caccc7844bfe53219411ab39affd802b3 100644 --- a/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll +++ b/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll @@ -3,18 +3,15 @@ target triple = "aarch64-unknown-linux-gnu" ; CHECK-LABEL: LoadI32FromPtr32: -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: -; CHECK-NEXT: str x30, [sp, #-16]! -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp0: -; CHECK-NEXT: ldr w0, [x0, #16] -; CHECK-NEXT: // %bb.1: -; CHECK-NEXT: ldr x30, [sp], #16 -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB0_2: -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp0: +; CHECK-NEXT: ldr w0, [x0, #16] // on-fault: .LBB0_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB0_2: +; CHECK-NEXT: bl ThrowNullPointerException define i32 @LoadI32FromPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -32,18 +29,15 @@ if.end: } ; CHECK-LABEL: LoadFloatFromPtr32: -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: -; CHECK-NEXT: str x30, [sp, #-16]! -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp1: -; CHECK-NEXT: ldr s0, [x0, #16] +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp1: +; CHECK-NEXT: ldr s0, [x0, #16] // on-fault: .LBB1_2 ; CHECK-NEXT: // %bb.1: -; CHECK-NEXT: ldr x30, [sp], #16 -; CHECK-NEXT: ret +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret ; CHECK-NEXT: .LBB1_2: -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-NEXT: bl ThrowNullPointerException define float @LoadFloatFromPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -61,18 +55,15 @@ if.end: ; preds = %entry } ; CHECK-LABEL: LoadDoubleFromPtr32: -; CHECK: .cfi_startproc -; CHECK: // %bb.0: // %entry -; CHECK: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK: .cfi_def_cfa_offset 16 -; CHECK: .cfi_offset w30, -16 +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! ; CHECK: .Ltmp2: -; CHECK: ldr d0, [x0, #64] // on-fault: .LBB2_2 -; CHECK: // %bb.1: // %if.end -; CHECK: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK: ret -; CHECK: .LBB2_2: // %if.then -; CHECK: bl ThrowNullPointerException +; CHECK-NEXT: ldr d0, [x0, #64] // on-fault: .LBB2_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB2_2: +; CHECK-NEXT: bl ThrowNullPointerException define double @LoadDoubleFromPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -89,19 +80,16 @@ if.end: ret double %1 } -; CHECK-LABEL: LoadPtr32FromPtr32: // @LoadPtr32FromPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp3: -; CHECK-NEXT: ldr w0, [x0, #16] // on-fault: .LBB3_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB3_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: LoadPtr32FromPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp3: +; CHECK-NEXT: ldr w0, [x0, #16] // on-fault: .LBB3_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB3_2: +; CHECK-NEXT: bl ThrowNullPointerException define ptr addrspace(271) @LoadPtr32FromPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -118,19 +106,16 @@ if.end: ; preds = %entry ret ptr addrspace(271) %1 } -; CHECK-LABEL: StoreI32ToPtr32: // @StoreI32ToPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp4: -; CHECK-NEXT: str w1, [x0, #32] // on-fault: .LBB4_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB4_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: StoreI32ToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp4: +; CHECK-NEXT: str w1, [x0, #32] // on-fault: .LBB4_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB4_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StoreI32ToPtr32(ptr addrspace(271) %object, i32 %value) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -147,19 +132,16 @@ if.end: ; preds = %entry ret void } -; CHECK-LABEL: StoreFloatToPtr32: // @StoreFloatToPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp5: -; CHECK-NEXT: str s0, [x0, #32] // on-fault: .LBB5_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB5_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: StoreFloatToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp5: +; CHECK-NEXT: str s0, [x0, #32] // on-fault: .LBB5_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB5_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StoreFloatToPtr32(ptr addrspace(271) %object, float %value) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -176,19 +158,16 @@ if.end: ; preds = %entry ret void } -; CHECK-LABEL: StoreDoubleToPtr32: // @StoreDoubleToPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp6: -; CHECK-NEXT: str d0, [x0, #32] // on-fault: .LBB6_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB6_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: StoreDoubleToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp6: +; CHECK-NEXT: str d0, [x0, #32] // on-fault: .LBB6_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB6_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StoreDoubleToPtr32(ptr addrspace(271) %object, double %value) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -208,24 +187,20 @@ if.end: ; preds = %entry ; Note LLVM does not support this case because ImplicitNullChecks does not hoist ; str x8, [x0, #32] above the moves to x8 because of the dependency on x8 ; The test should be enabled when such support is introduced -; StoreConstantDoubleToPtr32: // @StoreConstantDoubleToPtr32 -; // %bb.0: // %entry -; str x30, [sp, #-16]! // 8-byte Folded Spill -; cbz x0, .LBB7_2 -; // %bb.1: // %if.end -; mov x8, #55370 -; movk x8, #19730, lsl #16 -; movk x8, #8699, lsl #32 -; movk x8, #16393, lsl #48 -; str x8, [x0, #32] -; ldr x30, [sp], #16 // 8-byte Folded Reload -; ret -; .LBB7_2: // %if.then -; bl ThrowNullPointerException - -; COM: CHECK-LABEL: StoreConstantDoubleToPtr32: // @StoreConstantDoubleToPtr32 -; COM: CHECK-NOT: cbz x0, {{.*}} -; COM: CHECK: ret +; CHECK-LABEL: StoreConstantDoubleToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: cbz x0, .LBB7_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: mov x8, #55370 +; CHECK-NEXT: movk x8, #19730, lsl #16 +; CHECK-NEXT: movk x8, #8699, lsl #32 +; CHECK-NEXT: movk x8, #16393, lsl #48 +; CHECK-NEXT: str x8, [x0, #32] +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB7_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StoreConstantDoubleToPtr32(ptr addrspace(271) %object) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr @@ -242,19 +217,16 @@ if.end: ; preds = %entry ret void } -; CHECK-LABEL: StorePtr32ToPtr32: // @StorePtr32ToPtr32 -; CHECK-NEXT: .cfi_startproc -; CHECK-NEXT: // %bb.0: // %entry -; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill -; CHECK-NEXT: .cfi_def_cfa_offset 16 -; CHECK-NEXT: .cfi_offset w30, -16 -; CHECK-NEXT: .Ltmp7: -; CHECK-NEXT: str w1, [x0, #32] // on-fault: .LBB8_2 -; CHECK-NEXT: // %bb.1: // %if.end -; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload -; CHECK-NEXT: ret -; CHECK-NEXT: .LBB8_2: // %if.then -; CHECK-NEXT: bl ThrowNullPointerException +; CHECK-LABEL: StorePtr32ToPtr32: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: str x30, [sp, #-16]! +; CHECK: .Ltmp7: +; CHECK-NEXT: str w1, [x0, #32] // on-fault: .LBB8_2 +; CHECK-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB8_2: +; CHECK-NEXT: bl ThrowNullPointerException define void @StorePtr32ToPtr32(ptr addrspace(271) %object, ptr addrspace(271) %value) { entry: %0 = addrspacecast ptr addrspace(271) %object to ptr diff --git a/llvm/test/Linker/module-flags-min-0-required.ll b/llvm/test/Linker/module-flags-min-0-required.ll new file mode 100644 index 0000000000000000000000000000000000000000..b8c9406be2a7517d9742b4887fcb0dd9554aa3c5 --- /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 } diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index b6de5e52ee58c343f5df456beb94d65c157cb59a..7dd345a6f2ffe60ad741f87534dff9af33d6c062 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -29,6 +29,7 @@ #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" @@ -354,7 +355,7 @@ protected: void loadDynamicTable(); void parseDynamicTable(); - Expected> findAdlt(); + Expected> findAdlt(); // OHOS_LOCAL Expected getSymbolVersion(const Elf_Sym &Sym, bool &IsDefault) const; @@ -368,14 +369,16 @@ protected: DynRegionInfo DynSymTabShndxRegion; DynRegionInfo DynamicTable; StringRef DynamicStringTable; - StringRef AdltStringTable; + 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; @@ -394,8 +397,10 @@ 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; @@ -580,7 +585,7 @@ public: void printVersionDefinitionSection(const Elf_Shdr *Sec) override; void printVersionDependencySection(const Elf_Shdr *Sec) override; void printHashHistograms() override; - void printAdltSection() override; + void printAdltSection() override; // OHOS_LOCAL void printCGProfile() override; void printBBAddrMaps() override; void printAddrsig() override; @@ -685,7 +690,7 @@ public: void printVersionDefinitionSection(const Elf_Shdr *Sec) override; void printVersionDependencySection(const Elf_Shdr *Sec) override; void printHashHistograms() override; - void printAdltSection() override; + void printAdltSection() override; // OHOS_LOCAL void printCGProfile() override; void printBBAddrMaps() override; void printAddrsig() override; @@ -1426,7 +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); // ADLT info + LLVM_READOBJ_ENUM_CASE(ELF, PT_ADLT); // OHOS_LOCAL ADLT info default: return ""; } @@ -1716,11 +1721,12 @@ 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}, + {"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 @@ -1728,7 +1734,8 @@ 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; + if (DotAdlt && DotAdltStrtab) + break; switch (Sec.sh_type) { case ELF::SHT_STRTAB: @@ -1754,6 +1761,7 @@ Expected> ELFDumper::findAdlt() { return Obj.getSectionContents(*DotAdlt); } +// OHOS_LOCAL end template std::pair @@ -2448,18 +2456,21 @@ std::string ELFDumper::getDynamicEntry(uint64_t Type, } template -StringRef ELFDumper::getDynamicString(uint64_t Value) const { +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 { +StringRef ELFDumper::getAdltDynamicString(uint64_t Value) const { return this->getDynamicString(Value, AdltStringTable); } template -StringRef ELFDumper::getDynamicString( - uint64_t Value, StringRef DynamicStringTable) const { +StringRef +ELFDumper::getDynamicString(uint64_t Value, + StringRef DynamicStringTable) const { if (DynamicStringTable.empty() && !DynamicStringTable.data()) { reportUniqueWarning("string table was not found"); return ""; @@ -2496,6 +2507,7 @@ StringRef ELFDumper::getDynamicString( return DynamicStringTable.data() + Value; } +// OHOS_LOCAL end template void ELFDumper::printUnwindInfo() { DwarfCFIEH::PrinterContext Ctx(W, ObjF); @@ -4883,9 +4895,11 @@ 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"; @@ -7019,7 +7033,7 @@ 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; @@ -7030,53 +7044,54 @@ template void LLVMELFDumper::printAdltSection() { } ArrayRef adltRaw = ContentsOrErr.get(); - auto* header = reinterpret_cast(adltRaw.data()); - const auto& ver = header->schemaVersion; + 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"); + "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"); + "blob is out of section range"); DictScope DSec(W, "ADLT"); do { - DictScope DHeader(W, "Header"); + 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") ); + 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.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); + 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"); + "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"); + "blob is out of section range"); if (ver.minor >= 1) { DictScope PHEntry(W, "ph-indexes"); - const auto& arr = header->phIndexes; + const auto &arr = header->phIndexes; W.printHex("size", arr.size); W.printHex("offset", arr.offset); @@ -7084,20 +7099,20 @@ template void LLVMELFDumper::printAdltSection() { if (!chunk.empty()) { W.printBinary("raw", chunk); ArrayRef phIdxs( - reinterpret_cast(chunk.data()), - chunk.size() / sizeof(uint16_t)); + reinterpret_cast(chunk.data()), + chunk.size() / sizeof(uint16_t)); W.printList("values", phIdxs); } } - } while(0); + } 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); - + for (Elf64_Half 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()); @@ -7124,7 +7139,7 @@ template void LLVMELFDumper::printAdltSection() { } { DictScope DNEntry(W, "dt-needed"); - const auto& arr = psod.dtNeeded; + const auto &arr = psod.dtNeeded; W.printHex("size", arr.size); W.printHex("offset", arr.offset); @@ -7133,12 +7148,13 @@ template void LLVMELFDumper::printAdltSection() { W.printBinary("raw", chunk); ArrayRef deps( - reinterpret_cast(chunk.data()), - chunk.size() / sizeof(adlt_dt_needed_index_t)); + 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)); + 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); @@ -7147,19 +7163,19 @@ template void LLVMELFDumper::printAdltSection() { } { DictScope SLEntry(W, "shared-local-symbol"); - const auto& csref = psod.sharedLocalSymbolIndex; + 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; + 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; + const auto &arr = psod.phIndexes; W.printHex("size", arr.size); W.printHex("offset", arr.offset); @@ -7167,14 +7183,14 @@ template void LLVMELFDumper::printAdltSection() { if (!chunk.empty()) { W.printBinary("raw", chunk); ArrayRef phIdxs( - reinterpret_cast(chunk.data()), - chunk.size() / sizeof(uint16_t)); + reinterpret_cast(chunk.data()), + chunk.size() / sizeof(uint16_t)); W.printList("values", phIdxs); } } { DictScope RDEntry(W, "rela-dyn-idxs"); - const auto& arr = psod.relaDynIndx; + const auto &arr = psod.relaDynIndx; W.printHex("size", arr.size); W.printHex("offset", arr.offset); @@ -7188,7 +7204,7 @@ template void LLVMELFDumper::printAdltSection() { } { DictScope RPEntry(W, "rela-plt-idsx"); - const auto& arr = psod.relaPltIndx; + const auto &arr = psod.relaPltIndx; W.printHex("size", arr.size); W.printHex("offset", arr.offset); @@ -7214,6 +7230,7 @@ template void LLVMELFDumper::printAdltSection() { W.printBinaryBlock("raw", blob); } } +// OHOS_LOCAL end // Returns true if rel/rela section exists, and populates SymbolIndices. // Otherwise returns false. diff --git a/llvm/tools/llvm-readobj/ObjDumper.h b/llvm/tools/llvm-readobj/ObjDumper.h index 320e5972d479bee640e5e2292c7996424ca242e3..bad21cc732b21e0542f1b0bdd6fa9af549380dbd 100644 --- a/llvm/tools/llvm-readobj/ObjDumper.h +++ b/llvm/tools/llvm-readobj/ObjDumper.h @@ -129,7 +129,7 @@ public: virtual void printVersionInfo() {} virtual void printGroupSections() {} virtual void printHashHistograms() {} - virtual void printAdltSection() {} + 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 012a16bb99ff7ae00d632f4b050cd51f2161da48..2abd661af548b7c91f49d1b86bace658ac139594 100644 --- a/llvm/tools/llvm-readobj/Opts.td +++ b/llvm/tools/llvm-readobj/Opts.td @@ -55,6 +55,7 @@ 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; diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp index 8c470a60ff9acad77cf08b3907d93a32ed82018c..b4c1d7dd94b7953bfaf24f3f73b48ef146a51171 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -125,7 +125,7 @@ static cl::boolOrDefault SectionMapping; static SmallVector SortKeys; // ELF specific options. -static bool AdltSection; +static bool AdltSection; // OHOS_LOCAL static bool DynamicTable; static bool ELFLinkerOptions; static bool GnuHashTable; @@ -254,6 +254,7 @@ 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); @@ -451,8 +452,10 @@ static void dumpObject(ObjectFile &Obj, ScopedPrinter &Writer, Dumper->printGroupSections(); if (opts::HashHistogram) Dumper->printHashHistograms(); + // OHOS_LOCAL begin if (opts::AdltSection) Dumper->printAdltSection(); + // OHOS_LOCAL end if (opts::CGProfile) Dumper->printCGProfile(); if (opts::BBAddrMap) diff --git a/llvm/utils/emacs/llvm-mode.el b/llvm/utils/emacs/llvm-mode.el index c4def25469f21f5f6b81d6b63120868cc0082b94..2b335ac76fdb7146c0350875f36f5be599258f62 100644 --- a/llvm/utils/emacs/llvm-mode.el +++ b/llvm/utils/emacs/llvm-mode.el @@ -59,7 +59,7 @@ "ccc" "fastcc" "coldcc" "webkit_jscc" "anyregcc" "preserve_mostcc" "preserve_allcc" ;; OHOS_LOCAL begin "cxx_fast_tlscc" "swiftcc" "tailcc" "swifttailcc" "cfguard_checkcc" "arkintcc" - "arkfast0cc" "arkfast1cc" "arkfast2cc" "arkfast3cc" "arkfast4cc" "arkfast5cc" + "arkfast0cc" "arkfast1cc" "arkfast2cc" "arkfast3cc" "arkfast4cc" "arkfast5cc" "arkfast6cc" "arkmethodcc" "arkresolvercc" "arkpltcc" ;; OHOS_LOCAL end ;; Visibility styles diff --git a/llvm/utils/vim/syntax/llvm.vim b/llvm/utils/vim/syntax/llvm.vim index 5b333a8b5bbc4542391aea419473969613706201..a2f58f8b472eb582a0a1d9c8630e4c2115433930 100644 --- a/llvm/utils/vim/syntax/llvm.vim +++ b/llvm/utils/vim/syntax/llvm.vim @@ -55,6 +55,7 @@ syn keyword llvmKeyword \ arkfast3cc \ arkfast4cc \ arkfast5cc + \ arkfast6cc \ arkintccx \ arkmethodcc \ arkpltcc