diff --git a/.gitee/PULL_REQUEST_TEMPLATE.en.md b/.gitee/PULL_REQUEST_TEMPLATE.en.md index e7d9a15062a7e476174b06d81e87ca142db71601..c15c8992b6f4770ba69ba0286f2798e34ca8e8be 100644 --- a/.gitee/PULL_REQUEST_TEMPLATE.en.md +++ b/.gitee/PULL_REQUEST_TEMPLATE.en.md @@ -20,3 +20,4 @@ Development Guidelines: https://gitee.com/openharmony/third_party_llvm-project/b why: +### Compatibility impact assessment, please indicate (Y/N) \ No newline at end of file diff --git a/OAT.xml b/OAT.xml index fe34bbf4d4a419173f6d15376329f3de6b7f4580..0407b602a7499c13540996ab6cf9e2a02f9bb065 100644 --- a/OAT.xml +++ b/OAT.xml @@ -47,7 +47,7 @@ - llvm/LICENSE.TXT|clang/LICENSE.TXT|libcxx/LICENSE.TXT|lldb/LICENSE.TXT|clang-tools-extra/LICENSE.TXT|llvm/utils/lit/LICENSE.TXT|llvm/tools/msbuild/license.txt|llvm/tools/msbuild/license.txt|clang-tools-extra/clang-tidy/cert/LICENSE.TXT|clang-tools-extra/clang-tidy/hicpp/LICENSE.TXT|libclc/LICENSE.TXT|llvm/include/llvm/Support/LICENSE.TXT + llvm/LICENSE.TXT @@ -205,6 +205,9 @@ + + + diff --git a/OpenHarmonyDevelopmentGuidelines.md b/OpenHarmonyDevelopmentGuidelines.md index 29cfad2fa8be2713dc7f8f03b7b58e50d1359a07..13e41c5e663386e7780fa54654884053a2911497 100644 --- a/OpenHarmonyDevelopmentGuidelines.md +++ b/OpenHarmonyDevelopmentGuidelines.md @@ -37,6 +37,10 @@ Some local OHOS change The presence of such marks greatly simplifies porting such code snippets to new LLVM versions. All such changes MUST be accompanied with a test case that MUST fail should the change is reverted. +If the change is from the upstream and is a mainline patch, the OHOS_LOCAL flag does not need to be added. Similar PRs, such as: +- https://gitee.com/openharmony/third_party_llvm-project/pulls/93 +- https://gitee.com/openharmony/third_party_llvm-project/pulls/409 + --------------------- ### Commit title and message diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index bf3dd812b9e8db202d58396c16d286eeaf68acce..9df9776504bc4ec847e87653827f66bf3007d437 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3446,10 +3446,32 @@ void CodeGenFunction::EmitCfiSlowPathCheck( void CodeGenFunction::EmitCfiCheckStub() { llvm::Module *M = &CGM.getModule(); auto &Ctx = M->getContext(); + // OHOS_LOCAL begin + auto &C = getContext(); + QualType QInt8Ty = C.getIntTypeForBitwidth(8, false); + QualType QInt64Ty = C.getIntTypeForBitwidth(64, false); + QualType QInt8PtrTy = C.getPointerType(QInt8Ty); + + FunctionArgList Args; + ImplicitParamDecl ArgCallsiteTypeId(C, QInt64Ty, ImplicitParamDecl::Other); + ImplicitParamDecl ArgAddr(C, QInt8PtrTy, ImplicitParamDecl::Other); + ImplicitParamDecl ArgCFICheckFailData(C, QInt8PtrTy, + ImplicitParamDecl::Other); + Args.push_back(&ArgCallsiteTypeId); + Args.push_back(&ArgAddr); + Args.push_back(&ArgCFICheckFailData); + + const CGFunctionInfo &FI = + CGM.getTypes().arrangeBuiltinFunctionDeclaration(C.VoidTy, Args); + llvm::Function *F = llvm::Function::Create( llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false), llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M); + CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, F, /*IsThunk=*/false); + CGM.SetLLVMFunctionAttributesForDefinition(nullptr, F); + // OHOS_LOCAL end CGM.setDSOLocal(F); + llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F); // FIXME: consider emitting an intrinsic call like // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2) diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index 7afdecefb6147b0604ff95f9d8e9b389b19da6d4..1bbe09030f3c38c7f1a29a5a72ea77e06132d44b 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -403,6 +403,8 @@ 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; @@ -418,6 +420,8 @@ SanitizerMask OHOS::getSupportedSanitizers() const { // OHOS_LOCAL Res |= SanitizerKind::HWAddress; // TODO: Support TSAN and HWASAN and update mask. + if (IsAArch64 || IsX86_64) + Res |= SanitizerKind::Thread; return Res; } diff --git a/clang/test/CodeGen/cfi-check-attrs.c b/clang/test/CodeGen/cfi-check-attrs.c new file mode 100644 index 0000000000000000000000000000000000000000..375aa30074d8874b5a5ddae8c5b15652af10044a --- /dev/null +++ b/clang/test/CodeGen/cfi-check-attrs.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -triple arm-unknown-linux -funwind-tables=1 -fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck %s + +// CHECK: define weak {{.*}}void @__cfi_check({{.*}} [[ATTR:#[0-9]*]] + +// CHECK: attributes [[ATTR]] = {{.*}} uwtable(sync) diff --git a/clang/test/CodeGen/cfi-check-fail.c b/clang/test/CodeGen/cfi-check-fail.c index 09c40d43fef2a7ea22b0ebdf4c24ba9fa7793f1c..89d5bac4c174d98d09dca5fdca9fd322e823da59 100644 --- a/clang/test/CodeGen/cfi-check-fail.c +++ b/clang/test/CodeGen/cfi-check-fail.c @@ -73,7 +73,9 @@ void caller(void (*f)(void)) { // CHECK: [[CONT5]]: // CHECK: ret void -// CHECK: define weak void @__cfi_check(i64 %0, i8* %1, i8* %2) +// OHOS_LOCAL begin +// CHECK: define weak void @__cfi_check(i64 noundef %0, i8* noundef %1, i8* noundef %2) +// OHOS_LOCAL end // CHECK-NOT: } // CHECK: call void @llvm.trap() // CHECK-NEXT: ret void diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index 0e3ce2ad7938d9102a512b19259df9b834df7a64..98ade77f0d76336aef56abe4ffdefdfbb1834bb4 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -565,6 +565,14 @@ if(COMPILER_RT_USE_LLVM_UNWINDER) endif() endif() +# OHOS_LOCAL begin +if (COMPILER_RT_HAS_SCUDO_STANDALONE AND + NOT COMPILER_RT_USE_LLVM_UNWINDER AND # unwinder not set yet + COMPILER_RT_DEFAULT_TARGET_TRIPLE MATCHES "^arm-.*") + list(APPEND COMPILER_RT_UNWINDER_LINK_LIBS "unwind") +endif() +# OHOS_LOCAL end + if (COMPILER_RT_CXX_LIBRARY STREQUAL "libcxx") # We are using the in-tree libc++ so avoid including the default one. append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_COMMON_CFLAGS) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index a549732afea0596899f7b13a7a69df992a585ce5..3c6fe62e1aaf38939e6688587f951c809c1ee3cf 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -814,7 +814,7 @@ else() endif() #TODO(kostyak): add back Android & Fuchsia when the code settles a bit. -if (SCUDO_STANDALONE_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux" AND +if (SCUDO_STANDALONE_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux|OHOS" AND COMPILER_RT_HAS_AUXV) set(COMPILER_RT_HAS_SCUDO_STANDALONE TRUE) else() diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp index 2bbf0ac5240a703e3e48ce6d8e960e7905dd7edb..68683406314987b8520093a2c501a7b91f1e80fd 100644 --- a/compiler-rt/lib/asan/asan_rtl.cpp +++ b/compiler-rt/lib/asan/asan_rtl.cpp @@ -433,6 +433,8 @@ static void AsanInitInternal() { // AsanInitInternal -> android_log_write -> __interceptor_strcmp AndroidLogInit(); + OhosLogInit(); // OHOS_LOCAL + ReplaceSystemMalloc(); DisableCoreDumperIfNecessary(); diff --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp index ef3923eb788db8fae739cbe6c8d4e13c4736f444..5bf1284e1f896f81a5b7164408294cf457da1df4 100644 --- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp +++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp @@ -120,13 +120,6 @@ void GuardedPoolAllocator::enable() { BacktraceMutex.unlock(); } -// OHOS_LOCAL begin -void GuardedPoolAllocator::enableAtFork() { - PoolMutex.unlockAtFork(); - BacktraceMutex.unlockAtFork(); -} -// OHOS_LOCAL end - void GuardedPoolAllocator::iterate(void *Base, size_t Size, iterate_callback Cb, void *Arg) { uintptr_t Start = reinterpret_cast(Base); diff --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h index f1086651395f12f4df0d05945efe83b5363c46c3..152028acd822c28c96b9d8ebc6192f57aa469e30 100644 --- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h +++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h @@ -63,7 +63,6 @@ public: // to allocate memory, until enable() is called. void disable(); void enable(); - void enableAtFork(); // OHOS_LOCAL typedef void (*iterate_callback)(uintptr_t base, size_t size, void *arg); // Execute the callback Cb for every allocation the lies in [Base, Base + diff --git a/compiler-rt/lib/gwp_asan/mutex.h b/compiler-rt/lib/gwp_asan/mutex.h index 299eae6719ea79dd67cb8c992b00906f81867a95..34b91a2880ddcfc12fae4b939cb59a7454f76526 100644 --- a/compiler-rt/lib/gwp_asan/mutex.h +++ b/compiler-rt/lib/gwp_asan/mutex.h @@ -25,7 +25,6 @@ public: bool tryLock(); // Unlock the mutex. void unlock(); - void unlockAtFork(); // OHOS_LOCAL }; class ScopedLock { diff --git a/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp b/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp index f2db40aa3cb9647883df4344cdacc7320560b4b3..149b74238f0d98f3ad2a22d7a90e700116159583 100644 --- a/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp +++ b/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp @@ -106,13 +106,7 @@ void GuardedPoolAllocator::installAtFork() { }; auto Enable = []() { if (auto *S = getSingleton()) -// OHOS_LOCAL begin -#if defined(__OHOS__) - S->enableAtFork(); -#else S->enable(); -#endif -// OHOS_LOCAL end }; pthread_atfork(Disable, Enable, Enable); } diff --git a/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_tls.h b/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_tls.h index 3e2055db3dc55212d788c4b8c806a04f0bad14a6..475b176ccd4742ac7293121db2201f7e1fd2fca5 100644 --- a/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_tls.h +++ b/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_tls.h @@ -44,12 +44,26 @@ static_assert(sizeof(ThreadLocalPackedVariables) == sizeof(uint64_t), #ifdef GWP_ASAN_PLATFORM_TLS_HEADER #include GWP_ASAN_PLATFORM_TLS_HEADER #else +// OHOS_LOCAL begin +#if defined(__OHOS__) +// Musl doesn't support libc using TLS variables now, +// so musl puts gwp_asan tls on the pthread, this interface can return the corresponding address. +extern "C" void* get_platform_gwp_asan_tls_slot(); +namespace gwp_asan { +inline ThreadLocalPackedVariables *getThreadLocals() { + return reinterpret_cast(get_platform_gwp_asan_tls_slot()); +} +} // namespace gwp_asan +#else namespace gwp_asan { inline ThreadLocalPackedVariables *getThreadLocals() { alignas(8) static GWP_ASAN_TLS_INITIAL_EXEC ThreadLocalPackedVariables Locals; return &Locals; } } // namespace gwp_asan +#endif // __OHOS__ +// OHOS_LOCAL end + #endif // GWP_ASAN_PLATFORM_TLS_HEADER #endif // GWP_ASAN_GUARDED_POOL_ALLOCATOR_TLS_H_ diff --git a/compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp b/compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp index a3ee11c0e78ae0ea462a7da22d93d16834822cfa..8bd405e1074cb39f7ce3a54cd53f5c49845e4e88 100644 --- a/compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp +++ b/compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.cpp @@ -27,16 +27,4 @@ void Mutex::unlock() { // Remove warning for non-debug builds. (void)Status; } - -// OHOS_LOCAL begin -// 1、OHOS uses recursive locks to avoid deadlock, such as this call chain: -// `gwp_asan malloc -> find double free -> get lock -> trigger segv -> -// segv handler -> malloc -> gwp_asan malloc` -// 2、It will be failed to unlock recursive lock after fork because tid changes, -// so we just create a new recursive lock here. -void Mutex::unlockAtFork() { - Mu = {{{PTHREAD_MUTEX_RECURSIVE}}}; -} -// OHOS_LOCAL end - } // namespace gwp_asan diff --git a/compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.h b/compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.h index 57b981c6e1b03de4093edcda1f67fac784f743c2..7f0239198f565858e661a654927e969b847f171e 100644 --- a/compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.h +++ b/compiler-rt/lib/gwp_asan/platform_specific/mutex_posix.h @@ -15,13 +15,7 @@ namespace gwp_asan { class PlatformMutex { protected: -// OHOS_LOCAL begin -#if defined(__OHOS__) - pthread_mutex_t Mu = {{{PTHREAD_MUTEX_RECURSIVE}}}; -#else pthread_mutex_t Mu = PTHREAD_MUTEX_INITIALIZER; -#endif -// OHOS_LOCAL end }; } // namespace gwp_asan diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp index 235aa73740af811a8d25785f087179835fb08100..41c0c8b51fdfbbccd7664ec55cf4f006fc1beff5 100644 --- a/compiler-rt/lib/hwasan/hwasan.cpp +++ b/compiler-rt/lib/hwasan/hwasan.cpp @@ -351,6 +351,7 @@ __attribute__((constructor(0))) void __hwasan_init() { SetPrintfAndReportCallback(AppendToErrorMessageBuffer); // This may call libc -> needs initialized shadow. AndroidLogInit(); + OhosLogInit(); // OHOS_LOCAL InitializeInterceptors(); InstallDeadlySignalHandlers(HwasanOnDeadlySignal); diff --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/CMakeLists.txt index 9bc93abc553a1eb849944c3ae826fb3a76170150..c7012e08a9ded0affa92b853c6c48d916f247e9b 100644 --- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt +++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt @@ -219,6 +219,12 @@ 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_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 08c6062ba067856502ace04bada1ac516fce46f2..c4153201a1a04632b1d23e23f89d646642e66003 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -925,9 +925,11 @@ inline void LogMessageOnPrintf(const char *str) {} #if SANITIZER_LINUX || SANITIZER_WIN_TRACE // Initialize Android logging. Any writes before this are silently lost. void AndroidLogInit(); +void OhosLogInit(); // OHOS_LOCAL void SetAbortMessage(const char *); #else inline void AndroidLogInit() {} +inline void OhosLogInit() {} // OHOS_LOCAL // FIXME: MacOS implementation could use CRSetCrashLogMessage. inline void SetAbortMessage(const char *) {} #endif diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 006d5a9f5d382417da4a4fa25569f3dd45b9c431..c489cb2979f1835b2310484fbbcf4fd044ee228a 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -2670,7 +2670,7 @@ INTERCEPTOR(int, wait3, int *status, int options, void *rusage) { } return res; } -#if SANITIZER_ANDROID || SANITIZER_OHOS +#if SANITIZER_ANDROID INTERCEPTOR(int, __wait4, int pid, int *status, int options, void *rusage) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, __wait4, pid, status, options, rusage); @@ -3250,7 +3250,7 @@ static void read_msghdr_control(void *ctx, void *control, uptr controllen) { __sanitizer_cmsghdr *cmsg = (__sanitizer_cmsghdr *)p; COMMON_INTERCEPTOR_READ_RANGE(ctx, &cmsg->cmsg_len, sizeof(cmsg->cmsg_len)); - if (p + RoundUpTo(cmsg->cmsg_len, sizeof(uptr)) > control_end) break; + if (control_end - p < RoundUpTo(cmsg->cmsg_len, sizeof(uptr))) break; // OHOS_LOCAL COMMON_INTERCEPTOR_READ_RANGE(ctx, &cmsg->cmsg_level, sizeof(cmsg->cmsg_level)); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index f03ef2562033f78452f64eae697fa20cbe3a52d8..630def6c0a57c7f3cd1d80f45372174e63ba0fbb 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2090,7 +2090,41 @@ bool SignalContext::IsTrueFaultingAddress() const { } void SignalContext::DumpAllRegisters(void *context) { - // FIXME: Implement this. + // OHOS_LOCAL begin + Report("Register values:\n"); + + ucontext_t *ucontext = (ucontext_t*)context; + # define DUMPREG64(r) \ + Printf("x%s = 0x%016llx ", #r, ucontext->uc_mcontext.regs[r]); + # define DUMPREGA64(r) \ + Printf("%s = 0x%016llx ", #r, ucontext->uc_mcontext. r); + # define DUMPREG32(r) \ + Printf("%s = 0x%08x ", #r, ucontext->uc_mcontext->__ss.__ ## r); + # define DUMPREG_(r) Printf(" "); DUMPREG(r); + # define DUMPREG__(r) Printf(" "); DUMPREG(r); + # define DUMPREG___(r) Printf(" "); DUMPREG(r); + + #if defined(__aarch64__) + #define DUMPREG(r) DUMPREG64(r) + DUMPREG_(0); DUMPREG_(1); DUMPREG_(2); DUMPREG_(3); Printf("\n"); + DUMPREG_(4); DUMPREG_(5); DUMPREG_(6); DUMPREG_(7); Printf("\n"); + DUMPREG_(8); DUMPREG_(9); DUMPREG(10); DUMPREG(11); Printf("\n"); + DUMPREG(12); DUMPREG(13); DUMPREG(14); DUMPREG(15); Printf("\n"); + DUMPREG(16); DUMPREG(17); DUMPREG(18); DUMPREG(19); Printf("\n"); + DUMPREG(20); DUMPREG(21); DUMPREG(22); DUMPREG(23); Printf("\n"); + DUMPREG(24); DUMPREG(25); DUMPREG(26); DUMPREG(27); Printf("\n"); + DUMPREG(28); DUMPREG(29); DUMPREG(30); DUMPREGA64(sp); Printf("\n"); + + #endif + + # undef DUMPREG64 + # undef DUMPREGA64 + # undef DUMPREG32 + # undef DUMPREG_ + # undef DUMPREG__ + # undef DUMPREG___ + # undef DUMPREG + // OHOS_LOCAL end } static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp index 182155687d08c08bc8bd681489ad11e02061e848..785c399d02384e18d68e315ac1bad499742bccf6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -896,7 +896,34 @@ void SetAbortMessage(const char *str) { if (&android_set_abort_message) android_set_abort_message(str); } +// OHOS_LOCAL begin +#elif SANITIZER_OHOS + +void AndroidLogInit() {} + +static atomic_uint8_t ohos_log_initialized; + +void OhosLogInit() { + atomic_store(&ohos_log_initialized, 1, memory_order_release); +} + +static bool ShouldLogAfterPrintf() { + return atomic_load(&ohos_log_initialized, memory_order_acquire); +} + +extern "C" SANITIZER_WEAK_ATTRIBUTE int musl_log(const char *fmt, ...); +void WriteOneLineToSyslog(const char *s) { + if (&musl_log) { + musl_log(s); + } else { + syslog(LOG_INFO, "%s", s); + } +} +void SetAbortMessage(const char *str) {} + #else +void OhosLogInit() {} + void AndroidLogInit() {} static bool ShouldLogAfterPrintf() { return true; } @@ -910,6 +937,7 @@ void LogMessageOnPrintf(const char *str) { if (common_flags()->log_to_syslog && ShouldLogAfterPrintf()) WriteToSyslog(str); } +// OHOS_LOCAL end #endif // SANITIZER_LINUX diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index b78534e8fc4210c103cf6a8974df165abe7346aa..66ace37d4d6256f8efb7db99c34df2164e0c5ad1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -241,8 +241,10 @@ #define SANITIZER_INTERCEPT_TIME SI_POSIX #define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS) #define SANITIZER_INTERCEPT_GLOB64 SI_GLIBC -#define SANITIZER_INTERCEPT___B64_TO SI_LINUX_NOT_ANDROID -#define SANITIZER_INTERCEPT___DN_EXPAND SI_LINUX_NOT_ANDROID +// OHOS_LOCAL begin +#define SANITIZER_INTERCEPT___B64_TO (SI_LINUX_NOT_ANDROID && !SI_OHOS) +#define SANITIZER_INTERCEPT___DN_EXPAND (SI_LINUX_NOT_ANDROID && !SI_OHOS) +// OHOS_LOCAL end #define SANITIZER_INTERCEPT_POSIX_SPAWN SI_POSIX #define SANITIZER_INTERCEPT_WAIT SI_POSIX #define SANITIZER_INTERCEPT_INET SI_POSIX @@ -360,11 +362,14 @@ #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETTYPE SI_POSIX #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPROTOCOL \ (SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) +// OHOS_LOCAL begin #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPRIOCEILING \ - (SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + ((SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) && !SI_OHOS) #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST \ - (SI_LINUX_NOT_ANDROID || SI_SOLARIS) -#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST_NP SI_LINUX_NOT_ANDROID + ((SI_LINUX_NOT_ANDROID || SI_SOLARIS) && !SI_OHOS) +#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST_NP \ + (SI_LINUX_NOT_ANDROID && !SI_OHOS) +// OHOS_LOCAL end #define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETPSHARED \ (SI_POSIX && !SI_NETBSD) #define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETKIND_NP SI_GLIBC @@ -405,10 +410,12 @@ #define SANITIZER_INTERCEPT_PTHREAD_MUTEX SI_POSIX #define SANITIZER_INTERCEPT___PTHREAD_MUTEX SI_GLIBC #define SANITIZER_INTERCEPT___LIBC_MUTEX SI_NETBSD +// OHOS_LOCAL begin #define SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP \ - (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS || SI_OHOS) #define SANITIZER_INTERCEPT_PTHREAD_GETNAME_NP \ - (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS || SI_OHOS) +// OHOS_LOCAL end #define SANITIZER_INTERCEPT_TLS_GET_ADDR \ (SI_FREEBSD || SI_NETBSD || (SI_LINUX_NOT_ANDROID && !SI_OHOS) || SI_SOLARIS) @@ -443,8 +450,9 @@ #define SANITIZER_INTERCEPT_FCLOSE SI_POSIX #ifndef SANITIZER_INTERCEPT_DLOPEN_DLCLOSE +// OHOS_LOCAL #define SANITIZER_INTERCEPT_DLOPEN_DLCLOSE \ - (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || (SI_LINUX_NOT_ANDROID && !SI_OHOS) || SI_MAC || SI_SOLARIS) #endif #define SANITIZER_INTERCEPT_GETPASS \ @@ -455,7 +463,8 @@ #define SANITIZER_INTERCEPT_FOPENCOOKIE SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_SEM \ (SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_SOLARIS) -#define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_POSIX +// OHOS_LOCAL +#define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL (SI_POSIX && !SI_OHOS) #define SANITIZER_INTERCEPT_MINCORE \ (SI_LINUX || SI_NETBSD || SI_FREEBSD || SI_SOLARIS) #define SANITIZER_INTERCEPT_PROCESS_VM_READV SI_LINUX @@ -577,8 +586,9 @@ #define SANITIZER_INTERCEPT_FDEVNAME SI_FREEBSD #define SANITIZER_INTERCEPT_GETUSERSHELL (SI_POSIX && !SI_ANDROID) #define SANITIZER_INTERCEPT_SL_INIT (SI_FREEBSD || SI_NETBSD) +// OHOS_LOCAL #define SANITIZER_INTERCEPT_CRYPT (SI_POSIX && !SI_ANDROID) -#define SANITIZER_INTERCEPT_CRYPT_R (SI_LINUX && !SI_ANDROID) +#define SANITIZER_INTERCEPT_CRYPT_R (SI_LINUX && !SI_ANDROID && !SI_OHOS) #define SANITIZER_INTERCEPT_GETRANDOM \ ((SI_LINUX && __GLIBC_PREREQ(2, 25)) || SI_FREEBSD) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp index e0568c9b62d5ee6c838e2d5d4bf6d3da776416e3..e7b7d6f31f0f0dc2b3f34bd270a928da295aa4c3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp @@ -1182,6 +1182,8 @@ void LogFullErrorReport(const char *buffer) { TraceLoggingValue(buffer, "AsanReportContents")); } } + +void OhosLogInit(void) {} // OHOS_LOCAL #endif // SANITIZER_WIN_TRACE void InitializePlatformCommonFlags(CommonFlags *cf) {} diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt index 4b586bc662b45b55059078b840723209b7b00c10..55e97ac0dadf49ce7438f8042422b16a0e7130a0 100644 --- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt @@ -30,7 +30,13 @@ endif() set(SCUDO_LINK_FLAGS) -list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro) +# OHOS_LOCAL begin +# We do not have all symbols at build time (get_platform_gwp_asan_tls_slot), +# since musl is built without them for some reason +if (NOT OHOS) + list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro) +endif() +# OHOS_LOCAL end list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections) @@ -141,7 +147,8 @@ append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread SCUDO_LINK_FLAGS) append_list_if(FUCHSIA zircon SCUDO_LINK_LIBS) -if(COMPILER_RT_DEFAULT_TARGET_ARCH MATCHES "mips|mips64|mipsel|mips64el") +if(COMPILER_RT_DEFAULT_TARGET_ARCH MATCHES "mips|mips64|mipsel|mips64el" AND + NOT OHOS) # OHOS_LOCAL OHOS uses compiler-rt list(APPEND SCUDO_LINK_LIBS atomic) endif() diff --git a/compiler-rt/lib/tsan/CMakeLists.txt b/compiler-rt/lib/tsan/CMakeLists.txt index a327fb14de9a5d6fa09a4c99888e72b0637e5abd..23f1bc15207afa88e991cf2c341f96b8457f9658 100644 --- a/compiler-rt/lib/tsan/CMakeLists.txt +++ b/compiler-rt/lib/tsan/CMakeLists.txt @@ -15,6 +15,12 @@ if(COMPILER_RT_TSAN_DEBUG_OUTPUT) list(APPEND TSAN_CFLAGS -DTSAN_DEBUG_OUTPUT=2) endif() +# OHOS_LOCAL begin +if(OHOS) + list(APPEND TSAN_CFLAGS -fno-emulated-tls) +endif() +# OHOS_LOCAL end + # Add the actual runtime library. option(TSAN_USE_OLD_RUNTIME "Use the old tsan runtime (temporal option for emergencies)." OFF) if (TSAN_USE_OLD_RUNTIME) diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp index 17f6b1f472d8fcb823070527073d8dabf3602a39..825814f54d824a1c24b169c041682d712029e957 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp @@ -1109,7 +1109,7 @@ TSAN_INTERCEPTOR(void, pthread_exit, void *retval) { REAL(pthread_exit)(retval); } -#if SANITIZER_LINUX +#if SANITIZER_LINUX && !SANITIZER_OHOS // OHOS_LOCAL 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); @@ -2835,7 +2835,7 @@ void InitializeInterceptors() { TSAN_INTERCEPT(pthread_join); TSAN_INTERCEPT(pthread_detach); TSAN_INTERCEPT(pthread_exit); - #if SANITIZER_LINUX + #if SANITIZER_LINUX && !SANITIZER_OHOS // OHOS_LOCAL TSAN_INTERCEPT(pthread_tryjoin_np); TSAN_INTERCEPT(pthread_timedjoin_np); #endif diff --git a/compiler-rt/lib/tsan/tests/CMakeLists.txt b/compiler-rt/lib/tsan/tests/CMakeLists.txt index 8afd217cb8b0e06d649c5abdac1478f96fc49a74..d36ed16b499a8e0ad6126ddf8709aee5ae6ef82d 100644 --- a/compiler-rt/lib/tsan/tests/CMakeLists.txt +++ b/compiler-rt/lib/tsan/tests/CMakeLists.txt @@ -15,6 +15,12 @@ set(TSAN_UNITTEST_CFLAGS -fno-rtti ) +# OHOS_LOCAL begin +if(OHOS) + list(APPEND TSAN_UNITTEST_CFLAGS -fno-emulated-tls) +endif() +# OHOS_LOCAL end + if(COMPILER_RT_TSAN_DEBUG_OUTPUT) # Need to match these flags with the runtime. list(APPEND TSAN_UNITTEST_CFLAGS -DTSAN_COLLECT_STATS=1 diff --git a/compiler-rt/lib/ubsan/ubsan_init.cpp b/compiler-rt/lib/ubsan/ubsan_init.cpp index 5802d58896f0fe8066bd707b3e760d3dbd7a4e82..01080567331ed894bf855f01b0b3a69720c63fd6 100644 --- a/compiler-rt/lib/ubsan/ubsan_init.cpp +++ b/compiler-rt/lib/ubsan/ubsan_init.cpp @@ -46,6 +46,7 @@ static void CommonStandaloneInit() { __sanitizer::InitializePlatformEarly(); __sanitizer_set_report_path(common_flags()->log_path); AndroidLogInit(); + OhosLogInit(); // OHOS_LOCAL InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir); CommonInit(); diff --git a/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp b/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp index 559f9434e3925dc7ed3801378610ba794cd7b074..f0f36ec310c71b4c3885a011b551a519b7a52111 100644 --- a/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp +++ b/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp @@ -38,7 +38,8 @@ void *run(void *arg) { for (size_t i = 0; i < niter; ++i) { random_delay(&seed); - // CHECK: ERROR: AddressSanitizer: use-after-poison + // OHOS_LOCAL + // CHECK-DAG: ERROR: AddressSanitizer: use-after-poison volatile int idx = 0; tmp[idx] = 0; } @@ -71,7 +72,8 @@ int main(int argc, char **argv) { } } - // CHECK: All threads terminated + // OHOS_LOCAL + // CHECK-DAG: All threads terminated printf("All threads terminated\n"); delete [] tids; diff --git a/compiler-rt/test/gwp_asan/lit.cfg.py b/compiler-rt/test/gwp_asan/lit.cfg.py index c806ae2d47271e6bb44acb163f05429ed0f57df0..58658a4551dc45f8186b74213b8acf4e47c5daf5 100644 --- a/compiler-rt/test/gwp_asan/lit.cfg.py +++ b/compiler-rt/test/gwp_asan/lit.cfg.py @@ -51,6 +51,6 @@ default_gwp_asan_options += ':' config.substitutions.append(('%env_scudo_options=', 'env SCUDO_OPTIONS=' + default_gwp_asan_options)) -# GWP-ASan tests are currently supported on Linux only. -if config.host_os not in ['Linux']: +# GWP-ASan tests are currently supported on Linux and OHOS only. +if config.host_os not in ['Linux', 'OHOS']: # OHOS_LOCAL config.unsupported = True diff --git a/compiler-rt/test/hwasan/TestCases/Linux/lit.local.cfg.py b/compiler-rt/test/hwasan/TestCases/Linux/lit.local.cfg.py index 57271b8078a49730b9ae06f901ec3faf907dcef5..ce7ce5ddde93dd9896fe163d5c871ef899cb3316 100644 --- a/compiler-rt/test/hwasan/TestCases/Linux/lit.local.cfg.py +++ b/compiler-rt/test/hwasan/TestCases/Linux/lit.local.cfg.py @@ -5,5 +5,5 @@ def getRoot(config): root = getRoot(config) -if root.host_os not in ['Linux']: +if root.host_os not in ['Linux', 'OHOS']: # OHOS_LOCAL config.unsupported = True diff --git a/compiler-rt/test/hwasan/TestCases/abort-message-android.cpp b/compiler-rt/test/hwasan/TestCases/abort-message-android.cpp index f89b929d454d4594d58916a52877d826ee3b5a99..c038d74a546b52a3b86f560d6d103369edd1c559 100644 --- a/compiler-rt/test/hwasan/TestCases/abort-message-android.cpp +++ b/compiler-rt/test/hwasan/TestCases/abort-message-android.cpp @@ -1,6 +1,7 @@ // RUN: %clangxx_hwasan -DERR=1 %s -o %t && not %run %t 2>&1 | FileCheck %s // RUN: %clangxx_hwasan -DERR=2 %s -o %t && not %run %t 2>&1 | FileCheck %s -// REQUIRES: android +// OHOS_LOCAL +// REQUIRES: android && !ohos_family #include #include diff --git a/compiler-rt/test/hwasan/TestCases/libc_thread_freeres.c b/compiler-rt/test/hwasan/TestCases/libc_thread_freeres.c index 83451f5bdf4061551acfe77df2c5abc4e2b025a4..10521397211289c74a1a2f4f34337a33102dc41a 100644 --- a/compiler-rt/test/hwasan/TestCases/libc_thread_freeres.c +++ b/compiler-rt/test/hwasan/TestCases/libc_thread_freeres.c @@ -1,5 +1,6 @@ // RUN: %clang_hwasan %s -o %t && %env_hwasan_opts=random_tags=1 %run %t -// REQUIRES: stable-runtime +// OHOS_LOCAL +// REQUIRES: stable-runtime && !ohos_family #include #include diff --git a/compiler-rt/test/hwasan/TestCases/preinit_array.c b/compiler-rt/test/hwasan/TestCases/preinit_array.c index 54d3ee7eea158a96a93fa9df512e6a2d3ec796e8..7e9c807fa34c0fe99e65e434d2b72298bc17f3e4 100644 --- a/compiler-rt/test/hwasan/TestCases/preinit_array.c +++ b/compiler-rt/test/hwasan/TestCases/preinit_array.c @@ -3,6 +3,10 @@ // RUN: %clang_hwasan %s -o %t // RUN: %run %t +// OHOS_LOCAL +// musl doesn't have .preinit_array section +// REQUIRES: !ohos_family + volatile int Global; void StoreToGlobal() { Global = 42; } diff --git a/compiler-rt/test/hwasan/TestCases/print-memory-usage-android.c b/compiler-rt/test/hwasan/TestCases/print-memory-usage-android.c index 5a057928ba7521c26a6ef9d9e3248d8a4dc9058a..3dc8a33bc9144255363fe5e0df33de236dc03877 100644 --- a/compiler-rt/test/hwasan/TestCases/print-memory-usage-android.c +++ b/compiler-rt/test/hwasan/TestCases/print-memory-usage-android.c @@ -1,6 +1,7 @@ // Tests __hwasan_print_memory_usage through /proc/$PID/maps. // RUN: %clang_hwasan %s -o %t && %env_hwasan_opts=export_memory_stats=1 %run %t 2>&1 | FileCheck %s -// REQUIRES: android +// OHOS_LOCAL +// REQUIRES: android && !ohos_family #include #include diff --git a/compiler-rt/test/hwasan/TestCases/sizes.cpp b/compiler-rt/test/hwasan/TestCases/sizes.cpp index 2cb70f52147ac18037e83ed11419e469e0e69bf0..32c2cfc27e86470320f7ddabd7d2c9b7def4c51e 100644 --- a/compiler-rt/test/hwasan/TestCases/sizes.cpp +++ b/compiler-rt/test/hwasan/TestCases/sizes.cpp @@ -23,6 +23,10 @@ // allocator can allocate. Tests that an integer overflow in the parameters of // calloc is caught. +// OHOS_LOCAL +// we can't link with libstdc++ +// REQUIRES: !ohos_family + #include #include #include diff --git a/compiler-rt/test/hwasan/TestCases/stack-uas.c b/compiler-rt/test/hwasan/TestCases/stack-uas.c index 7f5a6f26d0675bfc86f977cda973e466dd66b2c6..ca81663e00e6c250fc693726f04d092e7e26f591 100644 --- a/compiler-rt/test/hwasan/TestCases/stack-uas.c +++ b/compiler-rt/test/hwasan/TestCases/stack-uas.c @@ -17,6 +17,10 @@ // Stack histories currently are not recorded on x86. // XFAIL: x86_64 +// OHOS_LOCAL +// Return value is undefined on OHOS +// XFAIL: ohos_family + void USE(void *x) { // pretend_to_do_something(void *x) __asm__ __volatile__("" : diff --git a/compiler-rt/test/hwasan/lit.cfg.py b/compiler-rt/test/hwasan/lit.cfg.py index 85fda0c70324c268c49d4026a00fb1727f19891c..4b3313a374bab6f59055315b592792ef66e7bd15 100644 --- a/compiler-rt/test/hwasan/lit.cfg.py +++ b/compiler-rt/test/hwasan/lit.cfg.py @@ -53,6 +53,5 @@ config.substitutions.append(('%env_hwasan_opts=', # Default test suffixes. config.suffixes = ['.c', '.cpp'] - -if config.host_os not in ['Linux', 'Android'] or not config.has_lld: +if config.host_os not in ['Linux', 'Android', 'OHOS'] or not config.has_lld: # OHOS_LOCAL config.unsupported = True diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py index 4c43a0b0143ec11957090c0663ae292b1a32554a..869d0e233ef34d946260aae60ad71b1cfc4b2121 100644 --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -7,10 +7,15 @@ import os import platform import re import subprocess +import sys # OHOS_LOCAL import json import lit.formats import lit.util +# OHOS_LOCAL begin +from lit.llvm import llvm_config +from lit.llvm.subst import ToolSubst, WrapTool, FindTool +# OHOS_LOCAL end # Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if # it's not available. @@ -175,8 +180,6 @@ if config.asan_shadow_scale != '': if config.memprof_shadow_scale != '': config.target_cflags += " -mllvm -memprof-mapping-scale=" + config.memprof_shadow_scale -config.environment = dict(os.environ) - # Clear some environment variables that might affect Clang. possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS', 'MSAN_OPTIONS', 'UBSAN_OPTIONS', @@ -256,6 +259,7 @@ def get_ios_commands_dir(): return os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "ios_commands") # Allow tests to be executed on a simulator or remotely. +tools = [] # OHOS_LOCAL if emulator: config.substitutions.append(('%run', emulator)) config.substitutions.append(('%env ', "env ")) @@ -264,6 +268,7 @@ if emulator: lit_config.warning('%device_rm is not implemented') config.substitutions.append(('%device_rm', 'echo ')) config.compile_wrapper = "" +# OHOS_LOCAL begin elif is_ohos_family_mobile(): config.available_features.add('ohos_family') # FIXME: some tests for hos also need this now, @@ -273,10 +278,9 @@ elif is_ohos_family_mobile(): config.compile_wrapper = compile_wrapper config.substitutions.append( ('%run', "") ) config.substitutions.append( ('%env ', "env ") ) - # TODO: Implement `%device_rm` to perform removal of files on a device. For - # now just make it a no-op. - lit_config.warning('%device_rm is not implemented') - config.substitutions.append( ('%device_rm', 'echo ') ) + tool_wrapper = os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "ohos_family_commands", "ohos_tool.py") + " " + tools.append(ToolSubst('llvm-objdump', command=WrapTool('llvm-objdump', tool_wrapper), unresolved='fatal')) +# OHOS_LOCAL end elif config.host_os == 'Darwin' and config.apple_platform != "osx": # Darwin tests can be targetting macOS, a device or a simulator. All devices # are declared as "ios", even for iOS derivatives (tvOS, watchOS). Similarly, @@ -346,6 +350,9 @@ else: config.substitutions.append(('%device_rm', 'echo ')) config.compile_wrapper = "" +# OHOS_LOCAL +llvm_config.add_tool_substitutions(tools, [config.llvm_tools_dir] + config.environment['PATH'].split(os.path.pathsep)) + # Define CHECK-%os to check for OS-dependent output. config.substitutions.append(('CHECK-%os', ("CHECK-" + config.host_os))) @@ -521,14 +528,28 @@ if config.android: # OHOS_LOCAL begin elif config.host_os == 'OHOS': + for var in [ + 'HDC', + 'HDC_SERVER_IP_PORT', + 'HDC_UTID', + 'OHOS_REMOTE_TMP_DIR', + 'OHOS_REMOTE_DYN_LINKER', + ]: + if var in os.environ: + config.environment[var] = os.environ[var] + + hdc_imp = os.path.join(os.path.dirname(__file__), 'sanitizer_common', 'ohos_family_commands') + sys.path.append(hdc_imp) + import hdc_constants env = os.environ.copy() - adb = os.environ.get('ADB', 'adb') - device_tmpdir = '/data/local/tmp/Output/' - config.substitutions.append( ('%device_rundir/', device_tmpdir) ) - config.substitutions.append( ('%push_to_device', "%s push " % adb) ) - config.substitutions.append( ('%adb_shell ', "%s shell " % adb) ) - config.substitutions.append( ('%device_rm', "%s shell 'rm ' " % adb) ) - subprocess.check_call([adb, "shell", "mkdir", "-p", device_tmpdir], env=env) + config.substitutions.append( ('%device_rundir/', hdc_constants.TMPDIR) ) + prefix = hdc_constants.get_hdc_cmd_prefix() + prefix_str = ' '.join(prefix) + config.substitutions.append(('%push_to_device', "%s file send " % prefix_str) ) + config.substitutions.append(('%adb_shell ', "%s shell " % prefix_str) ) + config.substitutions.append(('%device_rm', "%s shell 'rm ' " % prefix_str) ) + subprocess.check_call(prefix + ['tconn'], env=env) + subprocess.check_call(prefix + ['shell', 'mkdir', '-p', hdc_constants.TMPDIR], env=env) # OHOS_LOCAL end else: @@ -710,7 +731,11 @@ elif config.android or is_ohos_family_mobile(): # Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL # because the test hangs or fails on one configuration and not the other. -if config.android or (config.target_arch not in ['arm', 'armhf', 'aarch64']): +# OHOS_LOCAL begin +if config.android or config.host_os == 'OHOS' or ( + config.target_arch not in ['arm', 'armhf', 'aarch64'] + ): +# OHOS_LOCAL end config.available_features.add('stable-runtime') if config.asan_shadow_scale: diff --git a/compiler-rt/test/lit.common.configured.in b/compiler-rt/test/lit.common.configured.in index a06ede7e73313af10081e4eb3b53d2c1e6d5ea49..1a20461cbf7d83c322b717e8fcf506e00e9b6cae 100644 --- a/compiler-rt/test/lit.common.configured.in +++ b/compiler-rt/test/lit.common.configured.in @@ -18,6 +18,7 @@ set_default("compiler_rt_src_root", "@COMPILER_RT_SOURCE_DIR@") set_default("compiler_rt_obj_root", "@COMPILER_RT_BINARY_DIR@") set_default("enable_per_target_runtime_dir", @LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_PYBOOL@) set_default("llvm_tools_dir", "@LLVM_TOOLS_DIR@") +set_default("lit_tools_dir", "@LLVM_LIT_TOOLS_DIR@") set_default("llvm_shlib_dir", "@LLVM_LIBRARY_OUTPUT_INTDIR@") set_default("gnu_ld_executable", "@GNU_LD_EXECUTABLE@") set_default("gold_executable", "@GOLD_EXECUTABLE@") @@ -77,5 +78,8 @@ config.compiler_rt_libdir = lit_config.substitute(config.compiler_rt_libdir) if not os.path.exists(config.clang): lit_config.fatal("Can't find compiler on path %r" % config.clang) +import lit.llvm +lit.llvm.initialize(lit_config, config) + # Setup attributes common for all compiler-rt projects. lit_config.load_config(config, "@COMPILER_RT_SOURCE_DIR@/test/lit.common.cfg.py") diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/hdc_constants.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/hdc_constants.py new file mode 100644 index 0000000000000000000000000000000000000000..5fcfb514f4b32a9e5b3f57e8fddee110ef3322d8 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/hdc_constants.py @@ -0,0 +1,19 @@ + +import os + +# TODO: move this to the cmake ? +HDC = os.environ.get('HDC', 'hdc') +HDC_SERVER_IP_PORT = os.environ.get('HDC_SERVER_IP_PORT') +HDC_UTID = os.environ.get('HDC_UTID') +TMPDIR = os.environ.get('OHOS_REMOTE_TMP_DIR', '/data/local/tmp/Output') +DYN_LINKER = os.environ.get('OHOS_REMOTE_DYN_LINKER') + +# emit warning on import if some required constants are not set +if not HDC_SERVER_IP_PORT or not HDC_UTID: + print('Please set "HDC_SERVER_IP_PORT" and "HDC_UTID" environment variables ' + 'to be able to debug on remote device') + +def get_hdc_cmd_prefix(): + server = ['-s', HDC_SERVER_IP_PORT] if HDC_SERVER_IP_PORT else [] + device = ['-t', HDC_UTID] if HDC_UTID else [] + return [HDC, *server, *device] diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py index d4a94c03a654d9e2c77feb63e191367a918766fb..b84161f8b99c3a11efe3593dd209f9eeefd278da 100755 --- a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py @@ -1,9 +1,7 @@ #!/usr/bin/env python3 import os, subprocess, tempfile - -HOS_TMPDIR = '/data/local/tmp/Output' -ADB = os.environ.get('ADB', 'adb') +import hdc_constants verbose = False if os.environ.get('HOS_RUN_VERBOSE') == '1': @@ -11,10 +9,14 @@ if os.environ.get('HOS_RUN_VERBOSE') == '1': def host_to_device_path(path): rel = os.path.relpath(path, "/") - dev = os.path.join(HOS_TMPDIR, rel) + dev = os.path.join(hdc_constants.TMPDIR, rel) return dev -def adb(args, attempts = 1): +def hdc_output(args): + command = hdc_constants.get_hdc_cmd_prefix() + args + return subprocess.check_output(command, stderr=subprocess.STDOUT) + +def hdc(args, attempts=1, check_stdout=''): if verbose: print (args) tmpname = tempfile.mktemp() @@ -22,11 +24,13 @@ def adb(args, attempts = 1): ret = 255 while attempts > 0 and ret != 0: attempts -= 1 - ret = subprocess.call([ADB] + args, stdout=out, stderr=subprocess.STDOUT) - if attempts != 0: - ret = 5 + ret = 0 + output = hdc_output(args) + # hdc exit code is always zero + if check_stdout not in output.decode(): + ret = 255 if ret != 0: - print ("adb command failed", args) + print ("hdc command failed", args) print (tmpname) out.close() out = open(tmpname, 'r') @@ -36,12 +40,19 @@ def adb(args, attempts = 1): return ret def pull_from_device(path): + # hdc can't download empty files + file_sz = hdc_output(['shell', 'du', path]).split() + if file_sz and file_sz[0] == b'0': + return '' + tmp = tempfile.mktemp() - adb(['pull', path, tmp], 5) + hdc(['file', 'recv', path, tmp], attempts=5, check_stdout='FileTransfer finish') text = open(tmp, 'r').read() os.unlink(tmp) return text def push_to_device(path): dst_path = host_to_device_path(path) - adb(['push', path, dst_path], 5) + # hdc do not auto create directories on device + hdc(['shell', 'mkdir', '-p', os.path.dirname(dst_path)]) + hdc(['file', 'send', '-m', path, dst_path], attempts=5, check_stdout='FileTransfer finish') diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py index 265a4a9f8f09d7416168df5cd848be8045c9d095..b3f48571588e6d7c0bbce42eaf7b4a7d2962f53a 100755 --- a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py @@ -21,26 +21,15 @@ while args: output_type = 'object' elif arg == '-o': output = args.pop(0) - elif arg == '-target': - check_trgt = True - elif check_trgt or arg.startswith('--target='): - check_trgt = False - if arg.endswith('-linux-ohos'): - arg = arg.split('=')[-1] - dyld = 'unknown_hos_dyld' - # FIXME: Handle -mfloat-abi=hard for arm - # TODO: Support x86_64 - if arg.startswith('arm'): - dyld = 'ld-musl-arm.so.1' - elif arg.startswith('aarch64'): - dyld = 'ld-musl-aarch64.so.1' - append_args += ['-Wl,--dynamic-linker=' + os.path.join(HOS_TMPDIR, dyld)] +if hdc_constants.DYN_LINKER: + append_args.append('-Wl,--dynamic-linker=' + hdc_constants.DYN_LINKER) if output == None: print ("No output file name!") sys.exit(1) ret = subprocess.call(sys.argv[1:] + append_args) + if ret != 0: sys.exit(ret) diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py index 84a8d9fb709cac3831c0fd229db812107b82f173..675e064fa8ffaa6fbfad75c9653e9f569a44ee16 100755 --- a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 import os, signal, sys, subprocess import re @@ -6,12 +6,52 @@ from ohos_common import * device_binary = host_to_device_path(sys.argv[0]) +def map_path(path, do_push): + if os.path.exists(path): + if do_push: + push_to_device(path) + return host_to_device_path(path) + return path + +def map_list(value, sep, regex, get_path_and_do_push): + def repl(m): + path, do_push = get_path_and_do_push(m) + return map_path(path, do_push) + + opts = value.split(sep) + return sep.join(re.sub(regex, repl, opt) for opt in opts) + def build_env(): args = [] + sanitizers = ( + 'HWASAN', 'ASAN', 'LSAN', 'MEMPROF', 'MSAN', 'TSAN', 'UBSAN', 'SCUDO' + ) + for san in sanitizers: + # for all sanitizers we need 'abort_on_error=0', + # so prepare key for them, to set value later + opt_str = '%s_OPTIONS' % san + if opt_str not in os.environ: + os.environ[opt_str] = '' + + # All sanitizers need external symbolizers for some tests + # set them by default to llvm-symbolizer + symb_name = '%s_SYMBOLIZER_PATH' % san + args.append('%s=%s' % (symb_name, os.environ.get('LLVM_SYMBOLIZER_PATH', + os.path.join(hdc_constants.TMPDIR,'llvm-symbolizer-aarch64')))) # HOS linker ignores RPATH. Set LD_LIBRARY_PATH to Output dir. - args.append('LD_LIBRARY_PATH=%s' % (HOS_TMPDIR,)) + args.append('LD_LIBRARY_PATH=%s' % ( hdc_constants.TMPDIR,)) for (key, value) in os.environ.items(): - if key in ['ASAN_ACTIVATION_OPTIONS', 'SCUDO_OPTIONS'] or key.endswith('SAN_OPTIONS'): + san_opt = key.endswith('SAN_OPTIONS') + if san_opt: + value += ':abort_on_error=0' + if key in ['ASAN_ACTIVATION_OPTIONS', 'SCUDO_OPTIONS'] or san_opt or key == 'LD_LIBRARY_PATH': + if key == 'TSAN_OPTIONS': + # Map TSan suppressions file to device + value = map_list(value, ':', r'(?<=suppressions=)(.+)', lambda m: (m.group(1), True)) + elif key == 'LD_LIBRARY_PATH': + # Map LD_LIBRARY_PATH to device + value = map_list(value, ':', r'(.+)', lambda m: (m.group(1), False)) + args.append('%s="%s"' % (key, value)) return ' '.join(args) @@ -22,14 +62,17 @@ device_stderr = device_binary + '.stderr' device_exitcode = device_binary + '.exitcode' device_linker = '' -ret = adb(['shell', 'cd %s && %s %s %s %s >%s 2>%s ; echo $? >%s' % - (HOS_TMPDIR, device_env, device_linker, device_binary, device_args, - device_stdout, device_stderr, device_exitcode)]) -if ret != 0: - sys.exit(ret) +# Currently OHOS set log_path in UBSAN_OPTIONS +# Tests expects to see output in stdout/stderr and fails when it is not there +# So unset UBSAN_OPTIONS before run tests. +hdc(['shell', 'unset UBSAN_OPTIONS && cd %s && %s %s %s %s >%s 2>%s ; echo $? >%s' % + (hdc_constants.TMPDIR, device_env, device_linker, device_binary, device_args, + device_stdout, device_stderr, device_exitcode)]) sys.stdout.write(pull_from_device(device_stdout)) sys.stderr.write(pull_from_device(device_stderr)) +sys.stdout.flush() +sys.stderr.flush() retcode = int(pull_from_device(device_exitcode)) # If the device process died with a signal, do abort(). # Not exactly the same, but good enough to fool "not --crash". diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_tool.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_tool.py new file mode 100755 index 0000000000000000000000000000000000000000..cb3eb0fdabd6c386b0e18ebd9ce07db1adf104f5 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_tool.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +import os, sys, subprocess + +def map_arg(arg): + if not arg.startswith('-') and os.path.exists(arg) and os.path.exists(arg + '.real'): + return arg + '.real' + return arg + +args = [map_arg(arg) for arg in sys.argv[2:]] +sys.exit(subprocess.call([sys.argv[1]] + args)) diff --git a/compiler-rt/test/scudo/lit.cfg.py b/compiler-rt/test/scudo/lit.cfg.py index 236d645f3b940bf62467110b8fb75130bfb4d222..60cdeb65bd509296d24f00eabfaed116fff84ce3 100644 --- a/compiler-rt/test/scudo/lit.cfg.py +++ b/compiler-rt/test/scudo/lit.cfg.py @@ -45,7 +45,7 @@ config.substitutions.append(("%shared_minlibscudo", shared_minlibscudo)) # Platform-specific default SCUDO_OPTIONS for lit tests. default_scudo_opts = '' -if config.android: +if config.android or config.host_os == 'OHOS': # OHOS_LOCAL # Android defaults to abort_on_error=1, which doesn't work for us. default_scudo_opts = 'abort_on_error=0' @@ -59,6 +59,6 @@ if default_scudo_opts: config.substitutions.append(('%env_scudo_opts=', 'env SCUDO_OPTIONS=' + default_scudo_opts)) -# Hardened Allocator tests are currently supported on Linux only. -if config.host_os not in ['Linux']: +# Hardened Allocator tests are currently supported on Linux and OHOS only. +if config.host_os not in ['Linux', 'OHOS']: # OHOS_LOCAL config.unsupported = True diff --git a/compiler-rt/test/scudo/malloc.cpp b/compiler-rt/test/scudo/malloc.cpp index afa7ee47c03b370b73c7088cf167b25598b8fbe2..e0ba5deace3e64c698a9d2974b32df2975090e5a 100644 --- a/compiler-rt/test/scudo/malloc.cpp +++ b/compiler-rt/test/scudo/malloc.cpp @@ -11,6 +11,12 @@ #include +// OHOS_LOCAL begin +#ifdef __OHOS__ +#include +#endif +// OHOS_LOCAL end + int main(int argc, char **argv) { void *p; std::vector sizes{1, 8, 16, 32, 1024, 32768, diff --git a/compiler-rt/test/scudo/overflow.c b/compiler-rt/test/scudo/overflow.c index 7df9f8ba3534b05e401f3086d0b18f49125c3753..8c0d797cc086f0a9d42148a023814f8ea9285ea8 100644 --- a/compiler-rt/test/scudo/overflow.c +++ b/compiler-rt/test/scudo/overflow.c @@ -8,6 +8,12 @@ #include #include +// OHOS_LOCAL begin +#ifdef __OHOS__ +#include +#endif +// OHOS_LOCAL end + int main(int argc, char **argv) { ssize_t offset = sizeof(void *) == 8 ? 8 : 0; diff --git a/compiler-rt/test/tsan/CMakeLists.txt b/compiler-rt/test/tsan/CMakeLists.txt index 25e95aa98cf9501109f41beb14f2343476ac9d69..45039aecff7b72de1e2c59546587382715e4abf1 100644 --- a/compiler-rt/test/tsan/CMakeLists.txt +++ b/compiler-rt/test/tsan/CMakeLists.txt @@ -122,11 +122,15 @@ if(COMPILER_RT_INCLUDE_TESTS) ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg.py) endif() - list(APPEND TSAN_TEST_DEPS TsanUnitTests) - list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit) - if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME) - list(APPEND TSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic) + # OHOS_LOCAL begin + if (NOT OHOS) + list(APPEND TSAN_TEST_DEPS TsanUnitTests) + list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit) + if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME) + list(APPEND TSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic) + endif() endif() + # OHOS_LOCAL end endif() add_lit_testsuite(check-tsan "Running ThreadSanitizer tests" diff --git a/compiler-rt/test/tsan/Linux/lit.local.cfg.py b/compiler-rt/test/tsan/Linux/lit.local.cfg.py index 57271b8078a49730b9ae06f901ec3faf907dcef5..ce7ce5ddde93dd9896fe163d5c871ef899cb3316 100644 --- a/compiler-rt/test/tsan/Linux/lit.local.cfg.py +++ b/compiler-rt/test/tsan/Linux/lit.local.cfg.py @@ -5,5 +5,5 @@ def getRoot(config): root = getRoot(config) -if root.host_os not in ['Linux']: +if root.host_os not in ['Linux', 'OHOS']: # OHOS_LOCAL config.unsupported = True diff --git a/compiler-rt/test/tsan/Linux/mutex_robust.cpp b/compiler-rt/test/tsan/Linux/mutex_robust.cpp index 5ca5e70d49a71854ef30e9eefbb27030b7105451..bddf57e9653964eaa4b7836a470db2da8e68a3f5 100644 --- a/compiler-rt/test/tsan/Linux/mutex_robust.cpp +++ b/compiler-rt/test/tsan/Linux/mutex_robust.cpp @@ -1,4 +1,7 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +// OHOS_LOCAL +// pthread_mutexattr_setrobust not available on OHOS musl +// UNSUPPORTED: ohos_family #include #include #include diff --git a/compiler-rt/test/tsan/Linux/mutex_robust2.cpp b/compiler-rt/test/tsan/Linux/mutex_robust2.cpp index 0914c1763604457ec462c186ee23732b88454131..d6cae7a7c4974e9b3cba86c04ff602ce1073a1cb 100644 --- a/compiler-rt/test/tsan/Linux/mutex_robust2.cpp +++ b/compiler-rt/test/tsan/Linux/mutex_robust2.cpp @@ -1,4 +1,7 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s +// OHOS_LOCAL +// pthread_mutexattr_setrobust not available on OHOS musl +// UNSUPPORTED: ohos_family #include #include #include diff --git a/compiler-rt/test/tsan/Linux/thread_timedjoin.c b/compiler-rt/test/tsan/Linux/thread_timedjoin.c index 1d3f1098ece753e2809b7888fd41909229a616b7..a7cdb335bcbefdd24f19adcf44dc0f0a7c10558b 100644 --- a/compiler-rt/test/tsan/Linux/thread_timedjoin.c +++ b/compiler-rt/test/tsan/Linux/thread_timedjoin.c @@ -1,4 +1,7 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +// OHOS_LOCAL +// pthread_timedjoin_np not available on OHOS musl +// UNSUPPORTED: ohos_family #define _GNU_SOURCE #include "../test.h" #include diff --git a/compiler-rt/test/tsan/Linux/thread_tryjoin.c b/compiler-rt/test/tsan/Linux/thread_tryjoin.c index 675e1595528a7504186744f638c94a650cfcf74e..789842e0ed1b953bbe493e6aba532efea8af99aa 100644 --- a/compiler-rt/test/tsan/Linux/thread_tryjoin.c +++ b/compiler-rt/test/tsan/Linux/thread_tryjoin.c @@ -1,4 +1,7 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +// OHOS_LOCAL +// pthread_tryjoin_np not available on OHOS musl +// UNSUPPORTED: ohos_family #define _GNU_SOURCE #include "../test.h" #include @@ -29,7 +32,7 @@ int main() { if (!res) break; check(res); - pthread_yield(); + sched_yield(); // OHOS_LOCAL } var = 2; fprintf(stderr, "PASS\n"); diff --git a/compiler-rt/test/tsan/cond_cancel.c b/compiler-rt/test/tsan/cond_cancel.c index 7f20b8f8add43f99be5bd9d6fc1ab3d2a25ef122..0c741f7106a0f407d8f2ce27c26bb6e7ee8028e3 100644 --- a/compiler-rt/test/tsan/cond_cancel.c +++ b/compiler-rt/test/tsan/cond_cancel.c @@ -9,6 +9,9 @@ // however the same version GLIBC-2.17 will not make fail the test on // powerpc64 BE (VMA=46) // UNSUPPORTED: powerpc64-unknown-linux-gnu +// OHOS_LOCAL +// pthread_cancel not available on OHOS musl +// UNSUPPORTED: ohos_family #include "test.h" diff --git a/compiler-rt/test/tsan/debugging.cpp b/compiler-rt/test/tsan/debugging.cpp index be0a0c7b0824deacc8f89bace5e5262c3b3e9a4a..ec4dd59625c36f8640d770a34c42a2829d6b78dd 100644 --- a/compiler-rt/test/tsan/debugging.cpp +++ b/compiler-rt/test/tsan/debugging.cpp @@ -79,7 +79,8 @@ __tsan_on_report(void *report) { tid, addr, size, write, atomic); // CHECK: tid = 1, addr = [[GLOBAL]], size = 8, write = 1, atomic = 0 fprintf(stderr, "trace[0] = %p, trace[1] = %p\n", trace[0], trace[1]); - // CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = {{0x0|\(nil\)|\(null\)}} + // OHOS_LOCAL + // CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = {{0x0|\(nil\)|\(null\)|0}} __tsan_get_report_mop(report, 1, &tid, &addr, &size, &write, &atomic, trace, 16); @@ -87,7 +88,8 @@ __tsan_on_report(void *report) { tid, addr, size, write, atomic); // CHECK: tid = 0, addr = [[GLOBAL]], size = 8, write = 1, atomic = 0 fprintf(stderr, "trace[0] = %p, trace[1] = %p\n", trace[0], trace[1]); - // CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = {{0x0|\(nil\)|\(null\)}} + // OHOS_LOCAL + // CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = {{0x0|\(nil\)|\(null\)|0}} fprintf(stderr, "thread_count = %d\n", thread_count); // CHECK: thread_count = 2 diff --git a/compiler-rt/test/tsan/dtls.c b/compiler-rt/test/tsan/dtls.c index 57c9da83a374e0f62dbae705b3adb5fae490b9fb..9b4febb0c019ba906db2eb1c80b1f56edf182353 100644 --- a/compiler-rt/test/tsan/dtls.c +++ b/compiler-rt/test/tsan/dtls.c @@ -32,6 +32,9 @@ void *Thread2(void *arg) { } int main(int argc, char *argv[]) { + // OHOS_LOCAL + dlerror(); // Clear any previous errors + char path[4096]; snprintf(path, sizeof(path), "%s-so.so", argv[0]); diff --git a/compiler-rt/test/tsan/fiber_from_thread.cpp b/compiler-rt/test/tsan/fiber_from_thread.cpp index d27379e7acf4038a957b4998391f260289f5c56c..7f859a0c55e8a01e43563921a9474419de47c9a9 100644 --- a/compiler-rt/test/tsan/fiber_from_thread.cpp +++ b/compiler-rt/test/tsan/fiber_from_thread.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" diff --git a/compiler-rt/test/tsan/fiber_longjmp.cpp b/compiler-rt/test/tsan/fiber_longjmp.cpp index e56fd21befbbb1122c85627caaf9058a81542184..189726e4a042de14946067678c0d996c5c50b0e8 100644 --- a/compiler-rt/test/tsan/fiber_longjmp.cpp +++ b/compiler-rt/test/tsan/fiber_longjmp.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" #include diff --git a/compiler-rt/test/tsan/fiber_race.cpp b/compiler-rt/test/tsan/fiber_race.cpp index add66940ffd11fbaf8c41f9d521d27d9c5cf0e42..eef17cf42c5c7d90f8dabdbab0c3b4ce748edb68 100644 --- a/compiler-rt/test/tsan/fiber_race.cpp +++ b/compiler-rt/test/tsan/fiber_race.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" diff --git a/compiler-rt/test/tsan/fiber_simple.cpp b/compiler-rt/test/tsan/fiber_simple.cpp index 8123eb8eafc8a3b3d7c9327e50ab6f818be2a2ad..633f8bd408f50c25cfe328b5b439d7367cac92b8 100644 --- a/compiler-rt/test/tsan/fiber_simple.cpp +++ b/compiler-rt/test/tsan/fiber_simple.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" diff --git a/compiler-rt/test/tsan/fiber_two_threads.cpp b/compiler-rt/test/tsan/fiber_two_threads.cpp index d2961b94dde10179f4efd02a5e3f33f98f729c12..b4d6604c7ef15b94920fe3abfec2b06c37355080 100644 --- a/compiler-rt/test/tsan/fiber_two_threads.cpp +++ b/compiler-rt/test/tsan/fiber_two_threads.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" diff --git a/compiler-rt/test/tsan/ignore_lib1.cpp b/compiler-rt/test/tsan/ignore_lib1.cpp index 01139519e491b466917945723d9c5501551eefec..2b17dee501418bb40489f11d7654bcefd2540120 100644 --- a/compiler-rt/test/tsan/ignore_lib1.cpp +++ b/compiler-rt/test/tsan/ignore_lib1.cpp @@ -16,6 +16,10 @@ // FIXME: This test regularly fails on powerpc64 LE possibly starting with // r279664. Re-enable the test once the problem(s) have been fixed. +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + #ifndef LIB #include diff --git a/compiler-rt/test/tsan/ignore_lib2.cpp b/compiler-rt/test/tsan/ignore_lib2.cpp index 05b7c2ed915a766a7546d65b4da6d5f70a268b6a..24b7f5e66a3e8972769dc6ff894026ef944ad09d 100644 --- a/compiler-rt/test/tsan/ignore_lib2.cpp +++ b/compiler-rt/test/tsan/ignore_lib2.cpp @@ -6,6 +6,10 @@ // RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable // RUN: %env_tsan_opts=suppressions='%s.supp' %deflake %run %t-dir/executable | FileCheck %s +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + // Tests that called_from_lib suppression matched against 2 libraries // causes program crash (this is not supported). diff --git a/compiler-rt/test/tsan/ignore_lib3.cpp b/compiler-rt/test/tsan/ignore_lib3.cpp index b1a3940d03b615a24b143a140eb2ec76e47742e1..b13229184141e15d1aa2003a135c89b2938d32c5 100644 --- a/compiler-rt/test/tsan/ignore_lib3.cpp +++ b/compiler-rt/test/tsan/ignore_lib3.cpp @@ -11,6 +11,10 @@ // Some aarch64 kernels do not support non executable write pages // REQUIRES: stable-runtime +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + #ifndef LIB #include diff --git a/compiler-rt/test/tsan/ignore_lib4.cpp b/compiler-rt/test/tsan/ignore_lib4.cpp index 06241c7b89f3024dd26e83a1507ff5b7a9e117bf..00bde34639d0f9441de755a8ad07aa50ac68bfdf 100644 --- a/compiler-rt/test/tsan/ignore_lib4.cpp +++ b/compiler-rt/test/tsan/ignore_lib4.cpp @@ -13,6 +13,10 @@ // is matched against 2 libraries". // UNSUPPORTED: aarch64 +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + // Test longjmp in ignored lib. // It used to crash since we jumped out of ScopedInterceptor scope. diff --git a/compiler-rt/test/tsan/ignore_lib5.cpp b/compiler-rt/test/tsan/ignore_lib5.cpp index a71d560ab913c1e6855fb5bee3b6c46b6b7383db..9ae3f7bcbb9546368dff938a474472cdbdc35971 100644 --- a/compiler-rt/test/tsan/ignore_lib5.cpp +++ b/compiler-rt/test/tsan/ignore_lib5.cpp @@ -21,6 +21,10 @@ // ReadProcMaps() on NetBSD does not handle >=1MB of memory layout information // UNSUPPORTED: netbsd +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + #ifndef LIB #include diff --git a/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp b/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp index 2b35627229df7495b4eaac9da27c0eca91ce71b5..bbf43be5b6050bb1b4a596141a49f7977b2c77c9 100644 --- a/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp +++ b/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp @@ -49,7 +49,10 @@ int main(int argc, const char *argv[]) { return 0; } -// CHECK-RACE: WARNING: ThreadSanitizer: data race -// CHECK-RACE: OK +// OHOS_LOCAL begin +// CHECK-RACE-DAG: WARNING: ThreadSanitizer: data race +// CHECK-RACE-DAG: OK // CHECK-IGNORE-NOT: WARNING: ThreadSanitizer: data race // CHECK-IGNORE: OK +// CHECK-IGNORE-NOT: WARNING: ThreadSanitizer: data race +// OHOS_LOCAL end diff --git a/compiler-rt/test/tsan/java_finalizer2.cpp b/compiler-rt/test/tsan/java_finalizer2.cpp index 87528900541a84be2e3603b510cd8d08eaebe1eb..77e222766bd80ce4f5c73ee127f2902bb33c3619 100644 --- a/compiler-rt/test/tsan/java_finalizer2.cpp +++ b/compiler-rt/test/tsan/java_finalizer2.cpp @@ -37,9 +37,9 @@ void *Thread3(void *p) { Heap* heap = (Heap*)p; pthread_barrier_wait(&heap->barrier_finalizer); while (__atomic_load_n(&heap->ready, __ATOMIC_ACQUIRE) != 1) - pthread_yield(); + sched_yield(); // OHOS_LOCAL while (__atomic_load_n(&heap->finalized, __ATOMIC_RELAXED) != 1) - pthread_yield(); + sched_yield(); // OHOS_LOCAL __atomic_fetch_add(&heap->wg, 1, __ATOMIC_RELEASE); return 0; } @@ -70,7 +70,7 @@ int main() { pthread_join(ballast[i], 0); pthread_barrier_wait(&heap->barrier_finalizer); while (__atomic_load_n(&heap->wg, __ATOMIC_ACQUIRE) != 2) - pthread_yield(); + sched_yield(); // OHOS_LOCAL if (heap->data != 1) exit(printf("no data\n")); for (int i = 0; i < 3; i++) diff --git a/compiler-rt/test/tsan/lit.cfg.py b/compiler-rt/test/tsan/lit.cfg.py index 4295514f0a5e32386f38b6f0de0a4341594a41ac..ddd4d21642fa558a66763c25c00e152c699d1e1e 100644 --- a/compiler-rt/test/tsan/lit.cfg.py +++ b/compiler-rt/test/tsan/lit.cfg.py @@ -18,24 +18,25 @@ config.name = 'ThreadSanitizer' + config.name_suffix config.test_source_root = os.path.dirname(__file__) # Setup environment variables for running ThreadSanitizer. -default_tsan_opts = "atexit_sleep_ms=0" +# OHOS_LOCAL begin +default_tsan_opts = list(config.default_sanitizer_opts) +default_tsan_opts += ["atexit_sleep_ms=0"] if config.host_os == 'Darwin': - # On Darwin, we default to `abort_on_error=1`, which would make tests run - # much slower. Let's override this and run lit tests with 'abort_on_error=0'. - default_tsan_opts += ':abort_on_error=0' # On Darwin, we default to ignore_noninstrumented_modules=1, which also # suppresses some races the tests are supposed to find. Let's run without this # setting, but turn it back on for Darwin tests (see Darwin/lit.local.cfg.py). - default_tsan_opts += ':ignore_noninstrumented_modules=0' - default_tsan_opts += ':ignore_interceptors_accesses=0' + default_tsan_opts += ['ignore_noninstrumented_modules=0'] + default_tsan_opts += ['ignore_interceptors_accesses=0'] # Platform-specific default TSAN_OPTIONS for lit tests. -if default_tsan_opts: - config.environment['TSAN_OPTIONS'] = default_tsan_opts - default_tsan_opts += ':' +default_tsan_opts_str = ':'.join(default_tsan_opts) +if default_tsan_opts_str: + config.environment['TSAN_OPTIONS'] = default_tsan_opts_str + default_tsan_opts_str += ':' config.substitutions.append(('%env_tsan_opts=', - 'env TSAN_OPTIONS=' + default_tsan_opts)) + 'env TSAN_OPTIONS=' + default_tsan_opts_str)) +# OHOS_LOCAL end # GCC driver doesn't add necessary compile/link flags with -fsanitize=thread. if config.compiler_id == 'GNU': @@ -81,7 +82,7 @@ config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__ # Default test suffixes. config.suffixes = ['.c', '.cpp', '.m', '.mm'] -if config.host_os not in ['FreeBSD', 'Linux', 'Darwin', 'NetBSD']: +if config.host_os not in ['FreeBSD', 'Linux', 'Darwin', 'NetBSD', 'OHOS']: # OHOS_LOCAL config.unsupported = True if config.android: diff --git a/compiler-rt/test/tsan/mutex_lock_destroyed.cpp b/compiler-rt/test/tsan/mutex_lock_destroyed.cpp index 892d444005411b3658c4a3b3c474da54dbc9f87a..1a4135008410973e5d25e2458ab478c8341f40eb 100644 --- a/compiler-rt/test/tsan/mutex_lock_destroyed.cpp +++ b/compiler-rt/test/tsan/mutex_lock_destroyed.cpp @@ -5,6 +5,10 @@ // The pthread_mutex_lock interceptor assumes incompatible internals w/ NetBSD // XFAIL: netbsd +// OHOS_LOCAL +// musl seems to not return error when calling pthread_mutex_lock with a destroyed mutex +// UNSUPPORTED: ohos_family + #include #include #include diff --git a/compiler-rt/test/tsan/on_exit.cpp b/compiler-rt/test/tsan/on_exit.cpp index 2dadd68c144a41b7716203c421b6b64ad2e8c9f6..567fd0a8a73b8f53a808a431ece6d9694db7c2c4 100644 --- a/compiler-rt/test/tsan/on_exit.cpp +++ b/compiler-rt/test/tsan/on_exit.cpp @@ -3,6 +3,10 @@ // on_exit() is not available on Darwin. // UNSUPPORTED: darwin +// OHOS_LOCAL +// on_exit() is not available on musl. +// UNSUPPORTED: ohos_family + #include "test.h" volatile long global; diff --git a/compiler-rt/test/tsan/signal_sync2.cpp b/compiler-rt/test/tsan/signal_sync2.cpp index a1c31dcdc1ee74dddb0ea57c075d5ec0aa1e8901..7f61dae6a9a6c56e10e8b327a569f7b7b27861a8 100644 --- a/compiler-rt/test/tsan/signal_sync2.cpp +++ b/compiler-rt/test/tsan/signal_sync2.cpp @@ -13,13 +13,21 @@ const int kSignalCount = 500; -__thread int process_signals; +// OHOS_LOCAL begin +pthread_t main_tid; +int process_signals; +// OHOS_LOCAL end int signals_handled; int done; int ready[kSignalCount]; long long data[kSignalCount]; static void handler(int sig) { + // OHOS_LOCAL begin + // avoid using possibly emulated TLS in signal handlers + if (pthread_self() == main_tid) + return; + // OHOS_LOCAL end if (!__atomic_load_n(&process_signals, __ATOMIC_RELAXED)) return; int pos = signals_handled++; @@ -39,6 +47,8 @@ static void* thr(void *p) { } int main() { + main_tid = pthread_self(); // OHOS_LOCAL + struct sigaction act = {}; act.sa_handler = handler; if (sigaction(SIGPROF, &act, 0)) { diff --git a/compiler-rt/test/tsan/strerror_r.cpp b/compiler-rt/test/tsan/strerror_r.cpp index 438f54914d6c1cbf92bffcea86e8991c1c713684..3b0497ed97f3068d62d49412474aecebe40306d3 100644 --- a/compiler-rt/test/tsan/strerror_r.cpp +++ b/compiler-rt/test/tsan/strerror_r.cpp @@ -1,7 +1,8 @@ // RUN: %clangxx_tsan -O1 -DTEST_ERROR=ERANGE %s -o %t && %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-SYS %s // RUN: %clangxx_tsan -O1 -DTEST_ERROR=-1 %s -o %t && not %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-USER %s // This test is for GNU specific version of strerror_r() -// UNSUPPORTED: darwin, netbsd, freebsd +// OHOS_LOCAL +// UNSUPPORTED: darwin, netbsd, freebsd, ohos_family #include "test.h" diff --git a/compiler-rt/test/tsan/thread_name.cpp b/compiler-rt/test/tsan/thread_name.cpp index bc65421b36d0159c1ec65d5872e7c9338761c0e1..f6396ed29c79a6d901c8f6cd04aef82881714ebf 100644 --- a/compiler-rt/test/tsan/thread_name.cpp +++ b/compiler-rt/test/tsan/thread_name.cpp @@ -1,7 +1,8 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" -#if defined(__linux__) +// OHOS_LOCAL +#if defined(__linux__) && !defined(__OHOS__) #define USE_PTHREAD_SETNAME_NP __GLIBC_PREREQ(2, 12) #define tsan_pthread_setname_np pthread_setname_np #elif defined(__FreeBSD__) @@ -11,6 +12,11 @@ #elif defined(__NetBSD__) #define USE_PTHREAD_SETNAME_NP 1 #define tsan_pthread_setname_np(a, b) pthread_setname_np((a), "%s", (void *)(b)) +// OHOS_LOCAL begin +#elif defined(__OHOS__) +#define USE_PTHREAD_SETNAME_NP 1 +#define tsan_pthread_setname_np pthread_setname_np +// OHOS_LOCAL end #else #define USE_PTHREAD_SETNAME_NP 0 #endif diff --git a/compiler-rt/test/tsan/tls_race.cpp b/compiler-rt/test/tsan/tls_race.cpp index 5f5b6aae4f586f6c645dff7c28396abea3a059f0..0821680d0aaefa566189e1f19f109fee436588ed 100644 --- a/compiler-rt/test/tsan/tls_race.cpp +++ b/compiler-rt/test/tsan/tls_race.cpp @@ -24,3 +24,5 @@ int main() { // CHECK-FreeBSD: Location is TLS of main thread. // CHECK-NetBSD: Location is TLS of main thread. // CHECK-Darwin: Location is heap block of size 4 +// OHOS_LOCAL +// CHECK-OHOS: Location is heap block of size diff --git a/compiler-rt/test/tsan/tls_race2.cpp b/compiler-rt/test/tsan/tls_race2.cpp index 0e008313518a27cd3f88917c0f67303bce0af0a2..b05547e6643fbc5f4513cc93ec6eae28a9d474e8 100644 --- a/compiler-rt/test/tsan/tls_race2.cpp +++ b/compiler-rt/test/tsan/tls_race2.cpp @@ -33,4 +33,6 @@ int main() { // CHECK-FreeBSD: Location is TLS of thread T1. // CHECK-NetBSD: Location is TLS of thread T1. // CHECK-Darwin: Location is heap block of size 4 +// OHOS_LOCAL +// CHECK-OHOS: Location is heap block of size // CHECK: DONE diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake index 55d1aa17b46b597240e2acc0a09ac3832a22ccb6..209f8a1cd348423b60170fc0160451823a31438c 100644 --- a/lldb/cmake/modules/LLDBConfig.cmake +++ b/lldb/cmake/modules/LLDBConfig.cmake @@ -58,7 +58,13 @@ endmacro() add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" LibEdit LibEdit_FOUND) add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" CursesAndPanel CURSESANDPANEL_FOUND) +if (NOT LLDB_ENABLE_LZMA_7ZIP) # OHOS_LOCAL add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND) +# OHOS_LOCAL begin +else() +message(STATUS "Enable LZMA-7zip compression support in LLDB: TRUE") +endif() +# OHOS_LOCAL end add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" LuaAndSwig LUAANDSWIG_FOUND) add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonAndSwig PYTHONANDSWIG_FOUND) add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION 2.8) diff --git a/lldb/include/lldb/Host/Config.h.cmake b/lldb/include/lldb/Host/Config.h.cmake index 9ee0b9dcd04f47a1baec76d695fe17e215c828aa..ad69d0bfe74307bf788f11bd019227d99ae915fc 100644 --- a/lldb/include/lldb/Host/Config.h.cmake +++ b/lldb/include/lldb/Host/Config.h.cmake @@ -32,6 +32,8 @@ #cmakedefine01 LLDB_ENABLE_TERMIOS #cmakedefine01 LLDB_ENABLE_LZMA +// OHOS_LOCAL +#cmakedefine01 LLDB_ENABLE_LZMA_7ZIP #cmakedefine01 LLDB_ENABLE_CURSES diff --git a/lldb/source/Host/common/LZMA.cpp b/lldb/source/Host/common/LZMA.cpp index 5b457f07afca17b91a6da44782809c3d5d202f3a..34ce61c239a52fc6a0f51a19b2714721bcd80bce 100644 --- a/lldb/source/Host/common/LZMA.cpp +++ b/lldb/source/Host/common/LZMA.cpp @@ -11,7 +11,16 @@ #include "llvm/Support/Error.h" #if LLDB_ENABLE_LZMA +// OHOS_LOCAL begin +#if !LLDB_ENABLE_LZMA_7ZIP #include +#else +#include <7zCrc.h> +#include +#include +#define EXPAND_FACTOR 2 +#endif +// OHOS_LOCAL end #endif // LLDB_ENABLE_LZMA namespace lldb_private { @@ -34,6 +43,8 @@ llvm::Error uncompress(llvm::ArrayRef InputBuffer, bool isAvailable() { return true; } +// OHOS_LOCAL +#if !LLDB_ENABLE_LZMA_7ZIP static const char *convertLZMACodeToString(lzma_ret Code) { switch (Code) { case LZMA_STREAM_END: @@ -139,7 +150,93 @@ llvm::Error uncompress(llvm::ArrayRef InputBuffer, return llvm::Error::success(); } +// OHOS_LOCAL begin +#else +static const char *convertLZMACodeToString(SRes Code) { + switch (Code) { + case SZ_ERROR_DATA: + return "lzma error: SZ_ERROR_DATA"; + case SZ_ERROR_MEM: + return "lzma error: SZ_ERROR_MEM"; + case SZ_ERROR_CRC: + return "lzma error: SZ_ERROR_CRC"; + case SZ_ERROR_UNSUPPORTED: + return "lzma error: SZ_ERROR_UNSUPPORTED"; + case SZ_ERROR_PARAM: + return "lzma error: SZ_ERROR_PARAM"; + case SZ_ERROR_INPUT_EOF: + return "lzma error: SZ_ERROR_INPUT_EOF"; + case SZ_ERROR_OUTPUT_EOF: + return "lzma error: SZ_ERROR_OUTPUT_EOF"; + case SZ_ERROR_READ: + return "lzma error: SZ_ERROR_READ"; + case SZ_ERROR_WRITE: + return "lzma error: SZ_ERROR_WRITE"; + case SZ_ERROR_PROGRESS: + return "lzma error: SZ_ERROR_PROGRESS"; + case SZ_ERROR_FAIL: + return "lzma error: SZ_ERROR_FAIL"; + case SZ_ERROR_THREAD: + return "lzma error: SZ_ERROR_THREAD"; + case SZ_ERROR_ARCHIVE: + return "lzma error: SZ_ERROR_ARCHIVE"; + case SZ_ERROR_NO_ARCHIVE: + return "lzma error: SZ_ERROR_NO_ARCHIVE"; + default: + llvm_unreachable("unknown or unexpected lzma status code"); + } +} + +static void *XzAlloc(ISzAllocPtr, size_t size) { + return malloc(size); +} +static void XzFree(ISzAllocPtr, void *address) { + free(address); +} + +llvm::Error uncompress(llvm::ArrayRef InputBuffer, + llvm::SmallVectorImpl &Uncompressed) { + const uint8_t *src = InputBuffer.data(); + ISzAlloc alloc; + CXzUnpacker state; + alloc.Alloc = XzAlloc; + alloc.Free = XzFree; + XzUnpacker_Construct(&state, &alloc); + CrcGenerateTable(); + Crc64GenerateTable(); + size_t srcOff = 0; + size_t dstOff = 0; + size_t srcLen = InputBuffer.size(); + std::vector dst(srcLen, 0); + ECoderStatus status = CODER_STATUS_NOT_FINISHED; + while (status == CODER_STATUS_NOT_FINISHED) { + dst.resize(dst.size() * EXPAND_FACTOR); + size_t srcRemain = srcLen - srcOff; + size_t dstRemain = dst.size() - dstOff; + SRes res = XzUnpacker_Code(&state, + reinterpret_cast(&dst[dstOff]), &dstRemain, + reinterpret_cast(&src[srcOff]), &srcRemain, + true, CODER_FINISH_ANY, &status); + if (res != SZ_OK) { + XzUnpacker_Free(&state); + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "XzUnpacker_Code()=%s", convertLZMACodeToString(res)); + } + srcOff += srcRemain; + dstOff += dstRemain; + } + XzUnpacker_Free(&state); + if (!XzUnpacker_IsStreamWasFinished(&state)) { + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "XzUnpacker_IsStreamWasFinished()=lzma error: return False"); + } + Uncompressed.resize(dstOff); + memcpy(Uncompressed.data(), dst.data(), dstOff); + return llvm::Error::success(); +} +#endif +// OHOS_LOCAL end #endif // LLDB_ENABLE_LZMA } // end of namespace lzma diff --git a/lldb/source/Target/ThreadPlan.cpp b/lldb/source/Target/ThreadPlan.cpp index 5a7ff8ba1e50c0173cfffde3383b023e20604940..f9bd51ddbe183ed867913d73f30217976b0fa416 100644 --- a/lldb/source/Target/ThreadPlan.cpp +++ b/lldb/source/Target/ThreadPlan.cpp @@ -174,6 +174,9 @@ bool ThreadPlan::IsUsuallyUnexplainedStopReason(lldb::StopReason reason) { case eStopReasonExec: case eStopReasonThreadExiting: case eStopReasonInstrumentation: + case eStopReasonFork: + case eStopReasonVFork: + case eStopReasonVForkDone: return true; default: return false; diff --git a/lldb/test/API/functionalities/fork/resumes-child/Makefile b/lldb/test/API/functionalities/fork/resumes-child/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..99998b20bcb0502181cbf488a2034823e5f66d22 --- /dev/null +++ b/lldb/test/API/functionalities/fork/resumes-child/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/functionalities/fork/resumes-child/TestForkResumesChild.py b/lldb/test/API/functionalities/fork/resumes-child/TestForkResumesChild.py new file mode 100644 index 0000000000000000000000000000000000000000..70df4f1c51a7c526810c22bd92897bf508d65975 --- /dev/null +++ b/lldb/test/API/functionalities/fork/resumes-child/TestForkResumesChild.py @@ -0,0 +1,22 @@ +""" +Make sure that the fork child keeps running. +""" + + + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * + + +class TestForkResumesChild(TestBase): + + NO_DEBUG_INFO_TESTCASE = True + + @skipIfWindows + def test_step_over_fork(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp")) + self.runCmd("next") + self.expect("continue", substrs = ["exited with status = 0"]) diff --git a/lldb/test/API/functionalities/fork/resumes-child/main.cpp b/lldb/test/API/functionalities/fork/resumes-child/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2d37f323bdf6a3dc4ff2c6e29fd298999441916a --- /dev/null +++ b/lldb/test/API/functionalities/fork/resumes-child/main.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include +#include + +int main() { + pid_t fork_result = fork(); // break here + assert(fork_result >= 0); + if (fork_result == 0) { + // child + _exit(47); + } + // parent + // Use polling to avoid blocking if the child is not actually resumed. + auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(10); + std::chrono::milliseconds poll_interval{10}; + while (std::chrono::steady_clock::now() < deadline) { + int status; + pid_t waitpid_result = waitpid(fork_result, &status, WNOHANG); + if (waitpid_result == fork_result) + return 0; + assert(waitpid_result == 0); + std::this_thread::sleep_for(poll_interval); + poll_interval *= 2; + } + abort(); +} diff --git a/llvm-build/MakeLiblzma b/llvm-build/MakeLiblzma new file mode 100644 index 0000000000000000000000000000000000000000..b78b86f3496b6b89671c28e07302c31bf3e3d67e --- /dev/null +++ b/llvm-build/MakeLiblzma @@ -0,0 +1,65 @@ +# Copyright (C) 2023 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. + +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 +SRC_PREFIX := + +ifeq ($(TARGET_TRIPLE),linux-x86_64) +CFLAGS := --target=x86_64-unknown-linux-gnu -D_7ZIP_ST -Wall -Werror -Wno-empty-body -Wno-enum-conversion -Wno-logical-op-parentheses -Wno-self-assign -fPIC +LDFLAGS := -shared -fuse-ld=lld +TARGET := liblzma.so +else +ifeq ($(TARGET_TRIPLE),windows-x86_64) +CFLAGS := --target=x86_64-pc-windows-gnu --sysroot=$(SYSROOT) -D_7ZIP_ST -Wall -Werror -Wno-empty-body -Wno-enum-conversion -Wno-logical-op-parentheses -Wno-self-assign -fPIC +LDFLAGS := -shared -fuse-ld=lld --rtlib=compiler-rt -Wl,--out-implib=liblzma.dll.a +TARGET := liblzma.dll +TARGET_A := liblzma.dll.a +else +ifeq ($(findstring darwin,$(TARGET_TRIPLE)),darwin) +SDKROOT := $(shell xcrun --sdk macosx --show-sdk-path) +CFLAGS := -D_7ZIP_ST -Wall -Werror -Wno-empty-body -Wno-enum-conversion -Wno-logical-op-parentheses -Wno-self-assign -fPIC +LDFLAGS := -dynamiclib -fuse-ld=lld -Wl,-syslibroot,$(SDKROOT) -install_name @rpath/liblzma.dylib +TARGET := liblzma.dylib +else +$(warning *** warning: TARGET_TRIPLE $(TARGET_TRIPLE) has not been set in rights) +endif +endif +endif + +lzma_header_install: + @echo "begin header install" + mkdir -p $(INSTALL_DIR)/include + cp -rf $(SRC_PREFIX)* $(INSTALL_DIR)/include + +$(TARGET): lzma_header_install + $(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(addprefix $(SRC_PREFIX), $(SRCS)) + +.PHONY: clean + +clean: + rm -f $(TARGET) $(SRC_PREFIX)*.o + +.PHONY:install + +install: $(TARGET) + @echo "begin install" + mkdir -p $(INSTALL_DIR)/lib/$(TARGET_TRIPLE) + mv $(TARGET) $(INSTALL_DIR)/lib/$(TARGET_TRIPLE) +ifeq ($(TARGET_TRIPLE),windows-x86_64) + mv $(TARGET_A) $(INSTALL_DIR)/lib/$(TARGET_TRIPLE) +endif + @echo "install success!" diff --git a/llvm-build/README.md b/llvm-build/README.md index 7f776991e70a008d3f0f483682570b995f03e192..be4acceb02ca84a6bea1ed8f202ece9f89eac941 100644 --- a/llvm-build/README.md +++ b/llvm-build/README.md @@ -16,6 +16,19 @@ MacOS X >= 10.15.4
+### Environmental preparation + +ubuntu +``` +sudo apt-get install build-essential swig python3-dev libedit-dev libncurses5-dev binutils-dev gcc-multilib +``` +mac +``` +brew install swig git-lfs java coreutils wget +``` + +
+ ### Get Code ``` repo init -u https://gitee.com/OpenHarmony/manifest.git -b master -m llvm-toolchain.xml @@ -121,7 +134,7 @@ OHOS fetch prebuilts from: https://mirrors.huaweicloud.com/openharmony/compiler/ License: Apache License v2.0 with LLVM Exceptions ``` -### Build process of AArch64 LLVM components for Ark Runtime +### Build process of AArch64 toolchain First build toolchain on Linux. Here is an example of starting build process on Linux: @@ -141,7 +154,7 @@ build-ohos-aarch64.py options: ```
-When build successfully completed, artifacts will be available in `out/ohos-aarch64-install` directory, including LLVM tools and libLLVM.so for aarch64. +When build successfully completed, artifacts will be available in `out/ohos-aarch64-install` directory, including clang, lld, runtimes, LLVM tools and libLLVM.so for aarch64. ## Function Introduction diff --git a/llvm-build/build-ohos-aarch64.py b/llvm-build/build-ohos-aarch64.py old mode 100644 new mode 100755 index f197e3ea75cb705970603971f4fb6f225cc91a04..9dc42111624a68acbaa3f32ac31efc5ff2028094 --- a/llvm-build/build-ohos-aarch64.py +++ b/llvm-build/build-ohos-aarch64.py @@ -1,3 +1,18 @@ +#!/usr/bin/env python3 +# Copyright (C) 2023 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 build import BuildConfig, BuildUtils @@ -53,7 +68,7 @@ def main(): llvm_defines['CMAKE_INSTALL_PREFIX'] = llvm_install llvm_defines['CMAKE_SYSROOT'] = sysroot llvm_defines['CMAKE_LIBRARY_ARCHITECTURE'] = llvm_triple - llvm_defines['LLVM_TARGETS_TO_BUILD'] = 'AArch64' + 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' @@ -63,8 +78,10 @@ def main(): 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_DISTRIBUTION_COMPONENTS'] = 'cmake-exports;llvm-headers;LLVM' + llvm_defines['LLVM_ENABLE_PROJECTS'] = 'clang;clang-tools-extra;lld;lldb;openmp' + # 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 @@ -98,6 +115,8 @@ def main(): 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') if build_config.enable_assertions: llvm_defines['LLVM_ENABLE_ASSERTIONS'] = 'ON' @@ -111,6 +130,29 @@ def main(): 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) + if __name__ == '__main__': main() diff --git a/llvm-build/build.py b/llvm-build/build.py index e8a06e08b5b71440411062009a03cc1ef7cea773..a3122ade6bec5019fe6aa4d87f7ddac45f68e44a 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -55,6 +55,7 @@ class BuildConfig(): self.need_libs = self.do_build and 'libs' not in args.no_build self.need_lldb_server = self.do_build and 'lldb-server' not in args.no_build and not args.build_only self.build_python = args.build_python + self.build_with_debug_info = args.build_with_debug_info self.build_only = True if args.build_only else False self.build_only_llvm = args.build_only["llvm"] if self.build_only else [] @@ -72,9 +73,11 @@ class BuildConfig(): self.build_libxml2 = args.build_libxml2 self.lldb_timeout = args.lldb_timeout self.enable_monitoring = args.enable_monitoring + self.enable_lzma_7zip = args.enable_lzma_7zip self.build_libs = args.build_libs self.build_libs_flags = args.build_libs_flags self.adlt_debug_build = args.adlt_debug_build + self.compression_format = args.compression_format self.discover_paths() @@ -90,6 +93,9 @@ class BuildConfig(): self.CLANG_VERSION = prebuilts_clang_version self.MINGW_TRIPLE = 'x86_64-windows-gnu' self.build_libs_with_hb = self.build_libs_flags == 'OH' or self.build_libs_flags == 'BOTH' + + self.ARCHIVE_EXTENSION = '.tar.' + self.compression_format + self.ARCHIVE_OPTION = '-c' + ('j' if self.compression_format == "bz2" else 'z') logging.basicConfig(level=logging.INFO) def discover_paths(self): @@ -234,6 +240,12 @@ class BuildConfig(): default=False, help='Build libxml2 tool') + parser.add_argument( + '--enable-lzma-7zip', + action='store_true', + default=False, + help='Build 7zip tool and enable LZMA compression support in LLDB') + parser.add_argument( '--lldb-timeout', action='store_true', @@ -245,6 +257,21 @@ class BuildConfig(): action='store_true', default=False, help='Enable lldb performance monitoring') + + compression_formats = ['bz2', 'gz'] + + parser.add_argument( + '--compression-format', + choices=compression_formats, + default='bz2', + help='Choose compression output format (bz2 or gz)' + ) + + parser.add_argument( + '--build-with-debug-info', + action='store_true', + default=False, + help='Append -g to build flags in build_libs') parser.add_argument( '--adlt-debug-build', @@ -677,6 +704,9 @@ class LlvmCore(BuildUtils): llvm_defines['CURSES_LIBRARIES'] = ncurses_libs llvm_defines['PANEL_LIBRARIES'] = ncurses_libs + if self.build_config.enable_lzma_7zip: + llvm_defines['LIBLZMA_LIBRARIES'] = self.merge_out_path('lzma', 'lib', self.use_platform(), 'liblzma.dylib') + if self.build_config.build_libedit: llvm_defines['LibEdit_LIBRARIES'] = os.path.join(self.get_prebuilts_dir('libedit'), 'lib', 'libedit.0.dylib') @@ -718,6 +748,9 @@ class LlvmCore(BuildUtils): llvm_defines['CURSES_LIBRARIES'] = ncurses_libs llvm_defines['PANEL_LIBRARIES'] = ncurses_libs + if self.build_config.enable_lzma_7zip: + 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') @@ -763,6 +796,12 @@ 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') + + if self.build_config.enable_lzma_7zip: + llvm_defines['LLDB_ENABLE_LZMA'] = 'ON' + llvm_defines['LLDB_ENABLE_LZMA_7ZIP'] = 'ON' + llvm_defines['LIBLZMA_INCLUDE_DIRS'] = self.merge_out_path('lzma', 'include') + 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') @@ -819,8 +858,9 @@ class LlvmCore(BuildUtils): llvm_defines['LLVM_BUILD_INSTRUMENTED'] = 'ON' llvm_defines['LLVM_PROFDATA'] = llvm_profdata - 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) + resource_dir = os.path.join(llvm_clang_install, 'lib', 'clang', self.build_config.CLANG_VERSION, + 'lib', 'x86_64-unknown-linux-gnu', 'libclang_rt.profile.a') + ldflags += ' %s' % resource_dir cflags = '-fstack-protector-strong' if not self.host_is_darwin(): @@ -830,8 +870,7 @@ class LlvmCore(BuildUtils): self.llvm_compile_llvm_defines(llvm_defines, llvm_clang_install, cflags, ldflags) - linker_path = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'prebuilts', 'clang', - 'ohos', 'linux-x86_64', 'llvm', 'bin', 'ld.lld')) + linker_path = os.path.join(llvm_clang_install, 'bin', 'ld.lld') llvm_defines['CMAKE_LINKER'] = linker_path self.build_llvm(targets=self.build_config.TARGETS, @@ -897,6 +936,12 @@ class LlvmCore(BuildUtils): if self.build_config.enable_monitoring: windows_defines['LLDB_ENABLE_PERFORMANCE'] = 'ON' + if self.build_config.enable_lzma_7zip: + windows_defines['LLDB_ENABLE_LZMA'] = 'ON' + windows_defines['LLDB_ENABLE_LZMA_7ZIP'] = 'ON' + windows_defines['LIBLZMA_INCLUDE_DIRS'] = self.merge_out_path('lzma', 'include') + windows_defines['LIBLZMA_LIBRARIES'] = self.merge_out_path('lzma', 'lib', 'windows-x86_64', 'liblzma.dll.a') + def llvm_compile_windows_flags(self, windows_defines, windowstool_path, @@ -1137,7 +1182,6 @@ class SysrootComposer(BuildUtils): gn_args += ' is_legacy=true musl_target_multilib=nanlegacy' multi_lib_dir = os.path.join(ohos_lib_dir, 'nanlegacy') sysroot_multi_lib_dir = os.path.join(sysroot_lib_dir, 'nanlegacy') - self.run_hb_build(product_name, target_cpu, target_name, gn_args) ld_musl_lib = os.path.join(sysroot_multi_lib_dir, 'ld-musl-{}.so.1'.format(ld_arch)) self.build_musl_libs(product_name, target_cpu, target_name, multi_lib_dir, sysroot_multi_lib_dir, ld_musl_lib, gn_args) @@ -1244,6 +1288,8 @@ class LlvmLibs(BuildUtils): '-ffunction-sections', '-fdata-sections', extra_flags, ] + if self.build_config.build_with_debug_info: + cflag.append('-g') cflags.extend(cflag) @@ -1764,6 +1810,41 @@ class LlvmLibs(BuildUtils): self.llvm_package.copy_ncurses_to_llvm(llvm_make) self.llvm_package.copy_ncurses_to_llvm(llvm_install) + def build_lzma(self, llvm_make, llvm_install): + self.logger().info('Building lzma') + target_triple = self.use_platform() + liblzma_build_path = self.merge_out_path('lzma') + llvm_clang_prebuilts = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, + 'prebuilts', 'clang', 'ohos', self.use_platform(), + 'clang-%s' % self.build_config.CLANG_VERSION, 'bin', 'clang')) + src_dir = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'third_party', 'lzma', 'C')) + cmd = [ 'make', + 'install', + 'CC=%s' % llvm_clang_prebuilts, + 'SRC_PREFIX=%s/' % src_dir, + 'TARGET_TRIPLE=%s' % target_triple, + 'INSTALL_DIR=%s' % liblzma_build_path, + '-f', + 'MakeLiblzma'] + os.chdir(self.build_config.LLVM_BUILD_DIR) + self.check_call(cmd) + + if self.host_is_darwin(): + shlib_ext = '.dylib' + if self.host_is_linux(): + shlib_ext = '.so' + lzma_file = os.path.join(liblzma_build_path, 'lib', target_triple, 'liblzma' + shlib_ext) + + self.logger().info('Copy lzma to llvm make dir is %s', llvm_make) + lib_make_path = os.path.join(llvm_make, 'lib') + self.check_create_dir(lib_make_path) + self.check_copy_file(lzma_file, lib_make_path + '/liblzma' + shlib_ext) + + self.logger().info('Copy lzma to llvm install dir is %s', llvm_install) + lib_dst_path = os.path.join(llvm_install, 'lib') + 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): self.logger().info('Building libedit') @@ -1964,9 +2045,9 @@ class LlvmPackage(BuildUtils): #Package libcxx-ndk for host in hosts_list: tarball_name = 'libcxx-ndk-%s-%s' % (self.build_config.build_name, host) - package_path = '%s%s' % (self.merge_packages_path(tarball_name), '.tar.bz2') + package_path = '%s%s' % (self.merge_packages_path(tarball_name), self.build_config.ARCHIVE_EXTENSION) self.logger().info('Packaging %s', package_path) - args = ['tar', '-chjC', self.build_config.OUT_PATH, '-f', package_path, 'libcxx-ndk'] + args = ['tar', self.build_config.ARCHIVE_OPTION, '-h', '-C', self.build_config.OUT_PATH, '-f', package_path, 'libcxx-ndk'] self.check_create_dir(self.build_config.PACKAGES_PATH) self.check_call(args) @@ -2144,6 +2225,7 @@ class LlvmPackage(BuildUtils): 'llvm-strings%s' % ext, 'llvm-strip%s' % ext, 'llvm-symbolizer%s' % ext, + 'llvm-dwarfdump%s' % ext, ] necessary_bin_files.extend(necessary_bin_file) @@ -2190,6 +2272,12 @@ class LlvmPackage(BuildUtils): if self.build_config.build_libxml2: windows_additional_bin_files += ['libxml2%s' % shlib_ext] + if self.build_config.enable_lzma_7zip: + windows_additional_bin_files += ['liblzma%s' % shlib_ext] + bin_root = os.path.join(install_dir, 'bin') + prebuild_dir = self.merge_out_path('lzma', 'lib', 'windows-x86_64', 'liblzma.dll') + shutil.copyfile(prebuild_dir, os.path.join(bin_root, 'liblzma.dll')) + new_necessary_bin_files = list(set(necessary_bin_files) - set(windows_forbidden_list_bin_files)) new_necessary_bin_files.extend(windows_additional_bin_files) del necessary_bin_files[:] @@ -2206,9 +2294,9 @@ class LlvmPackage(BuildUtils): def package_up_resulting(self, package_name, host, install_host_dir): # Package up the resulting trimmed install/ directory. tarball_name = '%s-%s' % (package_name, host) - package_path = '%s%s' % (self.merge_packages_path(tarball_name), '.tar.bz2') + package_path = '%s%s' % (self.merge_packages_path(tarball_name), self.build_config.ARCHIVE_EXTENSION) self.logger().info('Packaging %s', package_path) - args = ['tar', '-cjC', install_host_dir, '-f', package_path, package_name] + args = ['tar', self.build_config.ARCHIVE_OPTION, '-C', install_host_dir, '-f', package_path, package_name] if host.startswith('windows'): # windows do not support symlinks, # replace them with file copies @@ -2220,9 +2308,9 @@ class LlvmPackage(BuildUtils): # Package ohos NDK if os.path.exists(self.merge_out_path('sysroot')): tarball_ndk_name = 'ohos-sysroot-%s' % self.build_config.build_name - package_ndk_path = '%s%s' % (self.merge_packages_path(tarball_ndk_name), '.tar.bz2') + package_ndk_path = '%s%s' % (self.merge_packages_path(tarball_ndk_name), self.build_config.ARCHIVE_EXTENSION) self.logger().info('Packaging %s', package_ndk_path) - args = ['tar', '-chjC', self.build_config.OUT_PATH, '-f', package_ndk_path, 'sysroot'] + args = ['tar', self.build_config.ARCHIVE_OPTION, '-h', '-C', self.build_config.OUT_PATH, '-f', package_ndk_path, 'sysroot'] self.check_call(args) def get_dependency_list(self, install_dir, lib): @@ -2394,7 +2482,7 @@ class LlvmPackage(BuildUtils): repo_tool = os.path.join(self.build_config.REPOROOT_DIR, '.repo', 'repo', 'repo') if os.path.isfile(repo_tool): self.logger().info('Generating manifest.') - subprocess.run(['python2.7', repo_tool, 'manifest', '-r', '-o', manifest], shell=False, + subprocess.run(['python3', repo_tool, 'manifest', '-r', '-o', manifest], shell=False, stdout=subprocess.PIPE, cwd=self.build_config.REPOROOT_DIR) else: self.logger().error('Cannot generate manifest, repo tool not found.') @@ -2433,8 +2521,6 @@ class LlvmPackage(BuildUtils): print('Did not find %s in %s' % (necessary_bin_file, bin_dir)) raise RuntimeError('Did not find %s in %s' % (necessary_bin_file, bin_dir)) - cmake_dir = os.path.join(lib_dir, 'cmake') - self.check_rm_tree(cmake_dir) self.notice_prebuilts_file(host, self.package_license_project_tuple(), install_dir) @@ -2486,6 +2572,9 @@ def main(): if build_config.build_ncurses: llvm_libs.build_ncurses(llvm_make, llvm_install) + 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) @@ -2574,6 +2663,27 @@ def main(): windows_python_builder.build() windows_python_builder.prepare_for_package() llvm_core.set_mingw_python_dir(windows_python_builder.install_dir) + + if build_config.enable_lzma_7zip: + build_utils.logger().info('build windows lzma') + target_triple = 'windows-x86_64' + build_dir = build_utils.merge_out_path('lzma') + build_utils.check_create_dir(build_dir) + clang_path = build_utils.merge_out_path('llvm-install', 'bin', 'clang') + src_dir = os.path.abspath(os.path.join(build_config.REPOROOT_DIR, 'third_party', 'lzma', 'C')) + windows_sysroot = build_utils.merge_out_path('mingw', build_config.MINGW_TRIPLE) + cmd = [ 'make', + 'install', + 'CC=%s' % clang_path, + 'SRC_PREFIX=%s/' % src_dir, + 'SYSROOT=%s' % windows_sysroot, + 'TARGET_TRIPLE=%s' % target_triple, + 'INSTALL_DIR=%s' % build_dir, + '-f', + 'MakeLiblzma'] + os.chdir(build_config.LLVM_BUILD_DIR) + build_utils.check_call(cmd) + llvm_core.llvm_compile_for_windows(build_config.TARGETS, build_config.enable_assertions, build_config.build_name) diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index 057431208322e7e8153a293b657e5efa69cb8b12..9202c141af8bd352ee3b313d429452c26ed7a549 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -2289,6 +2289,12 @@ function(llvm_setup_rpath name) set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-rpath-link,${LLVM_LIBRARY_OUTPUT_INTDIR} ") endif() + # OHOS_LOCAL begin + if(${CMAKE_SYSTEM_NAME} MATCHES "OHOS") + # Target property INSTALL_RPATH is not supported on OHOS. + set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-rpath,\'${_install_rpath}\' ") + endif() + # OHOS_LOCAL end else() return() endif() diff --git a/llvm/include/llvm/ObjCopy/CommonConfig.h b/llvm/include/llvm/ObjCopy/CommonConfig.h index 4921f5281ca63f6339a19dff0baed2f192ccff0c..38132b725557841d380c216b0fdf30b72f84b57e 100644 --- a/llvm/include/llvm/ObjCopy/CommonConfig.h +++ b/llvm/include/llvm/ObjCopy/CommonConfig.h @@ -218,6 +218,11 @@ struct CommonConfig { StringRef AllocSectionsPrefix; DiscardType DiscardMode = DiscardType::None; + // OHOS_LOCAL begin + // Additional ELF object flags + Optional ELFObjFlags; + // OHOS_LOCAL end + // Repeated options std::vector AddSection; std::vector DumpSection; diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp index 781be3d8aeb1c836eb641c7725b77bf52a916bee..5c55abb72aeda739ad5d5f5a765bd41eb2a5164c 100644 --- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp @@ -604,6 +604,12 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig, Obj.OSABI = Config.OutputArch.value().OSABI; } + // OHOS_LOCAL begin + if (Config.ELFObjFlags) { + Obj.Flags |= Config.ELFObjFlags.value(); + } + // OHOS_LOCAL end + if (!Config.SplitDWO.empty() && Config.ExtractDWO) { return Obj.removeSections( ELFConfig.AllowBrokenLinks, diff --git a/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td b/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td index 5190ea36c3b68c48dd5ffda9270ebe0874145c52..5485ac4c90da1d0b6242294ef40e35aebd688eab 100644 --- a/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td +++ b/llvm/lib/Target/AArch64/AArch64ArkGcCallingConvention.td @@ -506,7 +506,7 @@ def CSR_AArch64_ArkInt : CalleeSavedRegs<(add FP)>; def CSR_AArch64_ArkFast5 : CalleeSavedRegs<(add (sub (sequence "X%u", 5, 27), X16, X17), LR, - (sequence "D%u", 0, 31))>; + (sequence "D%u", 0, 29))>; def CSR_AArch64_ArkFast4 : CalleeSavedRegs<(add CSR_AArch64_ArkFast5, X4)>; diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.td b/llvm/lib/Target/AArch64/AArch64CallingConvention.td index dbc5b5eb2218b3567778db4d9650506b4d840673..0094ee3e31290bd4f38376d2cda06c74e441a4b3 100644 --- a/llvm/lib/Target/AArch64/AArch64CallingConvention.td +++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.td @@ -505,7 +505,7 @@ def CSR_AArch64_ArkInt : CalleeSavedRegs<(add FP)>; def CSR_AArch64_ArkFast5 : CalleeSavedRegs<(add (sub (sequence "X%u", 5, 27), X16, X17), LR, - (sequence "D%u", 0, 31))>; + (sequence "D%u", 0, 29))>; def CSR_AArch64_ArkFast4 : CalleeSavedRegs<(add CSR_AArch64_ArkFast5, X4)>; diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp index 835a7b6cc81d987186486590e7e31cc6476766f4..98c4f1ada15b2191e214d3c253930a53a4b4c2bd 100644 --- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp @@ -8141,6 +8141,14 @@ AArch64InstrInfo::getTailDuplicateSize(CodeGenOpt::Level OptLevel) const { return OptLevel >= CodeGenOpt::Aggressive ? 6 : 2; } +// OHOS_LOCAL begin +bool AArch64InstrInfo::preservesZeroValueInReg( + const MachineInstr *MI, const Register NullValueReg, + const TargetRegisterInfo *TRI) const { + return !MI->modifiesRegister(NullValueReg, TRI); +} +// OHOS_LOCAL end + unsigned llvm::getBLRCallOpcode(const MachineFunction &MF) { if (MF.getSubtarget().hardenSlsBlr()) return AArch64::BLRNoIP; diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.h b/llvm/lib/Target/AArch64/AArch64InstrInfo.h index b7a6ac301cdc17c708dd056d69333e30067aa23f..7059de6b272c340e93041b09f40208104682fe6b 100644 --- a/llvm/lib/Target/AArch64/AArch64InstrInfo.h +++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.h @@ -194,6 +194,12 @@ public: // with subreg operands to foldMemoryOperandImpl. bool isSubregFoldable() const override { return true; } + // OHOS_LOCAL begin + bool preservesZeroValueInReg(const MachineInstr *MI, + const Register NullValueReg, + const TargetRegisterInfo *TRI) const override; + // OHOS_LOCAL end + using TargetInstrInfo::foldMemoryOperandImpl; MachineInstr * foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI, diff --git a/llvm/test/CodeGen/AArch64/implicit-null-check.ll b/llvm/test/CodeGen/AArch64/implicit-null-check.ll index ed236e0010fb4b7ed95d5b8614c55beb94dce25f..59bbfda757c8d8038de7dc7b8c09184cb57b5b91 100644 --- a/llvm/test/CodeGen/AArch64/implicit-null-check.ll +++ b/llvm/test/CodeGen/AArch64/implicit-null-check.ll @@ -224,11 +224,13 @@ define i32 @imp_null_check_add_result(i32* %x, i32 %p) { define i32 @imp_null_check_hoist_over_udiv(i32* %x, i32 %a, i32 %b) { ; CHECK-LABEL: imp_null_check_hoist_over_udiv: ; CHECK: // %bb.0: // %entry -; CHECK-NEXT: cbz x0, .LBB9_2 +;; OHOS_LOCAL begin +; CHECK-NEXT: .Ltmp6: +; CHECK-NEXT: ldr w9, [x0] // on-fault: .LBB9_2 ; CHECK-NEXT: // %bb.1: // %not_null ; CHECK-NEXT: udiv w8, w1, w2 -; CHECK-NEXT: ldr w9, [x0] ; CHECK-NEXT: add w0, w9, w8 +;; OHOS_LOCAL end ; CHECK-NEXT: ret ; CHECK-NEXT: .LBB9_2: ; CHECK-NEXT: mov w0, #42 @@ -247,21 +249,20 @@ define i32 @imp_null_check_hoist_over_udiv(i32* %x, i32 %a, i32 %b) { ret i32 %res } - -; TODO: We should be able to hoist this - we can on x86, why isn't this -; working for aarch64? Aliasing? define i32 @imp_null_check_hoist_over_unrelated_load(i32* %x, i32* %y, i32* %z) { +;; OHOS_LOCAL begin ; CHECK-LABEL: imp_null_check_hoist_over_unrelated_load: ; CHECK: // %bb.0: // %entry -; CHECK-NEXT: cbz x0, .LBB10_2 +; CHECK-NEXT: .Ltmp7: +; CHECK-NEXT: ldr w0, [x0] // on-fault: .LBB10_2 ; CHECK-NEXT: // %bb.1: // %not_null ; CHECK-NEXT: ldr w8, [x1] -; CHECK-NEXT: ldr w0, [x0] ; CHECK-NEXT: str w8, [x2] ; CHECK-NEXT: ret ; CHECK-NEXT: .LBB10_2: ; CHECK-NEXT: mov w0, #42 ; CHECK-NEXT: ret +;; OHOS_LOCAL end entry: %c = icmp eq i32* %x, null br i1 %c, label %is_null, label %not_null, !make.implicit !0 @@ -279,7 +280,9 @@ define i32 @imp_null_check_hoist_over_unrelated_load(i32* %x, i32* %y, i32* %z) define i32 @imp_null_check_gep_load_with_use_dep(i32* %x, i32 %a) { ; CHECK-LABEL: imp_null_check_gep_load_with_use_dep: ; CHECK: // %bb.0: // %entry -; CHECK-NEXT: .Ltmp6: +;; OHOS_LOCAL begin +; CHECK-NEXT: .Ltmp8: +;; OHOS_LOCAL end ; CHECK-NEXT: ldr w8, [x0] // on-fault: .LBB11_2 ; CHECK-NEXT: // %bb.1: // %not_null ; CHECK-NEXT: add w9, w0, w1 @@ -357,14 +360,15 @@ not_null: ret i32 %t } -; TODO: We can fold to implicit null here, not sure why this isn't working define void @imp_null_check_store(i32* %x) { +;; OHOS_LOCAL begin ; CHECK-LABEL: imp_null_check_store: ; CHECK: // %bb.0: // %entry -; CHECK-NEXT: cbz x0, .LBB14_2 -; CHECK-NEXT: // %bb.1: // %not_null ; CHECK-NEXT: mov w8, #1 -; CHECK-NEXT: str w8, [x0] +; CHECK-NEXT: .Ltmp9: +; CHECK-NEXT: str w8, [x0] // on-fault: .LBB14_2 +; CHECK-NEXT: // %bb.1: // %not_null +;; OHOS_LOCAL end ; CHECK-NEXT: .LBB14_2: // %common.ret ; CHECK-NEXT: ret entry: @@ -379,14 +383,15 @@ define void @imp_null_check_store(i32* %x) { ret void } -;; TODO: can be implicit define void @imp_null_check_unordered_store(i32* %x) { +;; OHOS_LOCAL begin ; CHECK-LABEL: imp_null_check_unordered_store: ; CHECK: // %bb.0: // %entry -; CHECK-NEXT: cbz x0, .LBB15_2 -; CHECK-NEXT: // %bb.1: // %not_null ; CHECK-NEXT: mov w8, #1 -; CHECK-NEXT: str w8, [x0] +; CHECK-NEXT: .Ltmp10: +; CHECK-NEXT: str w8, [x0] // on-fault: .LBB15_2 +; CHECK-NEXT: // %bb.1: // %not_null +;; OHOS_LOCAL end ; CHECK-NEXT: .LBB15_2: // %common.ret ; CHECK-NEXT: ret entry: @@ -404,7 +409,9 @@ define void @imp_null_check_unordered_store(i32* %x) { define i32 @imp_null_check_neg_gep_load(i32* %x) { ; CHECK-LABEL: imp_null_check_neg_gep_load: ; CHECK: // %bb.0: // %entry -; CHECK-NEXT: .Ltmp7: +;; OHOS_LOCAL begin +; CHECK-NEXT: .Ltmp11: +;; OHOS_LOCAL end ; CHECK-NEXT: ldur w0, [x0, #-128] // on-fault: .LBB16_2 ; CHECK-NEXT: // %bb.1: // %not_null ; CHECK-NEXT: ret @@ -424,4 +431,33 @@ define i32 @imp_null_check_neg_gep_load(i32* %x) { ret i32 %t } +;; OHOS_LOCAL begin +;; LLVM does not support implicit null checks for ldp and stp +;; 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-NEXT: ret +entry: + %cmp = icmp eq i64* %array, null + br i1 %cmp, label %return, label %if.end, !make.implicit !0 + +if.end: ; preds = %entry + %0 = load i64, i64* %array, align 8 + %arrayidx1 = getelementptr inbounds i64, i64* %array, i64 1 + %1 = load i64, i64* %arrayidx1, align 8 + %add = add nsw i64 %1, %0 + br label %return + +return: ; preds = %entry, %if.end + %retval.0 = phi i64 [ %add, %if.end ], [ 0, %entry ] + ret i64 %retval.0 +} +;; OHOS_LOCAL end + !0 = !{} diff --git a/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll b/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll new file mode 100644 index 0000000000000000000000000000000000000000..dcecc92d5b7085fd27adf7840b2ecbe2adae84b1 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/ptr32-implicit-null-checks.ll @@ -0,0 +1,276 @@ +; RUN: llc --enable-implicit-null-checks --aarch64-enable-ptr32 -verify-machineinstrs -O2 < %s | FileCheck %s + +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 +define i32 @LoadI32FromPtr32(ptr addrspace(271) %object) { +entry: + %0 = addrspacecast ptr addrspace(271) %object to ptr + %cmp = icmp eq ptr %0, null + br i1 %cmp, label %if.then, label %if.end, !make.implicit !0 + +if.then: + tail call void @ThrowNullPointerException() + unreachable + +if.end: + %add.ptr = getelementptr inbounds i32, ptr addrspace(271) %object, i32 4 + %1 = load i32, ptr addrspace(271) %add.ptr, align 4 + ret i32 %1 +} + +; 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-NEXT: // %bb.1: +; CHECK-NEXT: ldr x30, [sp], #16 +; CHECK-NEXT: ret +; CHECK-NEXT: .LBB1_2: +; CHECK-NEXT: bl ThrowNullPointerException +define float @LoadFloatFromPtr32(ptr addrspace(271) %object) { +entry: + %0 = addrspacecast ptr addrspace(271) %object to ptr + %cmp = icmp eq ptr %0, null + br i1 %cmp, label %if.then, label %if.end, !make.implicit !0 + +if.then: ; preds = %entry + tail call void @ThrowNullPointerException() #2 + unreachable + +if.end: ; preds = %entry + %add.ptr = getelementptr inbounds float, ptr addrspace(271) %object, i32 4 + %1 = load float, ptr addrspace(271) %add.ptr, align 4 + ret float %1 +} + +; 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: .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 +define double @LoadDoubleFromPtr32(ptr addrspace(271) %object) { +entry: + %0 = addrspacecast ptr addrspace(271) %object to ptr + %cmp = icmp eq ptr %0, null + br i1 %cmp, label %if.then, label %if.end, !make.implicit !0 + +if.then: + tail call void @ThrowNullPointerException() + unreachable + +if.end: + %add.ptr = getelementptr inbounds double, ptr addrspace(271) %object, i32 8 + %1 = load double, ptr addrspace(271) %add.ptr, align 8 + 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 +define ptr addrspace(271) @LoadPtr32FromPtr32(ptr addrspace(271) %object) { +entry: + %0 = addrspacecast ptr addrspace(271) %object to ptr + %cmp = icmp eq ptr %0, null + br i1 %cmp, label %if.then, label %if.end, !make.implicit !0 + +if.then: ; preds = %entry + tail call void @ThrowNullPointerException() + unreachable + +if.end: ; preds = %entry + %add.ptr = getelementptr inbounds ptr addrspace(271), ptr addrspace(271) %object, i32 4 + %1 = load ptr addrspace(271), ptr addrspace(271) %add.ptr, align 4 + 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 +define void @StoreI32ToPtr32(ptr addrspace(271) %object, i32 %value) { +entry: + %0 = addrspacecast ptr addrspace(271) %object to ptr + %cmp = icmp eq ptr %0, null + br i1 %cmp, label %if.then, label %if.end, !make.implicit !0 + +if.then: ; preds = %entry + tail call void @ThrowNullPointerException() + unreachable + +if.end: ; preds = %entry + %add.ptr = getelementptr inbounds ptr addrspace(271), ptr addrspace(271) %object, i32 8 + store i32 %value, ptr addrspace(271) %add.ptr, align 4 + 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 +define void @StoreFloatToPtr32(ptr addrspace(271) %object, float %value) { +entry: + %0 = addrspacecast ptr addrspace(271) %object to ptr + %cmp = icmp eq ptr %0, null + br i1 %cmp, label %if.then, label %if.end, !make.implicit !0 + +if.then: ; preds = %entry + tail call void @ThrowNullPointerException() + unreachable + +if.end: ; preds = %entry + %add.ptr = getelementptr inbounds ptr addrspace(271), ptr addrspace(271) %object, i32 8 + store float %value, ptr addrspace(271) %add.ptr, align 4 + 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 +define void @StoreDoubleToPtr32(ptr addrspace(271) %object, double %value) { +entry: + %0 = addrspacecast ptr addrspace(271) %object to ptr + %cmp = icmp eq ptr %0, null + br i1 %cmp, label %if.then, label %if.end, !make.implicit !0 + +if.then: ; preds = %entry + tail call void @ThrowNullPointerException() + unreachable + +if.end: ; preds = %entry + %add.ptr = getelementptr inbounds ptr addrspace(271), ptr addrspace(271) %object, i32 8 + store double %value, ptr addrspace(271) %add.ptr, align 8 + ret void +} + +; 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 +define void @StoreConstantDoubleToPtr32(ptr addrspace(271) %object) { +entry: + %0 = addrspacecast ptr addrspace(271) %object to ptr + %cmp = icmp eq ptr %0, null + br i1 %cmp, label %if.then, label %if.end, !make.implicit !0 + +if.then: ; preds = %entry + tail call void @ThrowNullPointerException() + unreachable + +if.end: ; preds = %entry + %add.ptr = getelementptr inbounds ptr addrspace(271), ptr addrspace(271) %object, i32 8 + store double 0x400921FB4D12D84A, ptr addrspace(271) %add.ptr, align 8 + 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 +define void @StorePtr32ToPtr32(ptr addrspace(271) %object, ptr addrspace(271) %value) { +entry: + %0 = addrspacecast ptr addrspace(271) %object to ptr + %cmp = icmp eq ptr %0, null + br i1 %cmp, label %if.then, label %if.end, !make.implicit !0 + +if.then: ; preds = %entry + tail call void @ThrowNullPointerException() + unreachable + +if.end: ; preds = %entry + %add.ptr = getelementptr inbounds ptr addrspace(271), ptr addrspace(271) %object, i32 8 + store ptr addrspace(271) %value, ptr addrspace(271) %add.ptr, align 4 + ret void +} + +declare void @ThrowNullPointerException() + +!0 = !{} diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp index 7db1e79f3e49a1b017bdd9d6705026845bb33752..cfacaa0aa030d65724aac20fbd2341a86db8ff95 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp @@ -662,6 +662,18 @@ objcopy::parseObjcopyOptions(ArrayRef RawArgsArr, VisibilityStr.str().c_str()); } + // OHOS_LOCAL begin + if (InputArgs.hasArg(OBJCOPY_elf_flags)) { + StringRef ELFObjFlags = InputArgs.getLastArgValue(OBJCOPY_elf_flags); + uint32_t result; + if (ELFObjFlags.getAsInteger(10, result)) + return createStringError(errc::invalid_argument, + "'%s' is not a valid ELF object flags value", + ELFObjFlags.str().c_str()); + Config.ELFObjFlags = result; + } + // OHOS_LOCAL end + for (const auto *Arg : InputArgs.filtered(OBJCOPY_subsystem)) { StringRef Subsystem, Version; std::tie(Subsystem, Version) = StringRef(Arg->getValue()).split(':'); diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td index d3713b5ec3c32ff16623d81ac4aa1175d6dc7db3..4c454d7ec59a4cd71031b1d795bdbfb8fe15f6a4 100644 --- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -29,6 +29,9 @@ defm new_symbol_visibility : Eq<"new-symbol-visibility", "Visibility of " " with --add-symbol unless otherwise" " specified. The default value is 'default'.">; +/// OHOS_LOCAL +defm elf_flags : Eq<"elf-flags", "Additional ELF flags of unsigned integer type">; + def compress_debug_sections : Joined<["--"], "compress-debug-sections=">, MetaVarName<"format">, diff --git a/llvm/utils/lit/lit/llvm/subst.py b/llvm/utils/lit/lit/llvm/subst.py index 4275b8a56a3be4aad21a22fddfa914876fd89777..c51a257386bb24a9b2cda8e0cb418c0597b4c217 100644 --- a/llvm/utils/lit/lit/llvm/subst.py +++ b/llvm/utils/lit/lit/llvm/subst.py @@ -29,6 +29,18 @@ class FindTool(object): command += ' go=' + exe return command +# OHOS_LOCAL begin +class WrapTool(FindTool): + def __init__(self, name, wrapper): + super().__init__(name) + self.wrapper = wrapper + + def resolve(self, config, dirs): + command = super().resolve(config, dirs) + if not command: + return None + return self.wrapper + " " + command +# OHOS_LOCAL end class ToolSubst(object): """String-like class used to build regex substitution patterns for llvm diff --git a/openmp/runtime/src/kmp_i18n.cpp b/openmp/runtime/src/kmp_i18n.cpp index 2474810ce6bf23e74ba418b9fd023c07ad00b0ed..a164aa180dd48b6751d7d9bbd5b7c03cf0d93d02 100644 --- a/openmp/runtime/src/kmp_i18n.cpp +++ b/openmp/runtime/src/kmp_i18n.cpp @@ -710,8 +710,7 @@ static char *sys_error(int err) { #if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || \ (defined(__BIONIC__) && defined(_GNU_SOURCE) && \ - __ANDROID_API__ >= __ANDROID_API_M__) || \ - (defined(__OHOS__) && defined(_GNU_SOURCE)) + __ANDROID_API__ >= __ANDROID_API_M__) // GNU version of strerror_r. char buffer[2048];