From 714617e7ed63e85a3ed760eea5bb0924c4e2965e Mon Sep 17 00:00:00 2001 From: kosovpavel Date: Thu, 29 Sep 2022 09:54:30 +0300 Subject: [PATCH] Add support for mipsel-linux-ohos target Known issues: - Executables built with this toolchain from C++ code containing try/catch blocks must be run directly via the elf interpreter, for example, `/path/to/ld-musl-mipsel.so.1 /path/to/executable`. When the executable is loaded to the process address space via the kernel, not by the elf interpreter, a segfault occurs. For the same reason, such executables cannot be run using qemu user emulation. The issue will be fixed in one of the subsequent PR's. - To compile C++ code containing try/catch blocks, -Wl,-z,notext option must be passed. The issue is related to the previous one and will also be fixed in one of the subsequent PR's. - FPXX is unsupported. The reason for that is different handling of FP32 and FP64 in libunwind (https://reviews.llvm.org/D41968). Because of that, rethrown exceptions of float and double types are not caught, and terminate is called. The default option is not FP64 instead of FPXX, which effectively means that FP32 is also unsupported (unless you rebuild sysroot by your own). The issue will be fixed in one of the subsequent PR's. Signed-off-by: kosovpavel --- .../clang/Basic/DiagnosticCommonKinds.td | 1 + clang/lib/Basic/Targets.cpp | 7 +- clang/lib/Basic/Targets/Mips.cpp | 6 ++ clang/lib/Basic/Targets/Mips.h | 5 +- clang/lib/Driver/ToolChains/Arch/Mips.cpp | 7 ++ clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/OHOS.cpp | 11 ++- clang/test/Driver/ohos.c | 2 + clang/test/Preprocessor/init-mips.c | 8 ++ clang/test/Preprocessor/ohos.c | 2 + compiler-rt/CMakeLists.txt | 4 +- .../cmake/Modules/CompilerRTUtils.cmake | 2 +- compiler-rt/cmake/config-ix.cmake | 2 +- .../sanitizer_platform_limits_posix.h | 2 +- .../sanitizer_stoptheworld_linux_libcdep.cpp | 7 +- llvm-build/Makefile | 8 ++ llvm-build/build.py | 97 +++++++++++-------- llvm-build/build_musl.sh | 6 +- 18 files changed, 127 insertions(+), 52 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td index a4f96a97991e..aee16705676d 100644 --- a/clang/include/clang/Basic/DiagnosticCommonKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td @@ -278,6 +278,7 @@ def err_target_unsupported_abi_for_triple : Error< def err_unsupported_abi_for_opt : Error<"'%0' can only be used with the '%1' ABI">; def err_mips_fp64_req : Error< "'%0' can only be used if the target supports the mfhc1 and mthc1 instructions">; +def err_unsupported_fpxx_ohos : Error<"fpxx is currently unsupported on OHOS">; def err_target_unknown_fpmath : Error<"unknown FP unit '%0'">; def err_target_unsupported_fpmath : Error< "the '%0' unit is not supported with this instruction set">; diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 8ba3f5c3223b..59fd19eb826d 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -270,7 +270,12 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::mipsel: switch (os) { case llvm::Triple::Linux: - return new LinuxTargetInfo(Triple, Opts); + switch (Triple.getEnvironment()) { + default: + return new LinuxTargetInfo(Triple, Opts); + case llvm::Triple::OpenHOS: + return new OHOSTargetInfo(Triple, Opts); + } case llvm::Triple::RTEMS: return new RTEMSTargetInfo(Triple, Opts); case llvm::Triple::FreeBSD: diff --git a/clang/lib/Basic/Targets/Mips.cpp b/clang/lib/Basic/Targets/Mips.cpp index 3a32fd492c6b..37110d8da9b6 100644 --- a/clang/lib/Basic/Targets/Mips.cpp +++ b/clang/lib/Basic/Targets/Mips.cpp @@ -269,6 +269,12 @@ bool MipsTargetInfo::validateTarget(DiagnosticsEngine &Diags) const { return false; } + // TODO: remove this if entry when fpxx is supported on OHOS + if (getTriple().isOpenHOS() && FPMode == FPXX) { + Diags.Report(diag::err_unsupported_fpxx_ohos); + return false; + } + // -fpxx is valid only for the o32 ABI if (FPMode == FPXX && (ABI == "n32" || ABI == "n64")) { Diags.Report(diag::err_unsupported_abi_for_opt) << "-mfpxx" << "o32"; diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h index b475c03889a1..82cdaf704716 100644 --- a/clang/lib/Basic/Targets/Mips.h +++ b/clang/lib/Basic/Targets/Mips.h @@ -86,7 +86,10 @@ public: } bool isFP64Default() const { - return CPU == "mips32r6" || ABI == "n32" || ABI == "n64" || ABI == "64"; + // TODO: remove getTriple().isOpenHOS() case + // when fpxx is supported on OHOS + return getTriple().isOpenHOS() || CPU == "mips32r6" || + ABI == "n32" || ABI == "n64" || ABI == "64"; } bool isNan2008() const override { return IsNan2008; } diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp b/clang/lib/Driver/ToolChains/Arch/Mips.cpp index 5a509dbb2bd3..889a983f2257 100644 --- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp +++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp @@ -362,6 +362,9 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple, } else if (mips::isFP64ADefault(Triple, CPUName)) { Features.push_back("+fp64"); Features.push_back("+nooddspreg"); + } else if (Triple.isOpenHOS()) { + // TODO: remove this else if entry when fpxx is supported on OHOS + Features.push_back("+fp64"); } AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg, @@ -466,6 +469,10 @@ bool mips::isFP64ADefault(const llvm::Triple &Triple, StringRef CPUName) { bool mips::isFPXXDefault(const llvm::Triple &Triple, StringRef CPUName, StringRef ABIName, mips::FloatABI FloatABI) { + // TODO: remove this if entry when fpxx is supported on OHOS + if (Triple.isOpenHOS()) + return false; + if (Triple.getVendor() != llvm::Triple::ImaginationTechnologies && Triple.getVendor() != llvm::Triple::MipsTechnologies && !Triple.isAndroid()) diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index cbd64e597976..bcaf75e25b25 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2124,7 +2124,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( static const char *const MIPSELLibDirs[] = {"/lib"}; static const char *const MIPSELTriples[] = { "mipsel-linux-gnu", "mips-img-linux-gnu", "mipsisa32r6el-linux-gnu", - "mipsel-linux-android"}; + "mipsel-linux-android", "mipsel-linux-ohos"}; static const char *const MIPS64LibDirs[] = {"/lib64", "/lib"}; static const char *const MIPS64Triples[] = { diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index efbe8fb778d1..f513488af15b 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -105,6 +105,8 @@ std::string OHOS::getMultiarchTriple(const llvm::Triple &T) const { return "riscv32-liteos-ohos"; case llvm::Triple::riscv64: return "riscv64-linux-ohos"; + case llvm::Triple::mipsel: + return "mipsel-linux-ohos"; case llvm::Triple::x86: return "i686-linux-ohos"; case llvm::Triple::x86_64: @@ -393,9 +395,12 @@ void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const { CmdArgs.push_back("relro"); CmdArgs.push_back("-z"); CmdArgs.push_back("max-page-size=4096"); - CmdArgs.push_back("--hash-style=gnu"); - // FIXME: gnu or both??? - CmdArgs.push_back("--hash-style=both"); + // .gnu.hash section is not compatible with the MIPS target + if (getArch() != llvm::Triple::mipsel) { + CmdArgs.push_back("--hash-style=gnu"); + // FIXME: gnu or both??? + CmdArgs.push_back("--hash-style=both"); + } #ifdef ENABLE_LINKER_BUILD_ID CmdArgs.push_back("--build-id"); #endif diff --git a/clang/test/Driver/ohos.c b/clang/test/Driver/ohos.c index e20d6bfd2177..8883dc69382a 100644 --- a/clang/test/Driver/ohos.c +++ b/clang/test/Driver/ohos.c @@ -56,6 +56,8 @@ // RUN: | FileCheck %s -check-prefix=CHECK-RUNTIME // RUN: %clang %s -### --target=aarch64-linux-ohos -fuse-ld=lld 2>&1 \ // RUN: | FileCheck %s -check-prefix=CHECK-RUNTIME +// RUN: %clang %s -### --target=mipsel-linux-ohos -fuse-ld=lld 2>&1 \ +// RUN: | FileCheck %s -check-prefix=CHECK-RUNTIME // RUN: %clang %s -### --target=x86_64-linux-ohos -fuse-ld=lld 2>&1 \ // RUN: | FileCheck %s -check-prefix=CHECK-RUNTIME // CHECK-RUNTIME: "{{.*}}/libclang_rt.builtins.a" diff --git a/clang/test/Preprocessor/init-mips.c b/clang/test/Preprocessor/init-mips.c index d76396aa35c9..258acfacde23 100644 --- a/clang/test/Preprocessor/init-mips.c +++ b/clang/test/Preprocessor/init-mips.c @@ -1,4 +1,7 @@ +// RUN: %clang_cc1 -E -dM -triple=mipsel-linux-ohos < /dev/null | FileCheck -match-full-lines -check-prefix MIPS32EL-OHOS %s // +// MIPS32EL-OHOS:#define __mips_fpr 64 + // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=mips-none-none < /dev/null | FileCheck -match-full-lines -check-prefix MIPS32BE -check-prefix MIPS32BE-C %s // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=mips-none-none < /dev/null | FileCheck -match-full-lines -check-prefix MIPS32BE -check-prefix MIPS32BE-CXX %s // @@ -1703,6 +1706,11 @@ // RUN: | FileCheck -match-full-lines -check-prefix MIPS64-NOFP %s // MIPS64-NOFP:#define __mips_fpr 64 +// RUN: not %clang_cc1 -target-feature +fpxx \ +// RUN: -E -dM -triple=mipsel-linux-ohos < /dev/null 2>&1 \ +// RUN: | FileCheck -match-full-lines -check-prefix MIPS32EL-OHOS-MFPXX %s +// MIPS32EL-OHOS-MFPXX:error: fpxx is currently unsupported on OHOS + // RUN: not %clang_cc1 -target-feature -fp64 \ // RUN: -E -dM -triple=mips64-none-none < /dev/null 2>&1 \ // RUN: | FileCheck -match-full-lines -check-prefix MIPS64-MFP32 %s diff --git a/clang/test/Preprocessor/ohos.c b/clang/test/Preprocessor/ohos.c index f67d342aa7cb..80af0fe6651d 100644 --- a/clang/test/Preprocessor/ohos.c +++ b/clang/test/Preprocessor/ohos.c @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=arm-linux-ohos < /dev/null | FileCheck %s -match-full-lines -check-prefix=ARM-OHOS-CXX // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=aarch64-linux-ohos < /dev/null | FileCheck %s -match-full-lines -check-prefix=ARM64-OHOS-CXX // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=riscv64-linux-ohos < /dev/null | FileCheck %s -match-full-lines -check-prefix=RISCV64-OHOS-CXX +// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=mipsel-linux-ohos < /dev/null | FileCheck %s -match-full-lines -check-prefix=MIPSEL-OHOS-CXX // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=x86_64-linux-ohos < /dev/null | FileCheck %s -match-full-lines -check-prefix=X86_64-OHOS-CXX // RUN: %clang_cc1 -E -dM -ffreestanding -triple=arm-linux-ohos < /dev/null | FileCheck %s -check-prefix=OHOS-DEFS @@ -9,6 +10,7 @@ // ARM64-HOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL // ARM64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL // RISCV64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL +// MIPSEL-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U // X86_64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL // OHOS-DEFS: __OHOS_FAMILY__ // OHOS-DEFS: __OHOS__ diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index 732e8863ed32..50d04bb1293e 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -429,7 +429,9 @@ append_list_if(MINGW -fms-extensions SANITIZER_COMMON_CFLAGS) # Set common link flags. append_list_if(COMPILER_RT_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS) -append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS) +if (NOT __MIPS) + append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS) +endif() if (COMPILER_RT_USE_BUILTINS_LIBRARY) string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake index 00bec8bdb846..77c5ae1c4b6d 100644 --- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -179,7 +179,7 @@ macro(detect_target_arch) elseif(__MIPS64) # must be checked before __MIPS add_default_target_arch(mips64) elseif(__MIPS) - add_default_target_arch(mips) + add_default_target_arch(mipsel) elseif(__PPC64) # must be checked before __PPC add_default_target_arch(powerpc64) elseif(__PPC64LE) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index 347de3a08bb6..62552fdac247 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -308,7 +308,7 @@ set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9}) set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64} ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9}) -set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64} ${VE}) +set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${RISCV32} ${RISCV64} ${VE}) set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) if(ANDROID) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h index f4294a74f8e2..ec77df6148ad 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -593,7 +593,7 @@ struct __sanitizer_sigaction { }; __sanitizer_sigset_t sa_mask; }; -#elif SANITIZER_ANDROID && (SANITIZER_WORDSIZE == 32) +#elif (SANITIZER_ANDROID || SANITIZER_OHOS) && (SANITIZER_WORDSIZE == 32) struct __sanitizer_sigaction { union { __sanitizer_sigactionhandler_ptr sigaction; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp index 0735b93c9a23..649078ba4e14 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp @@ -41,7 +41,7 @@ # include #endif #include // for user_regs_struct -#if SANITIZER_ANDROID && SANITIZER_MIPS +#if (SANITIZER_ANDROID || SANITIZER_OHOS) && SANITIZER_MIPS # include // for mips SP register in sys/user.h #endif #include // for signal-related stuff @@ -509,6 +509,11 @@ typedef pt_regs regs_struct; typedef struct user regs_struct; # if SANITIZER_ANDROID # define REG_SP regs[EF_R29] +// FIXME: For some reason, EF_R29 is not defined in asm/reg.h under +// #if _MIPS_SIM == _MIPS_SIM_ABI32 condition, so use MIPS32_EF_R29 as a +// temporary solution. +# elif SANITIZER_OHOS +# define REG_SP regs[MIPS32_EF_R29] # else # define REG_SP regs[EF_REG29] # endif diff --git a/llvm-build/Makefile b/llvm-build/Makefile index 916533aa8e7b..54a94743676c 100644 --- a/llvm-build/Makefile +++ b/llvm-build/Makefile @@ -76,6 +76,9 @@ else ifeq ($(ARCH),riscv64) ARCH_CFLAGS = else +ifeq ($(ARCH),mips) +ARCH_CFLAGS = +else ifeq ($(ARCH),x86_64) ARCH_CFLAGS = else @@ -85,6 +88,7 @@ endif endif endif endif +endif ifeq ($(ARCH),aarch64) CFLAGS = -march=armv8 -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack @@ -92,6 +96,9 @@ else ifeq ($(ARCH),riscv64) CFLAGS = -march=rv64gc -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack else +ifeq ($(ARCH),mips) +CFLAGS = -march=mips32r2 -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack +else ifeq ($(ARCH),x86_64) CFLAGS = -march=x86-64 -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack else @@ -99,6 +106,7 @@ CFLAGS = -march=armv7-a -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 - endif endif endif +endif .PHONY: $(TARGETS:%=musl_copy_for_%) .PHONY: $(TARGETS:%=musl_patch_for_%) diff --git a/llvm-build/build.py b/llvm-build/build.py index e261685b5f9d..d1121938a572 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -48,13 +48,14 @@ class BuildConfig(): self.no_build_arm = args.skip_build or args.no_build_arm self.no_build_aarch64 = args.skip_build or args.no_build_aarch64 self.no_build_riscv64 = args.skip_build or args.no_build_riscv64 + self.no_build_mipsel = args.skip_build or args.no_build_mipsel self.no_build_x86_64 = args.skip_build or args.no_build_x86_64 self.CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) self.REPOROOT_DIR = os.path.abspath(os.path.join(self.CURRENT_DIR, '../../')) self.LLVM_PROJECT_DIR = os.path.abspath(os.path.join(self.REPOROOT_DIR, 'toolchain', 'llvm-project')) self.OUT_PATH = os.path.join(self.REPOROOT_DIR, 'out') - self.TARGETS = 'AArch64;ARM;BPF;RISCV;X86' + self.TARGETS = 'AArch64;ARM;BPF;Mips;RISCV;X86' self.ORIG_ENV = dict(os.environ) self.VERSION = None # autodetected @@ -66,7 +67,7 @@ class BuildConfig(): @staticmethod def parse_add_argument(parser): - + parser.add_argument( '--enable-assertions', action='store_true', @@ -102,6 +103,12 @@ class BuildConfig(): default=False, help='Omit build os target: 64-bit RISC-V.') + parser.add_argument( + '--no-build-mipsel', + action='store_true', + default=False, + help='Omit build os target: mipsel.') + parser.add_argument( '--no-build-x86_64', action='store_true', @@ -111,7 +118,7 @@ class BuildConfig(): parser.add_argument( '--no-lto', action='store_true', - default=False, + default=False, help='Accelerate builds by disabling LTO (only affects llvm product)') parser.add_argument( @@ -146,7 +153,7 @@ class BuildConfig(): help='Omit the packaging, perform the packaging step directly.') self.parse_add_argument(parser) - + known_platforms = ('windows', 'libs', 'lldb-mi', 'lldb-server', 'linux', 'check-api') known_platforms_str = ', '.join(known_platforms) @@ -415,8 +422,8 @@ class LlvmCore(BuildUtils): llvm_defines['COMPILER_RT_BUILD_LIBFUZZER'] = 'OFF' llvm_defines['LLVM_BUILD_EXTERNAL_COMPILER_RT'] = 'ON' - def llvm_compile_linux_defines(self, - llvm_defines, + def llvm_compile_linux_defines(self, + llvm_defines, debug_build=False, no_lto=False, build_instrumented=False): @@ -434,7 +441,7 @@ class LlvmCore(BuildUtils): llvm_defines['LIBCXXABI_USE_LLVM_UNWINDER'] = 'YES' llvm_defines['LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY'] = 'YES' llvm_defines['LLVM_BINUTILS_INCDIR'] = '/usr/include' - + if not build_instrumented and not no_lto and not debug_build: llvm_defines['LLVM_ENABLE_LTO'] = 'Thin' @@ -492,7 +499,7 @@ class LlvmCore(BuildUtils): self.llvm_compile_darwin_defines(llvm_defines) self.llvm_compile_linux_defines(llvm_defines, debug_build, no_lto, build_instrumented) - + if self.host_is_linux(): ldflags += ' -lunwind --rtlib=compiler-rt -stdlib=libc++' @@ -511,7 +518,7 @@ class LlvmCore(BuildUtils): resource_dir = "lib/clang/10.0.1/lib/linux/libclang_rt.profile-x86_64.a" ldflags += ' %s' % os.path.join(llvm_clang_install, resource_dir) - + cflags = '-fstack-protector-strong -fPIE' ldflags += ' -Wl,-z,relro,-z,now -pie -s' @@ -535,7 +542,7 @@ class LlvmCore(BuildUtils): windows_sysroot): if self.build_config.enable_assertions: - + windows_defines['LLVM_ENABLE_ASSERTIONS'] = 'ON' windows_defines['LLDB_RELOCATABLE_PYTHON'] = 'OFF' @@ -544,7 +551,7 @@ class LlvmCore(BuildUtils): windows_defines['LLDB_ENABLE_PYTHON'] = 'ON' windows_defines['LLDB_PYTHON_HOME'] = 'python' windows_defines['LLDB_PYTHON_RELATIVE_PATH'] = 'bin/python/lib/python%s' % (self.build_config.LLDB_PY_VERSION) - windows_defines['PYTHON_INCLUDE_DIRS'] = os.path.join(win_sysroot, + windows_defines['PYTHON_INCLUDE_DIRS'] = os.path.join(win_sysroot, 'include', 'python%s' % self.build_config.LLDB_PY_VERSION) windows_defines['PYTHON_LIBRARIES'] = os.path.join(win_sysroot, 'lib', 'libpython%s.dll.a' % self.build_config.LLDB_PY_VERSION) @@ -616,7 +623,7 @@ class LlvmCore(BuildUtils): cxxflags, ldflags, windows_defines): - + zlib_path = self.merge_out_path('../', 'prebuilts', 'clang', 'host', 'windows-x86', 'toolchain-prebuilts', 'zlib') @@ -679,7 +686,7 @@ class LlvmCore(BuildUtils): ldflags = [] cflags = [] - self.llvm_compile_windows_flags(windows_defines, compiler_rt_path, native_cmake_file_path, + self.llvm_compile_windows_flags(windows_defines, compiler_rt_path, native_cmake_file_path, windowstool_path, windows64_install, ldflags, cflags) cxxflags = list(cflags) @@ -727,14 +734,18 @@ class SysrootComposer(BuildUtils): os.chdir(cur_dir) def install_linux_headers(self, arch, target): - dir_sufix = 'x86' if arch == 'x86_64' else arch + dir_suffix = arch + if arch == 'x86_64': + dir_suffix = 'x86' + elif arch == 'mipsel': + dir_suffix = 'mips' linux_kernel_dir = os.path.join('kernel_linux_patches', 'linux-5.10') linux_kernel_path = os.path.join(self.build_config.OUT_PATH, '..', linux_kernel_dir) ohosmusl_sysroot_dst = self.merge_out_path('sysroot', target, 'usr') headers_tmp_dir = os.path.join(linux_kernel_path, 'prebuilts', 'usr', 'include') self.check_copy_tree(os.path.join(headers_tmp_dir, 'linux'), os.path.join(ohosmusl_sysroot_dst, 'include/linux')) - self.check_copy_tree(os.path.join(headers_tmp_dir, 'asm-%s' % dir_sufix,'asm'), + self.check_copy_tree(os.path.join(headers_tmp_dir, 'asm-%s' % dir_suffix,'asm'), os.path.join(ohosmusl_sysroot_dst, 'include', 'asm')) self.check_copy_tree(os.path.join(headers_tmp_dir, 'asm-generic'), os.path.join(ohosmusl_sysroot_dst, 'include/asm-generic')) @@ -772,9 +783,9 @@ class LlvmLibs(BuildUtils): self.build_libs(need_lldb_server, llvm_install, target, - precompilation=True) + precompilation=True) self.sysroot_composer.build_musl(llvm_install, target, '-l') - + def build_libs_defines(self, llvm_triple, defines, @@ -785,7 +796,7 @@ class LlvmLibs(BuildUtils): ldflags, cflags, extra_flags): - + sysroot = self.merge_out_path('sysroot') defines['CMAKE_C_COMPILER'] = cc @@ -818,7 +829,7 @@ class LlvmLibs(BuildUtils): '-ffunction-sections', '-fdata-sections', extra_flags, ] - + cflags.extend(cflag) def build_need_libs_for_windows(self): @@ -844,6 +855,7 @@ class LlvmLibs(BuildUtils): '-march=armv7-a -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4', 'a7_hard_neon-vfpv4'), ('aarch64', self.open_ohos_triple('aarch64'), '', ''), ('riscv64', self.open_ohos_triple('riscv64'), '', ''), + ('mipsel', self.open_ohos_triple('mipsel'), '-march=mips32r2', ''), ('x86_64', self.open_ohos_triple('x86_64'), '', ''),] cc = os.path.join(llvm_install, 'bin', 'clang') @@ -864,10 +876,13 @@ class LlvmLibs(BuildUtils): cflags = [] self.logger().info('Build libs for %s', llvm_triple) self.build_libs_defines(llvm_triple, defines, cc, cxx, ar, llvm_config, ldflags, cflags, extra_flags) + if arch == 'mipsel': + ldflags.append('-Wl,-z,notext') llvm_path = self.merge_out_path('llvm_make') - arch_list = [self.liteos_triple('arm'), self.open_ohos_triple('arm'), self.open_ohos_triple('aarch64'), - self.open_ohos_triple('riscv64'), self.open_ohos_triple('x86_64')] + arch_list = [self.liteos_triple('arm'), self.open_ohos_triple('arm'), + self.open_ohos_triple('aarch64'), self.open_ohos_triple('riscv64'), + self.open_ohos_triple('mipsel'), self.open_ohos_triple('x86_64')] if precompilation: self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines) continue @@ -1068,17 +1083,17 @@ class LlvmLibs(BuildUtils): install=True) def build_libcxx_defines_parameters(self, - libcxx_defines, + libcxx_defines, libcxx_ldflags, - libcxx_cflags, - llvm_install, + libcxx_cflags, + llvm_install, multilib_suffix, - libcxx_path, - llvm_triple, + libcxx_path, + llvm_triple, out_dir, libcxx_ndk_install, do_build_system): - + libcxx_defines['CMAKE_EXE_LINKER_FLAGS'] = ' '.join(libcxx_ldflags) libcxx_defines['CMAKE_SHARED_LINKER_FLAGS'] = ' '.join(libcxx_ldflags) libcxx_defines['CMAKE_MODULE_LINKER_FLAGS'] = ' '.join(libcxx_ldflags) @@ -1116,8 +1131,7 @@ class LlvmLibs(BuildUtils): libcxx_defines['LIBCXX_HAS_PTHREAD_LIB'] = 'OFF' libcxx_defines['LIBCXX_HAS_RT_LIB'] = 'OFF' libcxx_defines['CMAKE_TRY_COMPILE_TARGET_TYPE'] = 'STATIC_LIBRARY' - - + def build_libcxx(self, @@ -1135,7 +1149,7 @@ class LlvmLibs(BuildUtils): suffix = '-' + multilib_suffix if multilib_suffix else '' libcxx_path = self.merge_out_path('lib', 'libcxx-%s-%s%s' % ('system' if do_build_system else 'ndk', llvm_triple, suffix)) - + out_dir = os.path.join(libcxx_path, 'lib') libcxx_ndk_install = self.merge_out_path('libcxx-ndk') self.check_create_dir(libcxx_ndk_install) @@ -1146,14 +1160,14 @@ class LlvmLibs(BuildUtils): libcxx_cflags.append('-fPIC') libcxx_defines = defines.copy() - - self.build_libcxx_defines_parameters(libcxx_defines, + + self.build_libcxx_defines_parameters(libcxx_defines, libcxx_ldflags, - libcxx_cflags, + libcxx_cflags, llvm_install, multilib_suffix, - libcxx_path, - llvm_triple, + libcxx_path, + llvm_triple, out_dir, libcxx_ndk_install, do_build_system) @@ -1350,7 +1364,7 @@ class LlvmLibs(BuildUtils): self.logger().info('Building libs for windows.') toolchain_dir = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION) install_dir = self.merge_out_path('windows-x86_64-install') - compiler_rt_path = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'lib', 'clang', + compiler_rt_path = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'lib', 'clang', self.build_config.CLANG_VERSION, 'lib', 'windows') windows_sysroot = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'x86_64-w64-mingw32') @@ -1474,7 +1488,7 @@ class LldbMi(BuildUtils): return ldflags_lists @staticmethod - def cflags_lists_define(): + def cflags_lists_define(): cflags_lists = ['-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_WIN32_WINNT=0x0600', @@ -1634,7 +1648,7 @@ class LlvmPackage(BuildUtils): def install_mingw_python(self, install_dir): - py_root = self.merge_out_path('../third_party', 'mingw-w64', 'mingw-w64-python', + py_root = self.merge_out_path('../third_party', 'mingw-w64', 'mingw-w64-python', self.build_config.LLDB_PY_VERSION) bin_root = os.path.join(install_dir, 'bin') py_dll = 'libpython' + self.build_config.LLDB_PY_VERSION + '.dll' @@ -1710,7 +1724,7 @@ class LlvmPackage(BuildUtils): notices.append(notice_file.read()) if host.startswith('windows'): - mingw_license_file = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, + mingw_license_file = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'third_party/mingw-w64/COPYING')) with open(mingw_license_file) as notice_file: notices.append(notice_file.read()) @@ -1988,6 +2002,9 @@ def main(): if not build_config.no_build_riscv64: configs.append(('riscv', build_utils.open_ohos_triple('riscv64'))) + if not build_config.no_build_mipsel: + configs.append(('mipsel', build_utils.open_ohos_triple('mipsel'))) + if not build_config.no_build_x86_64: configs.append(('x86_64', build_utils.open_ohos_triple('x86_64'))) @@ -2000,7 +2017,7 @@ def main(): build_config.no_lto, build_config.build_instrumented, build_config.xunit_xml_output) - + llvm_core.set_clang_version(llvm_install) if build_config.do_build and build_utils.host_is_linux(): diff --git a/llvm-build/build_musl.sh b/llvm-build/build_musl.sh index 8956ccd83414..9fb8737c032a 100755 --- a/llvm-build/build_musl.sh +++ b/llvm-build/build_musl.sh @@ -72,6 +72,10 @@ if [ $TARGET_TRIPLE == "arm-liteos-ohos" ]; then elif [ $TARGET_TRIPLE == "arm-linux-ohos" ]; then TARGET_USER="linux_user" TARGETS_PREFIX="arm" +elif [ $TARGET_TRIPLE == "mipsel-linux-ohos" ]; then + TARGET_USER="linux_user" + TARGETS_PREFIX="mips" + CFLAGS_FOR_TARGET=("-march=mips32r2") elif [ $TARGET_TRIPLE == "riscv64-linux-ohos" ]; then TARGET_USER="linux_user" TARGETS_PREFIX="riscv64" @@ -98,7 +102,7 @@ make musl_header_install_for_${TARGET_USER} CLANG="${CLANG_BIN_ROOT}/clang" TOPD # build musl_libs if ((make_libs == 1)); then if [ $TARGET_TRIPLE == "aarch64-linux-ohos" ] || [ $TARGET_TRIPLE == "riscv64-linux-ohos" ] || \ - [ $TARGET_TRIPLE == "x86_64-linux-ohos" ]; then + [ $TARGET_TRIPLE == "mipsel-linux-ohos" ] || [ $TARGET_TRIPLE == "x86_64-linux-ohos" ]; then make CLANG="${CLANG_BIN_ROOT}/clang" TOPDIR=${PWD}/../../ SYSROOTDIR=${OUT}/sysroot TARGETS=${TARGET_USER}\ TARGET=${TARGET_TRIPLE} ARCH=${TARGETS_PREFIX} -f Makefile else -- Gitee