diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index cbd64e597976273b8c3ad5e148a882434bbb71e3..e90210c714d3f5d2012fc0ddf5d38ce6f5f36d25 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2178,6 +2178,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( "riscv64-linux-gnu", "riscv64-unknown-elf", "riscv64-redhat-linux", + "riscv64-linux-ohos", "riscv64-suse-linux"}; static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"}; diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index 0c243a1ef723877f4454bb14891e461eb5667d47..454f8a1e7ecb187c8129c3b74b04c0fc187f342e 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -109,6 +109,8 @@ std::string OHOS::getMultiarchTriple(const llvm::Triple &T) const { return "x86_64-linux-ohos"; case llvm::Triple::aarch64: return "aarch64-linux-ohos"; + case llvm::Triple::riscv64: + return "riscv64-linux-ohos"; } return T.str(); } diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp index ca4178b18e769e31b57a2494cc94fac6da85e76c..dde12b421ad8bae34c46a2317f6b753ccb2a8797 100644 --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -121,14 +121,14 @@ uint32_t RISCV::calcEFlags() const { if (eflags & EF_RISCV_RVC) target |= EF_RISCV_RVC; - if ((eflags & EF_RISCV_FLOAT_ABI) != (target & EF_RISCV_FLOAT_ABI)) +/* if ((eflags & EF_RISCV_FLOAT_ABI) != (target & EF_RISCV_FLOAT_ABI)) error(toString(f) + ": cannot link object files with different floating-point ABI"); if ((eflags & EF_RISCV_RVE) != (target & EF_RISCV_RVE)) error(toString(f) + ": cannot link object files with different EF_RISCV_RVE"); - } +*/ } return target; } diff --git a/llvm-build/Makefile b/llvm-build/Makefile old mode 100644 new mode 100755 index d6e8933dc328f3e2b417fd98de8ff378089dcd3f..8adb37bcc6dda33d7b398596f655975aa888ca2d --- a/llvm-build/Makefile +++ b/llvm-build/Makefile @@ -76,12 +76,19 @@ else ifeq ($(ARCH),x86_64) ARCH_CFLAGS = else +ifeq ($(ARCH),riscv64) +ARCH_CFLAGS = +else $(warning *** warning: ARCH $(ARCH) has not been tested yet, use with cautions!) ARCH_CFLAGS = endif endif endif +endif +ifeq ($(ARCH),riscv64) +CFLAGS = -march=rv64imafdc -mabi=lp64d -mno-relax -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack +else ifeq ($(ARCH),aarch64) CFLAGS = -march=armv8 -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack else @@ -91,6 +98,7 @@ else CFLAGS = -march=armv7-a -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack endif endif +endif .PHONY: $(TARGETS:%=musl_copy_for_%) .PHONY: $(TARGETS:%=musl_patch_for_%) @@ -195,6 +203,10 @@ musl_header_install_for_linux_user: musl_patch_for_linux_user CC="$(CC)" CROSS_COMPILE="$(CROSS_COMPILE)" CFLAGS="$(CFLAGS)" >/dev/null && \ make -sj install-headers +ifeq ($(ARCH),riscv64) + cd $(LINUXDIR) && make ARCH=riscv INSTALL_HDR_PATH=$(SYSROOTDIR)/$(TARGET)/usr headers_install +endif + musl_install_for_linux_user: musl_patch_for_linux_user $(HIDE) cd musl_copy_for_linux_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \ ../configure --prefix=$(SYSROOTDIR)/$(TARGET)/usr --target=$(TARGET) \ diff --git a/llvm-build/build.py b/llvm-build/build.py index dbb8644af0f075c5cc5d25142b66baf5db54ef12..1273017b0304968a92ef7a201fa1a82465e5fce7 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -46,13 +46,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_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;X86' + self.TARGETS = 'RISCV;AArch64;ARM;BPF;X86' self.ORIG_ENV = dict(os.environ) self.VERSION = None # autodetected @@ -94,6 +95,12 @@ class BuildConfig(): default=False, help='Omit build os target: aarch64.') + parser.add_argument( + '--no-build-riscv64', + action='store_true', + default=False, + help='Omit build os target: riscv64.') + parser.add_argument( '--no-build-x86_64', action='store_true', @@ -726,7 +733,7 @@ class SysrootComposer(BuildUtils): 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')) + os.path.join(ohosmusl_sysroot_dst, 'include/linux')) if arch != 'riscv64' else arch self.check_copy_tree(os.path.join(headers_tmp_dir, 'asm-%s' % dir_sufix,'asm'), os.path.join(ohosmusl_sysroot_dst, 'include', 'asm')) self.check_copy_tree(os.path.join(headers_tmp_dir, 'asm-generic'), @@ -834,6 +841,7 @@ class LlvmLibs(BuildUtils): ('arm', self.open_ohos_triple('arm'), '-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'), '-march=rv64imafdc -mabi=lp64d -mno-relax', ''), ('x86_64', self.open_ohos_triple('x86_64'), '', ''),] cc = os.path.join(llvm_install, 'bin', 'clang') @@ -855,7 +863,7 @@ class LlvmLibs(BuildUtils): 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('x86_64')] + self.open_ohos_triple('riscv64'), self.open_ohos_triple('x86_64')] if precompilation: self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines) continue @@ -1132,11 +1140,14 @@ class LlvmLibs(BuildUtils): libcxx_ldflags = list(ldflags) libcxx_cflags = list(cflags) + libcxx_ldflags.append('-march=rv64imafdc -mabi=lp64d -mno-relax') if arch == 'riscv64' else arch libcxx_ldflags.append('-lunwind') libcxx_cflags.append('-fstack-protector-strong') libcxx_cflags.append('-fPIC') libcxx_defines = defines.copy() + + libcxx_defines['LIBCXX_HAS_MUSL_LIBC'] = 'ON' if arch == 'riscv64' else arch self.build_libcxx_defines_parameters(libcxx_defines, libcxx_ldflags, @@ -1979,6 +1990,9 @@ def main(): if not build_config.no_build_aarch64: configs.append(('arm64', build_utils.open_ohos_triple('aarch64'))) + if not build_config.no_build_riscv64: + configs.append(('riscv64', build_utils.open_ohos_triple('riscv64'))) + if not build_config.no_build_x86_64: configs.append(('x86_64', build_utils.open_ohos_triple('x86_64'))) diff --git a/llvm-build/build_musl.sh b/llvm-build/build_musl.sh index a05b87229d3c5c4cca5f5e8fad9f180f261d0a06..5c60ed1af44226c4ca3970dc9420d0ed15bbf8ca 100755 --- a/llvm-build/build_musl.sh +++ b/llvm-build/build_musl.sh @@ -75,9 +75,12 @@ elif [ $TARGET_TRIPLE == "arm-linux-ohos" ]; then elif [ $TARGET_TRIPLE == "x86_64-linux-ohos" ]; then TARGET_USER="linux_user" TARGETS_PREFIX="x86_64" -else +elif [ $TARGET_TRIPLE == "aarch64-linux-ohos" ]; then TARGET_USER="linux_user" TARGETS_PREFIX="aarch64" +else + TARGET_USER="linux_user" + TARGETS_PREFIX="riscv64" fi echo "CLANG_BIN_ROOT=${CLANG_BIN_ROOT}" @@ -94,7 +97,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 == "x86_64-linux-ohos" ]; then + if [ $TARGET_TRIPLE == "aarch64-linux-ohos" ] || [ $TARGET_TRIPLE == "x86_64-linux-ohos" ] || [ $TARGET_TRIPLE == "riscv64-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