diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index c4c93e42d303cd6764328f648c107f661695e1f8..449ae8ed0df08cc3bc7d645f69f5e86ec9ced31a 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -385,8 +385,6 @@ void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) const { } SanitizerMask OHOS::getSupportedSanitizers() const { - const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; - const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64; SanitizerMask Res = ToolChain::getSupportedSanitizers(); Res |= SanitizerKind::Address; Res |= SanitizerKind::PointerCompare; @@ -403,8 +401,6 @@ SanitizerMask OHOS::getSupportedSanitizers() const { Res |= SanitizerKind::HWAddress; // TODO: kASAN for liteos ?? // TODO: Support TSAN and HWASAN and update mask. - if (IsAArch64 || IsX86_64) - Res |= SanitizerKind::Thread; return Res; } diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index c62103d21c22b22ae7b516ba006e8034b10842be..b5160f9a048cc4e31fc9f359cbf79ee5c34bd299 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -799,7 +799,7 @@ if (LINKER_IS_LLD OR LLVM_TOOL_LLD_BUILD) endif() endif() -if(ANDROID OR OHOS) # OHOS_LOCAL +if(ANDROID) set(COMPILER_RT_HAS_LLD TRUE) set(COMPILER_RT_TEST_USE_LLD TRUE) append_list_if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG -fuse-ld=lld SANITIZER_COMMON_LINK_FLAGS) diff --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/CMakeLists.txt index ef03b15cf70153502bf59d1292bb48f12eca9339..66f2d259aa5fd46bc627f91789435a846f65414f 100644 --- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt +++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt @@ -229,12 +229,6 @@ append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=570 append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors SANITIZER_CFLAGS) -# OHOS_LOCAL begin -if(OHOS) - list(APPEND SANITIZER_CFLAGS -fno-emulated-tls) -endif() -# OHOS_LOCAL end - if(APPLE) set(OS_OPTION OS ${SANITIZER_COMMON_SUPPORTED_OS}) endif() diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 87ab61077f0af5dd0e10c7c88433c3c7428c30e0..3f4f29f455449d3c2f2bc0d25faac1d30c34c4d2 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -459,7 +459,7 @@ #define SANITIZER_INTERCEPT_SEM \ (SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_SOLARIS) // OHOS_LOCAL -#define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL (SI_POSIX && !SI_OHOS) +#define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_POSIX #define SANITIZER_INTERCEPT_MINCORE \ (SI_LINUX || SI_NETBSD || SI_FREEBSD || SI_SOLARIS) #define SANITIZER_INTERCEPT_PROCESS_VM_READV SI_LINUX diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp index d69584ed7802451e5cef87e9c075950da0dac2a8..9cab2a372712882dc5dfed729df603a0d92387d3 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp @@ -1121,7 +1121,7 @@ TSAN_INTERCEPTOR(void, pthread_exit, void *retval) { REAL(pthread_exit)(retval); } -#if SANITIZER_LINUX && !SANITIZER_OHOS // OHOS_LOCAL +#if SANITIZER_LINUX TSAN_INTERCEPTOR(int, pthread_tryjoin_np, void *th, void **ret) { SCOPED_INTERCEPTOR_RAW(pthread_tryjoin_np, th, ret); Tid tid = ThreadConsumeTid(thr, pc, (uptr)th); @@ -2938,7 +2938,7 @@ void InitializeInterceptors() { TSAN_INTERCEPT(pthread_join); TSAN_INTERCEPT(pthread_detach); TSAN_INTERCEPT(pthread_exit); - #if SANITIZER_LINUX && !SANITIZER_OHOS // OHOS_LOCAL + #if SANITIZER_LINUX TSAN_INTERCEPT(pthread_tryjoin_np); TSAN_INTERCEPT(pthread_timedjoin_np); #endif diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp index 06e654197351df6449ca5a3da88794fadd4c2c38..1ee67b87c2bbe823f32af9538b5570cc793c81a5 100644 --- a/libunwind/src/UnwindCursor.hpp +++ b/libunwind/src/UnwindCursor.hpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1 #endif @@ -2711,12 +2712,20 @@ bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) { // [1] https://github.com/torvalds/linux/blob/master/arch/arm64/kernel/vdso/sigreturn.S const pint_t pc = static_cast(this->getReg(UNW_REG_IP)); // The PC might contain an invalid address if the unwind info is bad, so - // directly accessing it could cause a SIGSEGV. - if (!isReadableAddr(pc)) - return false; - auto *instructions = reinterpret_cast(pc); + // directly accessing it could cause a segfault. Use process_vm_readv to read + // the memory safely instead. process_vm_readv was added in Linux 3.2, and + // AArch64 supported was added in Linux 3.7, so the syscall is guaranteed to + // be present. Unfortunately, there are Linux AArch64 environments where the + // libc wrapper for the syscall might not be present (e.g. Android 5), so call + // the syscall directly instead. + uint32_t instructions[2]; + struct iovec local_iov = {&instructions, sizeof instructions}; + struct iovec remote_iov = {reinterpret_cast(pc), sizeof instructions}; + long bytesRead = + syscall(SYS_process_vm_readv, getpid(), &local_iov, 1, &remote_iov, 1, 0); // Look for instructions: mov x8, #0x8b; svc #0x0 - if (instructions[0] != 0xd2801168 || instructions[1] != 0xd4000001) + if (bytesRead != sizeof instructions || instructions[0] != 0xd2801168 || + instructions[1] != 0xd4000001) return false; _info = {}; diff --git a/llvm-build/build.py b/llvm-build/build.py index 794f2fe9187a7f6ef8103e17e8fe3f2382fc39a0..b9cf2d15d9bf016147b2e5ebadbd28d0a6a25578 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -2517,6 +2517,36 @@ class LlvmPackage(BuildUtils): if os.path.exists(src_x86_cxx_static_dir) and os.path.exists(dst_x86_dir): shutil.copy2(src_x86_cxx_static_dir, dst_x86_dir) + + #libcxx-ndk/include/libcxx-ohos/include/c++/v1/__config_site + src_libcxx_dir = os.path.join(libcxx_install_dir, 'include', 'libcxx-ohos', 'include', 'c++', 'v1', '__config_site') + #llvm-install/include/c++/v1/__config_site + dst_libcxx_dir = os.path.join(llvm_install, 'include', 'c++', 'v1') + if os.path.exists(src_libcxx_dir) and os.path.exists(dst_libcxx_dir): + shutil.copy2(src_libcxx_dir, dst_libcxx_dir) + #llvm-install/include/libcxx-ohos/include/c++/v1/__config_site + dst_libcxx_dir2 = os.path.join(llvm_install, 'include', 'libcxx-ohos', 'include', 'c++', 'v1') + if os.path.exists(src_libcxx_dir) and os.path.exists(dst_libcxx_dir2): + shutil.copy2(src_libcxx_dir, dst_libcxx_dir2) + + + def modify_libcxx(self, llvm_install, libcxx_install_dir): + src_lib_dir = os.path.join(llvm_install, 'lib') + + for root, dirs, files in os.walk(src_lib_dir): + for file in files: + if file == 'libc++.a': + libcpp_path = os.path.join(root, file) + # 写入内容到输出文件 + with open(libcpp_path, 'w') as f: + f.write("INPUT(-lc++_static -lc++abi)\n") + + if file == 'libc++.so': + libcpp_path = os.path.join(root, file) + # 写入内容到输出文件 + with open(libcpp_path, 'w') as f: + f.write("INPUT(-lc++_shared)\n") + def copy_lldb_tools_to_llvm_install(self, tools, lldb_path, crt_install, llvm_triple): dst_dir = os.path.join(crt_install, 'bin', llvm_triple) @@ -3312,6 +3342,8 @@ def main(): llvm_libs.build_gtest(llvm_path, llvm_install) llvm_package.move_libcxx(llvm_install, libcxx_ndk_install) + + llvm_package.modify_libcxx(llvm_install, libcxx_ndk_install) if build_config.do_package: if build_utils.host_is_linux():