From ba514e6bec3952a6aa7309c9bd329143ea557c34 Mon Sep 17 00:00:00 2001 From: erjuan Date: Tue, 12 Nov 2024 10:56:58 +0800 Subject: [PATCH 1/3] support ohos targets and provide asan library support ohos targets and provide asan library Signed-off-by: fengting --- compiler/rustc_llvm/build.rs | 2 +- .../src/spec/aarch64_unknown_linux_ohos.rs | 4 +-- .../src/spec/armv7_unknown_linux_ohos.rs | 5 +++- compiler/rustc_target/src/spec/mod.rs | 1 + .../src/spec/x86_64_unknown_linux_ohos.rs | 30 +++++++++++++++++++ src/bootstrap/llvm.rs | 26 +++++++++++++--- 6 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 compiler/rustc_target/src/spec/x86_64_unknown_linux_ohos.rs diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index b0783d75d47..c6d3774e9ea 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -26,7 +26,7 @@ ]; const REQUIRED_COMPONENTS: &[&str] = - &["ipo", "bitreader", "bitwriter", "linker", "asmparser", "lto", "coverage", "instrumentation"]; + &["ipo", "bitreader", "bitwriter", "linker", "asmparser", "lto", "coverage", "instrumentation", "parts"]; fn detect_llvm_link() -> (&'static str, &'static str) { // Force the link mode we want, preferring static by default, but diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs b/compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs index bf1b089f657..dea3571a0dd 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs @@ -10,7 +10,7 @@ pub fn target() -> Target { Target { // LLVM 15 doesn't support OpenHarmony yet, use a linux target instead. - llvm_target: "aarch64-unknown-linux-musl".into(), + llvm_target: "aarch64-linux-ohos".into(), pointer_width: 64, data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), arch: "aarch64".into(), @@ -22,8 +22,6 @@ pub fn target() -> Target { supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK - | SanitizerSet::MEMORY - | SanitizerSet::MEMTAG | SanitizerSet::THREAD | SanitizerSet::HWADDRESS, ..base diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs index 16da2453367..ffaa950c060 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs @@ -1,4 +1,5 @@ use crate::spec::{Target, TargetOptions}; +use super::SanitizerSet; // This target is for OpenHarmony on ARMv7 Linux with thumb-mode, but no NEON or // hardfloat. @@ -8,7 +9,7 @@ pub fn target() -> Target { // target. Target { // LLVM 15 doesn't support OpenHarmony yet, use a linux target instead. - llvm_target: "armv7-unknown-linux-gnueabi".into(), + llvm_target: "arm-linux-ohos".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), arch: "arm".into(), @@ -22,6 +23,8 @@ pub fn target() -> Target { mcount: "\u{1}mcount".into(), force_emulated_tls: true, has_thread_local: false, + supported_sanitizers: SanitizerSet::ADDRESS + | SanitizerSet::LEAK, ..super::linux_musl_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 2365dfaf1af..689150b89f4 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1493,6 +1493,7 @@ fn $module() { ("aarch64-unknown-linux-ohos", aarch64_unknown_linux_ohos), ("armv7-unknown-linux-ohos", armv7_unknown_linux_ohos), + ("x86_64-unknown-linux-ohos", x86_64_unknown_linux_ohos), } /// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]> diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_linux_ohos.rs b/compiler/rustc_target/src/spec/x86_64_unknown_linux_ohos.rs new file mode 100644 index 00000000000..ae4eb088262 --- /dev/null +++ b/compiler/rustc_target/src/spec/x86_64_unknown_linux_ohos.rs @@ -0,0 +1,30 @@ +use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target}; + +pub fn target() -> Target { + let mut base = super::linux_musl_base::opts(); + + base.cpu = "x86-64".into(); + base.max_atomic_width = Some(64); + base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); + base.stack_probes = StackProbeType::X86; + base.static_position_independent_executables = true; + base.supported_sanitizers = SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::LEAK + | SanitizerSet::THREAD; + + base.env = "ohos".into(); + base.crt_static_default = false; + base.force_emulated_tls = true; + base.has_thread_local = false; + + Target { + // LLVM 15 doesn't support OpenHarmony yet, use a linux target instead. + llvm_target: "x86_64-linux-ohos".into(), + pointer_width: 64, + data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + .into(), + arch: "x86_64".into(), + options: base, + } +} \ No newline at end of file diff --git a/src/bootstrap/llvm.rs b/src/bootstrap/llvm.rs index 7e27960f3e9..4251f1d82bb 100644 --- a/src/bootstrap/llvm.rs +++ b/src/bootstrap/llvm.rs @@ -679,7 +679,11 @@ fn configure_cmake( } } if builder.config.llvm_clang_cl.is_some() { - cflags.push(&format!(" --target={}", target)); + if target.contains("armv7-unknown-linux-ohos") { + cflags.push(&format!(" --target={}", "arm-linux-ohos")); + } else { + cflags.push(&format!(" --target={}", target)); + } } for flag in extra_compiler_flags { cflags.push(&format!(" {}", flag)); @@ -691,7 +695,11 @@ fn configure_cmake( cxxflags.push(s); } if builder.config.llvm_clang_cl.is_some() { - cxxflags.push(&format!(" --target={}", target)); + if target.contains("armv7-unknown-linux-ohos") { + cxxflags.push(&format!(" --target={}", "arm-linux-ohos")); + } else { + cxxflags.push(&format!(" --target={}", target)); + } } for flag in extra_compiler_flags { cxxflags.push(&format!(" {}", flag)); @@ -946,7 +954,11 @@ fn run(self, builder: &Builder<'_>) -> Self::Output { let mut cfg = cmake::Config::new(&compiler_rt_dir); cfg.profile("Release"); - cfg.define("CMAKE_C_COMPILER_TARGET", self.target.triple); + if self.target.triple == "armv7-unknown-linux-ohos" { + cfg.define("CMAKE_C_COMPILER_TARGET", "arm-linux-ohos"); + } else { + cfg.define("CMAKE_C_COMPILER_TARGET", self.target.triple); + } cfg.define("COMPILER_RT_BUILD_BUILTINS", "OFF"); cfg.define("COMPILER_RT_BUILD_CRT", "OFF"); cfg.define("COMPILER_RT_BUILD_LIBFUZZER", "OFF"); @@ -1033,7 +1045,10 @@ fn supported_sanitizers( common_libs("linux", "aarch64", &["asan", "lsan", "msan", "tsan", "hwasan"]) } "aarch64-unknown-linux-ohos" => { - common_libs("linux", "aarch64", &["asan", "lsan", "msan", "tsan", "hwasan"]) + common_libs("linux", "aarch64", &["asan", "lsan", "tsan", "hwasan"]) + } + "armv7-unknown-linux-ohos" => { + common_libs("linux", "arm", &["asan", "lsan"]) } "x86_64-apple-darwin" => darwin_libs("osx", &["asan", "lsan", "tsan"]), "x86_64-unknown-fuchsia" => common_libs("fuchsia", "x86_64", &["asan"]), @@ -1050,6 +1065,9 @@ fn supported_sanitizers( "x86_64-unknown-linux-musl" => { common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"]) } + "x86_64-unknown-linux-ohos" => { + common_libs("linux", "x86_64", &["asan", "lsan", "tsan"]) + } "s390x-unknown-linux-gnu" => { common_libs("linux", "s390x", &["asan", "lsan", "msan", "tsan"]) } -- Gitee From 099557c78ea58775d8f3950176b0095f634d5616 Mon Sep 17 00:00:00 2001 From: erjuan Date: Tue, 12 Nov 2024 10:57:50 +0800 Subject: [PATCH 2/3] fix test case block in armv7 ohos fix test case block in armv7 ohos Signed-off-by: fengting --- compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs | 2 +- src/bootstrap/llvm.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs index ffaa950c060..f95fc51ba56 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs @@ -9,7 +9,7 @@ pub fn target() -> Target { // target. Target { // LLVM 15 doesn't support OpenHarmony yet, use a linux target instead. - llvm_target: "arm-linux-ohos".into(), + llvm_target: "armv7-unknown-linux-gnueabi".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), arch: "arm".into(), diff --git a/src/bootstrap/llvm.rs b/src/bootstrap/llvm.rs index 4251f1d82bb..2dea078ba2e 100644 --- a/src/bootstrap/llvm.rs +++ b/src/bootstrap/llvm.rs @@ -680,7 +680,7 @@ fn configure_cmake( } if builder.config.llvm_clang_cl.is_some() { if target.contains("armv7-unknown-linux-ohos") { - cflags.push(&format!(" --target={}", "arm-linux-ohos")); + cflags.push(&format!(" --target={}", "arm-linux-gnueabi")); } else { cflags.push(&format!(" --target={}", target)); } @@ -696,7 +696,7 @@ fn configure_cmake( } if builder.config.llvm_clang_cl.is_some() { if target.contains("armv7-unknown-linux-ohos") { - cxxflags.push(&format!(" --target={}", "arm-linux-ohos")); + cxxflags.push(&format!(" --target={}", "arm-linux-gnueabi")); } else { cxxflags.push(&format!(" --target={}", target)); } @@ -955,7 +955,7 @@ fn run(self, builder: &Builder<'_>) -> Self::Output { let mut cfg = cmake::Config::new(&compiler_rt_dir); cfg.profile("Release"); if self.target.triple == "armv7-unknown-linux-ohos" { - cfg.define("CMAKE_C_COMPILER_TARGET", "arm-linux-ohos"); + cfg.define("CMAKE_C_COMPILER_TARGET", "arm-linux-gnueabi"); } else { cfg.define("CMAKE_C_COMPILER_TARGET", self.target.triple); } -- Gitee From f0f786f5e002cfd02b5d333d7a579ca83e852aba Mon Sep 17 00:00:00 2001 From: erjuan Date: Tue, 12 Nov 2024 11:03:32 +0800 Subject: [PATCH 3/3] use OpenHarmony llvm-project use OpenHarmony llvm-project Signed-off-by: fengting --- rust-build/build.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rust-build/build.sh b/rust-build/build.sh index adcfdd4bb1e..ce22fa54a44 100644 --- a/rust-build/build.sh +++ b/rust-build/build.sh @@ -83,8 +83,7 @@ cp -r library ${rust_source_dir} cp -r src/doc/* ${rust_source_dir}/src/doc cp -r src/tools/cargo/* ${rust_source_dir}/src/tools/cargo -cp -r src/llvm-project/* ${rust_source_dir}/src/llvm-project/ -# cp -r ${root_build_dir}/../harmony/third_party_llvm-project/* ${rust_source_dir}/src/llvm-project/ +cp -r ${root_build_dir}/../harmony/third_party_llvm-project/* ${rust_source_dir}/src/llvm-project/ cd ${rust_source_dir} if [ "${host_platform}" = "linux" ]; then -- Gitee