From patchwork Wed Nov 15 10:57:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 165278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2456934vqg; Wed, 15 Nov 2023 02:58:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJfHPK3KuPtFkn+McbBWBbpd3ZVGSLA2hg5kITHFnOpXS2S3gzq3J2RI8QWIWLSR+eakMf X-Received: by 2002:a05:622a:15c1:b0:41c:c3ad:922d with SMTP id d1-20020a05622a15c100b0041cc3ad922dmr4638795qty.52.1700045889180; Wed, 15 Nov 2023 02:58:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700045889; cv=pass; d=google.com; s=arc-20160816; b=C/fcE/RKeXfrJwqdXTBwJR3odIiwOMqElsptZtm1pBEDmgGfQ4CbEgztg5wzD5NMmO fJsq8QRq3H8GLuV9wH8uySk1a5henbgUO4fC6axb+rTDaULGF+wMmaQeZfBxglxZ7QAk HIwxqNLPrvk0oxRwg820iiuIUgHkGttRO5bBaZaqh8YGtk0bX58uCveA1lQsp6DPNX1w 0OJMME5WSTMh1vQ+Q8HzgNsEwmN7QJILMom/H2UBTkTsqvQATjILK6IqPDNa2G2z9BTl feEkHYU6+gSATzRAlvn7cEa5tgmE31PQ1sGzWtdlPnX+2ph+vBO2tuAk2XzGjQl3uNE5 nt9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=B+8Fv6hXWRiPkD4xNq7VHYExxVkvBJ2mMCFfOWNhAcE=; fh=gQl4idKbq/nX3us5twaqDssuTOMIFQPDS+MWz3jC+os=; b=TwEz9hjO/VwzaKRMPoUDkzivc2sipy82t1cn7CaxXxFvOmqRMY96D1AyAEjylfOE5r Qz6XyY1x4Sq7FuG97xhpGp/5/dFSZlHCPfEIGkXG9Bp204eCfrsb5rAWyrNw4hTDTvXC gnA6x8STDQ94t6DBQYCGafyN2cGqpx13Jd4wOF0IyX378AcoDoAjtF1ihOu9XYslKn8W GObl2ZJRxkHu6Dp9EFq+rtczp/zlFo/eYfMcRnr0wYSSM78pBwULgLyqJKJ+r3RJiqPm rLsWBcPb2ZWvdZpJ1VDAzZkWxKcX80jdw8F1PI5WRdSx+wQLf1RCn+RVd3zecHTCsF9d Tvqw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cDkx0nhJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b14-20020ac87fce000000b004198ca326a2si9237631qtk.507.2023.11.15.02.58.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 02:58:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cDkx0nhJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD2303858CDB for ; Wed, 15 Nov 2023 10:58:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C57EC3858D20 for ; Wed, 15 Nov 2023 10:57:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C57EC3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C57EC3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700045866; cv=none; b=LYnTJU7BXelUPbE8QCDhl/CHSP5uPDUBu8gbuaimwBnmZEEgvi7jhXmr5gWH85/kcAx8XXI6Wm3qOsyGLwyzPzMR77Luv1V9dZNpSFflKMoKd64nstIfBx0tO9W8PflfmdCM5dWtbZvM8uR3/E3gnQRlQkOx9FaplGLpuPVtkho= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700045866; c=relaxed/simple; bh=mxzGiRHQNZC6ipzdB7Kj4TjtJia5zLRljiRsjr0DGsU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=EEZtIpDy/G/5ZL8uKN/Rvs7nHRZVZv3FVI+7XdNvhK1tVdRYmPLdXY1CWDHxFSOjhe6zLZhe8Xhjkuu+mB2VhOiXgOiKr76pQHfi3wHBMpblH6r1IyjpAEehPeiQz7OBRUbeQocR3ESPZsudFRk7nsgLr+GGT2YO7DlIEZYT138= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700045863; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=B+8Fv6hXWRiPkD4xNq7VHYExxVkvBJ2mMCFfOWNhAcE=; b=cDkx0nhJQ6fQnGBD6g1FX3RIkqT+/2mcvpdVlt8AiU9OgPKKWcuDPSv93By3d128IK9DE0 mrygyJZE1RWKhuDqnap4wdLj4+s+GwPCF/Ibr4pVLhYa+G+Anb+qJQwDV6EyuVkfNyeXy7 gBf+AAlR9rcT513N1ioVkEwBnbsW4VE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-79-by5xs45lPrSughNHcHs2WQ-1; Wed, 15 Nov 2023 05:57:41 -0500 X-MC-Unique: by5xs45lPrSughNHcHs2WQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A4BD1C05EB9; Wed, 15 Nov 2023 10:57:41 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 310CD492BE0; Wed, 15 Nov 2023 10:57:41 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AFAvc1V285830 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 11:57:38 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AFAvbRt285829; Wed, 15 Nov 2023 11:57:37 +0100 Date: Wed, 15 Nov 2023 11:57:36 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org, Iain Sandoe , Jeff Law Subject: [PATCH 2/4] libsanitizer: Apply local patches Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782627318406659243 X-GMAIL-MSGID: 1782627318406659243 Hi! This patch just reapplies local patches (will be noted in LOCAL_PATCHES). Jakub diff --git a/libsanitizer/asan/asan_globals.cpp b/libsanitizer/asan/asan_globals.cpp index 4d391cb2a88..01a243927ca 100644 --- a/libsanitizer/asan/asan_globals.cpp +++ b/libsanitizer/asan/asan_globals.cpp @@ -158,23 +158,6 @@ static void CheckODRViolationViaIndicator(const Global *g) { } } -// Check ODR violation for given global G by checking if it's already poisoned. -// We use this method in case compiler doesn't use private aliases for global -// variables. -static void CheckODRViolationViaPoisoning(const Global *g) { - if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) { - // This check may not be enough: if the first global is much larger - // the entire redzone of the second global may be within the first global. - for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) { - if (g->beg == l->g->beg && - (flags()->detect_odr_violation >= 2 || g->size != l->g->size) && - !IsODRViolationSuppressed(g->name)) - ReportODRViolation(g, FindRegistrationSite(g), - l->g, FindRegistrationSite(l->g)); - } - } -} - // Clang provides two different ways for global variables protection: // it can poison the global itself or its private alias. In former // case we may poison same symbol multiple times, that can help us to @@ -220,8 +203,6 @@ static void RegisterGlobal(const Global *g) { // where two globals with the same name are defined in different modules. if (UseODRIndicator(g)) CheckODRViolationViaIndicator(g); - else - CheckODRViolationViaPoisoning(g); } if (CanPoisonMemory()) PoisonRedZones(*g); diff --git a/libsanitizer/asan/asan_interceptors.h b/libsanitizer/asan/asan_interceptors.h index c4bf087ea17..9a6c22c764a 100644 --- a/libsanitizer/asan/asan_interceptors.h +++ b/libsanitizer/asan/asan_interceptors.h @@ -81,7 +81,12 @@ void InitializePlatformInterceptors(); #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \ !SANITIZER_NETBSD # define ASAN_INTERCEPT___CXA_THROW 1 -# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1 +# if ! defined(ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION) \ + || ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION +# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1 +# else +# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0 +# endif # if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__)) # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1 # else diff --git a/libsanitizer/asan/asan_mapping.h b/libsanitizer/asan/asan_mapping.h index c5f95c07a21..47ccf8444d3 100644 --- a/libsanitizer/asan/asan_mapping.h +++ b/libsanitizer/asan/asan_mapping.h @@ -190,7 +190,7 @@ # elif defined(__aarch64__) # define ASAN_SHADOW_OFFSET_CONST 0x0000001000000000 # elif defined(__powerpc64__) -# define ASAN_SHADOW_OFFSET_CONST 0x0000100000000000 +# define ASAN_SHADOW_OFFSET_CONST 0x0000020000000000 # elif defined(__s390x__) # define ASAN_SHADOW_OFFSET_CONST 0x0010000000000000 # elif SANITIZER_FREEBSD diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp index 37b2b57c0c8..2720a3cab2c 100644 --- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -838,9 +838,13 @@ u32 GetNumberOfCPUs() { #elif SANITIZER_SOLARIS return sysconf(_SC_NPROCESSORS_ONLN); #else +#if defined(CPU_COUNT) cpu_set_t CPUs; CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0); return CPU_COUNT(&CPUs); +#else + return 1; +#endif #endif } diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_mac.cpp index 24e3d111252..e1f83e4002a 100644 --- a/libsanitizer/sanitizer_common/sanitizer_mac.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_mac.cpp @@ -38,7 +38,7 @@ extern char **environ; # endif -# if defined(__has_include) && __has_include() +# if defined(__has_include) && __has_include() && defined(__BLOCKS__) # define SANITIZER_OS_TRACE 1 # include # else @@ -71,7 +71,15 @@ extern char ***_NSGetArgv(void); # include # include # include -# include +# if defined(__has_builtin) && __has_builtin(__builtin_os_log_format) +# include +# else + /* Without support for __builtin_os_log_format, fall back to the older + method. */ +# define OS_LOG_DEFAULT 0 +# define os_log_error(A,B,C) \ + asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", (C)); +# endif # include # include # include diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.h b/libsanitizer/sanitizer_common/sanitizer_mac.h index f0a97d098ee..1cf2e298cc9 100644 --- a/libsanitizer/sanitizer_common/sanitizer_mac.h +++ b/libsanitizer/sanitizer_common/sanitizer_mac.h @@ -14,6 +14,26 @@ #include "sanitizer_common.h" #include "sanitizer_platform.h" + +/* TARGET_OS_OSX is not present in SDKs before Darwin16 (macOS 10.12) use + TARGET_OS_MAC (we have no support for iOS in any form for these versions, + so there's no ambiguity). */ +#if !defined(TARGET_OS_OSX) && TARGET_OS_MAC +# define TARGET_OS_OSX 1 +#endif + +/* Other TARGET_OS_xxx are not present on earlier versions, define them to + 0 (we have no support for them; they are not valid targets anyway). */ +#ifndef TARGET_OS_IOS +#define TARGET_OS_IOS 0 +#endif +#ifndef TARGET_OS_TV +#define TARGET_OS_TV 0 +#endif +#ifndef TARGET_OS_WATCH +#define TARGET_OS_WATCH 0 +#endif + #if SANITIZER_APPLE #include "sanitizer_posix.h" diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp index bf0f355847c..c278c8797f7 100644 --- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp @@ -26,7 +26,10 @@ // With old kernels (and even new kernels on powerpc) asm/stat.h uses types that // are not defined anywhere in userspace headers. Fake them. This seems to work -// fine with newer headers, too. +// fine with newer headers, too. Beware that with , struct stat +// takes the form of struct stat64 on 32-bit platforms if _FILE_OFFSET_BITS=64. +// Also, for some platforms (e.g. mips) there are additional members in the +// struct stat:s. #include # if defined(__x86_64__) || defined(__mips__) || defined(__hexagon__) # include diff --git a/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp index b44e016a0e5..f2f38467121 100644 --- a/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp @@ -146,8 +146,13 @@ static bool IsDyldHdr(const mach_header *hdr) { // until we hit a Mach header matching dyld instead. These recurse // calls are expensive, but the first memory map generation occurs // early in the process, when dyld is one of the only images loaded, -// so it will be hit after only a few iterations. These assumptions don't hold -// on macOS 13+ anymore (dyld itself has moved into the shared cache). +// so it will be hit after only a few iterations. These assumptions don't +// hold on macOS 13+ anymore (dyld itself has moved into the shared cache). + +// FIXME: Unfortunately, the upstream revised version to deal with macOS 13+ +// is incompatible with GCC and also uses APIs not available on earlier +// systems which we support; backed out for now. + static mach_header *GetDyldImageHeaderViaVMRegion() { vm_address_t address = 0; @@ -171,64 +176,17 @@ static mach_header *GetDyldImageHeaderViaVMRegion() { } } -extern "C" { -struct dyld_shared_cache_dylib_text_info { - uint64_t version; // current version 2 - // following fields all exist in version 1 - uint64_t loadAddressUnslid; - uint64_t textSegmentSize; - uuid_t dylibUuid; - const char *path; // pointer invalid at end of iterations - // following fields all exist in version 2 - uint64_t textSegmentOffset; // offset from start of cache -}; -typedef struct dyld_shared_cache_dylib_text_info - dyld_shared_cache_dylib_text_info; - -extern bool _dyld_get_shared_cache_uuid(uuid_t uuid); -extern const void *_dyld_get_shared_cache_range(size_t *length); -extern int dyld_shared_cache_iterate_text( - const uuid_t cacheUuid, - void (^callback)(const dyld_shared_cache_dylib_text_info *info)); -} // extern "C" - -static mach_header *GetDyldImageHeaderViaSharedCache() { - uuid_t uuid; - bool hasCache = _dyld_get_shared_cache_uuid(uuid); - if (!hasCache) - return nullptr; - - size_t cacheLength; - __block uptr cacheStart = (uptr)_dyld_get_shared_cache_range(&cacheLength); - CHECK(cacheStart && cacheLength); - - __block mach_header *dyldHdr = nullptr; - int res = dyld_shared_cache_iterate_text( - uuid, ^(const dyld_shared_cache_dylib_text_info *info) { - CHECK_GE(info->version, 2); - mach_header *hdr = - (mach_header *)(cacheStart + info->textSegmentOffset); - if (IsDyldHdr(hdr)) - dyldHdr = hdr; - }); - CHECK_EQ(res, 0); - - return dyldHdr; -} - const mach_header *get_dyld_hdr() { if (!dyld_hdr) { // On macOS 13+, dyld itself has moved into the shared cache. Looking it up // via vm_region_recurse_64() causes spins/hangs/crashes. + // FIXME: find a way to do this compatible with GCC. if (GetMacosAlignedVersion() >= MacosVersion(13, 0)) { - dyld_hdr = GetDyldImageHeaderViaSharedCache(); - if (!dyld_hdr) { VReport(1, - "Failed to lookup the dyld image header in the shared cache on " - "macOS 13+ (or no shared cache in use). Falling back to " + "looking up the dyld image header in the shared cache on " + "macOS 13+ is not yet supported. Falling back to " "lookup via vm_region_recurse_64().\n"); dyld_hdr = GetDyldImageHeaderViaVMRegion(); - } } else { dyld_hdr = GetDyldImageHeaderViaVMRegion(); } diff --git a/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp b/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp index d24fae98213..661495e2340 100644 --- a/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp @@ -87,8 +87,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp, // Nope, this does not look right either. This means the frame after next does // not have a valid frame pointer, but we can still extract the caller PC. // Unfortunately, there is no way to decide between GCC and LLVM frame - // layouts. Assume LLVM. - return bp_prev; + // layouts. Assume GCC. + return bp_prev - 1; #else return (uhwptr*)bp; #endif @@ -111,14 +111,21 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top, IsAligned((uptr)frame, sizeof(*frame)) && size < max_depth) { #ifdef __powerpc__ - // PowerPC ABIs specify that the return address is saved at offset - // 16 of the *caller's* stack frame. Thus we must dereference the - // back chain to find the caller frame before extracting it. + // PowerPC ABIs specify that the return address is saved on the + // *caller's* stack frame. Thus we must dereference the back chain + // to find the caller frame before extracting it. uhwptr *caller_frame = (uhwptr*)frame[0]; if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) || !IsAligned((uptr)caller_frame, sizeof(uhwptr))) break; + // For most ABIs the offset where the return address is saved is two + // register sizes. The exception is the SVR4 ABI, which uses an + // offset of only one register size. +#ifdef _CALL_SYSV + uhwptr pc1 = caller_frame[1]; +#else uhwptr pc1 = caller_frame[2]; +#endif #elif defined(__s390__) uhwptr pc1 = frame[14]; #elif defined(__loongarch__) || defined(__riscv) diff --git a/libsanitizer/tsan/tsan_rtl_ppc64.S b/libsanitizer/tsan/tsan_rtl_ppc64.S index 8285e21aa1e..9e533a71a9c 100644 --- a/libsanitizer/tsan/tsan_rtl_ppc64.S +++ b/libsanitizer/tsan/tsan_rtl_ppc64.S @@ -1,5 +1,6 @@ #include "tsan_ppc_regs.h" + .machine altivec .section .text .hidden __tsan_setjmp .globl _setjmp diff --git a/libsanitizer/ubsan/ubsan_flags.cpp b/libsanitizer/ubsan/ubsan_flags.cpp index 25cefd46ce2..9a66bd37518 100644 --- a/libsanitizer/ubsan/ubsan_flags.cpp +++ b/libsanitizer/ubsan/ubsan_flags.cpp @@ -50,6 +50,7 @@ void InitializeFlags() { { CommonFlags cf; cf.CopyFrom(*common_flags()); + cf.print_summary = false; cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH"); OverrideCommonFlags(cf); } diff --git a/libsanitizer/ubsan/ubsan_handlers.cpp b/libsanitizer/ubsan/ubsan_handlers.cpp index 410292a0d53..970075e69a6 100644 --- a/libsanitizer/ubsan/ubsan_handlers.cpp +++ b/libsanitizer/ubsan/ubsan_handlers.cpp @@ -894,6 +894,21 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable, } // namespace __ubsan +void __ubsan::__ubsan_handle_cfi_bad_icall(CFIBadIcallData *CallData, + ValueHandle Function) { + GET_REPORT_OPTIONS(false); + CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type}; + handleCFIBadIcall(&Data, Function, Opts); +} + +void __ubsan::__ubsan_handle_cfi_bad_icall_abort(CFIBadIcallData *CallData, + ValueHandle Function) { + GET_REPORT_OPTIONS(true); + CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type}; + handleCFIBadIcall(&Data, Function, Opts); + Die(); +} + void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data, ValueHandle Value, uptr ValidVtable) { diff --git a/libsanitizer/ubsan/ubsan_handlers.h b/libsanitizer/ubsan/ubsan_handlers.h index 219fb15de55..9f412353fc0 100644 --- a/libsanitizer/ubsan/ubsan_handlers.h +++ b/libsanitizer/ubsan/ubsan_handlers.h @@ -215,12 +215,20 @@ enum CFITypeCheckKind : unsigned char { CFITCK_VMFCall, }; +struct CFIBadIcallData { + SourceLocation Loc; + const TypeDescriptor &Type; +}; + struct CFICheckFailData { CFITypeCheckKind CheckKind; SourceLocation Loc; const TypeDescriptor &Type; }; +/// \brief Handle control flow integrity failure for indirect function calls. +RECOVERABLE(cfi_bad_icall, CFIBadIcallData *Data, ValueHandle Function) + /// \brief Handle control flow integrity failures. RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function, uptr VtableIsValid) diff --git a/libsanitizer/ubsan/ubsan_platform.h b/libsanitizer/ubsan/ubsan_platform.h index d2cc2e10bd2..ad3e883f0f3 100644 --- a/libsanitizer/ubsan/ubsan_platform.h +++ b/libsanitizer/ubsan/ubsan_platform.h @@ -12,6 +12,7 @@ #ifndef UBSAN_PLATFORM_H #define UBSAN_PLATFORM_H +#ifndef CAN_SANITIZE_UB // Other platforms should be easy to add, and probably work as-is. #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \ defined(__NetBSD__) || defined(__DragonFly__) || \ @@ -21,5 +22,6 @@ #else # define CAN_SANITIZE_UB 0 #endif +#endif //CAN_SANITIZE_UB #endif From patchwork Wed Nov 15 10:59:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 165279 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2457520vqg; Wed, 15 Nov 2023 02:59:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFangNnjBzJCz7gPzQlZlfOKlMCHznc4vzmXlePTCeRbYGBGiHOgO541glGbaYFIhuhJcKy X-Received: by 2002:a05:622a:188f:b0:421:ad0b:fe5a with SMTP id v15-20020a05622a188f00b00421ad0bfe5amr6003195qtc.2.1700045987376; Wed, 15 Nov 2023 02:59:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700045987; cv=pass; d=google.com; s=arc-20160816; b=y9UxKX/QGQso9lJnQXPPKy3hOEUVp/Q/1WJVtoBWkBgvir0/vvj7hAerasQ6HKoaHC Q4ahc6QT0gGWEYcGfP1zExyCykc1W+DRx8ar2KRtMM3wHkMCrfM1Tv0yIQxX3L25QEOV TiKy5uwcF2cNGlKpz+UOBdRJWPfq+2eVtAUVZBJh4CwLmuEGK4PN2By5BQmce/4VJ2In jE8SDEBKAoonF/7GRUORdbo8m3fK/fHB9ypKuHK3yp22Rj9uP2mM3RUVcRTnpNzWdD60 ZwVuNo+fgCu/XE7g8aJXH9ubZmVGu/EHfDseqLRSCDBADrgC/DgSgl7QvVansFahO7XK KVQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=vXil8TZofhX7T1dA+gm8TcjZGAOqmcMaor0oGqYJwaQ=; fh=gQl4idKbq/nX3us5twaqDssuTOMIFQPDS+MWz3jC+os=; b=o92KqKqD6H964GHUtWVigfBEQpK7N/0a18G8P3vjQARVtB/ZEjCEsWSrUw3YizpB5i XoiZN2/gmPGlbHI86/35bg1es7X+2ZwNc9/8+nuuvv7C64674qZ6FcvGncDALR4ogN82 6fLa3iCe3/nBQgPEzF9cRj322OimB+IEozS+UMT336AJSUfcxpChMr6wjnn2wnBQ51Nn FBsCxNTiaAAzZXcdBOVQ/aY9e6MfiYD1KSIMIEKypavmq0ZN08w0fK/2TpMrsPy7kdLk 4ZJSDObogkfewHGI1dNmmTW5sHyjfZeeWve5dLFCkcr5HKkrX9CzCdFLd/9gCzReLEBx QIMQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ufs7BL1/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s27-20020a05622a1a9b00b0040fdcdae9d5si8280844qtc.4.2023.11.15.02.59.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 02:59:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ufs7BL1/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C26A3858419 for ; Wed, 15 Nov 2023 10:59:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9A56D3858D20 for ; Wed, 15 Nov 2023 10:59:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A56D3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9A56D3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700045964; cv=none; b=Ex7BQ0hSSqJM2PB0kTX/k/5TZgS+xePvLGIYOLbP8iqEgGyRxNp2kN9KGqWVRJuMTwcpPLLhsturx99yjevq5+T38QMTf8YdAqZiCyPQIRoWvmSD1jqSqPHOwHq9FGN+LTZk98xl2OJVRvoMUkrj6tO/+in2Ndt1KJTVvr+9Gjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700045964; c=relaxed/simple; bh=C+CxijXg3glIU6rIO9k6Ha/vfVt4s1trel4K5jL9BnE=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=KwWwCYtOcPPJpLSWMSb1Oz+pUVFQCbCOazUAnleB2esslU7n43PZUBHo6AocRhNWtYyXfhYUJ6OtPuuLj18yfRo8IqrE8/AxJ0cIwjN5Rez1ALCZ9AIZQMUInH3iqo0Cq5sgoQ7I11sJRG0H7DmZUgH11HbFYO/SXJwEm3Ma33w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700045963; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=vXil8TZofhX7T1dA+gm8TcjZGAOqmcMaor0oGqYJwaQ=; b=Ufs7BL1/lQ4t3kSA3LauL9SWzkTCjJ0N/fmaybaoIe4VZ9YpCWCnkjmPgwcm/UtXf75PTM RmIvzMQoFyxDlhS9OOjpgx+hxHOngoV//hU9GWRk6W8SrsgVQACYxRo2IaQ6vJ0sPYoHtu 7CbMscYXTDGXL2qHgv4co8qRRr7XLvE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-442-wy-if1SWO9GTpGnHlSfCYg-1; Wed, 15 Nov 2023 05:59:18 -0500 X-MC-Unique: wy-if1SWO9GTpGnHlSfCYg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 32A8B381A88A; Wed, 15 Nov 2023 10:59:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E251D36EE; Wed, 15 Nov 2023 10:59:17 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AFAxFvh285845 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 11:59:15 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AFAxDbM285844; Wed, 15 Nov 2023 11:59:13 +0100 Date: Wed, 15 Nov 2023 11:59:13 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org, Iain Sandoe , Jeff Law Subject: [PATCH 3/4] libsanitizer: Adjust the asan/sanity-check-pure-c-1.c test Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782627421310209294 X-GMAIL-MSGID: 1782627421310209294 Hi! The updated libasan doesn't print __interceptor_free (or __interceptor_malloc) but free (or malloc), the following patch adjusts the testcase so that it accepts it. 2023-11-15 Jakub Jelinek * c-c++-common/asan/sanity-check-pure-c-1.c: Adjust for interceptor_ or wrap_ substrings possibly not being emitted in newer libasan. Jakub --- gcc/testsuite/c-c++-common/asan/sanity-check-pure-c-1.c.jj 2020-01-14 20:02:46.646611886 +0100 +++ gcc/testsuite/c-c++-common/asan/sanity-check-pure-c-1.c 2023-11-15 10:51:50.921621770 +0100 @@ -10,7 +10,7 @@ int main() { } /* { dg-output "heap-use-after-free.*(\n|\r\n|\r)" } */ -/* { dg-output " #0 \[^\n\r]*(in _*(interceptor_|wrap_)free|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #0 \[^\n\r]*(in _*(interceptor_|wrap_)?free|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output " #1 \[^\n\r]*(in _*main (\[^\n\r]*sanity-check-pure-c-1.c:8|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */ -/* { dg-output " #0 \[^\n\r]*(in _*(interceptor_|wrap_)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ +/* { dg-output " #0 \[^\n\r]*(in _*(interceptor_|wrap_)?malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ /* { dg-output " #1 \[^\n\r]*(in _*main (\[^\n\r]*sanity-check-pure-c-1.c:7|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */ From patchwork Wed Nov 15 11:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 165280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2459824vqg; Wed, 15 Nov 2023 03:03:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEs7opyy3fT++V9DUVDwf5anOJ4T8GcojyPsEgzKxjwgVQuRjLunpgldt/eGeM5sh5u/QWg X-Received: by 2002:a05:6214:17c6:b0:66d:3f8b:fd93 with SMTP id cu6-20020a05621417c600b0066d3f8bfd93mr5441710qvb.2.1700046187412; Wed, 15 Nov 2023 03:03:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700046187; cv=pass; d=google.com; s=arc-20160816; b=bgixGOkDQzvq3H77pUYSQ893L3eLeW7TV+nqBUhLwdgiFZ4p4R3ujJ/lrGgzyugOQY c+2VtaPFLTe8G2JGfUuRfX4Ii6H4nGwp3i0GM0RMIFb9V2c0b4LFqCGKClpFl6T01lFo FIEiyaVY+2/0JVIOfKsxsFqdJtxHo+0TU1JRNJMZRprUs0JJ/mzjmxTiVNcXKDUxL8KY Rd8462A84IfLorVxmUJgWoxIxWByMO/Ee7kvJU9F0HVh9gLzTV4iv2TV09dt/GX9KIQW iHy9D7a6x255Kk2kgkD2MP1A7h5XGZRU5GPuLawuo6CUwttsjhHgEVtIm89yCVonKV2Y bKgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=JO1HF1FzV0JQL82smmjEupE4F56H0jIluQd+g0vn6Jc=; fh=gQl4idKbq/nX3us5twaqDssuTOMIFQPDS+MWz3jC+os=; b=0txWTR6B6n6DaOBOCL6UJ0eU4/AcgFX3earb+F0hGnNZoWbBYsmWYnEwI4fN0Blgbd uuoxVPJEiWNUGR5GHuQGzk5pK4Y7PifRmBzzbLTCT872GQv7AroS8l6D8mYGycAahntA 3l5E6h7ef2s5fzPpaf/o1B75sx/6TMP+Q+8qn0CLd8naGQTKqOoGx2MuxliGLQYSDJuA sOGEz5mWzSr19GdnJ0cw7jDf95QUw4ywFWvaulanA67jhYUtS3NY/dL8HDCkBSyf1nqo vrr3nRFFQerwfQxzaQDJtoE4ClakRFIktA/ebcrcqT+FN967+BqmLTaIUbPWfAy3cncI VJFw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XZ1O6+L4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id eu18-20020ad44f52000000b00670b3a82416si8720795qvb.343.2023.11.15.03.03.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 03:03:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XZ1O6+L4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B704385783E for ; Wed, 15 Nov 2023 11:02:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B0BB43858C30 for ; Wed, 15 Nov 2023 11:02:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0BB43858C30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B0BB43858C30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700046154; cv=none; b=SBhhDLDloXmc2T4x6lS1kV9KLb24ASHWeowLvlON+EEsP04gA3OKbrDsRHjQcHhEVEkrrYXMctkaJ8sQCrcJC8MfJpXXJz357/moh4Y6C8nISj0umVyXVu4hAuh6xIF70iMwK0uj0cQzlQOn8ZfbUpDwUcQd0JVigBhpJT3nmvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700046154; c=relaxed/simple; bh=WzxxdN036MGZCpHPbqCdoJrWxYf7JDGEFkKgMytwrYM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=oNslNeuhuxP4AeMqrtLSd/xM1qyzmCrevyFUV8aOE2PHT+Qk4d2KMz52VGhtUM+0HG/CVYjHMCRsCS2S8pGs7v1fpeFwSlvog44AbWh9mqodxjH5BVVZkoZwd2Xib4LUT9L3bDtma5po1nO9NL6/gGevkOGxTWtxfLsPL4jTKfo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700046151; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=JO1HF1FzV0JQL82smmjEupE4F56H0jIluQd+g0vn6Jc=; b=XZ1O6+L4No42DUjqID/TDuRQYsMO+FOvd/l8SwWQF/UCqEmeA2TDfDBxRSB9laFxs66QvR bgyRjb4IB0+ftGnVKpBW6aAu8W9zBMk2e0+JLLGC0YLpvXfRV+Szv5xjBPRKZIRA1bUJQc yaXZn9f20hS6nUYQ1o5Aieb5a1cI+ac= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-2vNRZKQrMBijex_ZB-bkTQ-1; Wed, 15 Nov 2023 06:02:28 -0500 X-MC-Unique: 2vNRZKQrMBijex_ZB-bkTQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 47D85811003; Wed, 15 Nov 2023 11:02:28 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC2FA2166B29; Wed, 15 Nov 2023 11:02:27 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AFB2O1Y285879 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 12:02:25 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AFB2NZJ285878; Wed, 15 Nov 2023 12:02:23 +0100 Date: Wed, 15 Nov 2023 12:02:23 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org, Iain Sandoe , Jeff Law Subject: [PATCH 4/4] libsanitizer: Readd __ubsan_handle_function_type_mismatch_v1{,_abort} Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782627630616786067 X-GMAIL-MSGID: 1782627630616786067 Hi! So that we don't have to bump libubsan.so.1 SONAME, the following patch reverts part of the changes which removed two handlers. While we don't actually use them from GCC, we shouldn't remove supported entrypoints unless SONAME is changed (removal of __interceptor_* or ___interceptor_* is fine). This is the only removal, other libraries just added some symbols. 2023-11-15 Jakub Jelinek * ubsan/ubsan_handlers_cxx.h (FunctionTypeMismatchData): Forward declare. (__ubsan_handle_function_type_mismatch_v1, __ubsan_handle_function_type_mismatch_v1_abort): Declare. * ubsan/ubsan_handlers_cxx.cpp (handleFunctionTypeMismatch, __ubsan_handle_function_type_mismatch_v1, __ubsan_handle_function_type_mismatch_v1_abort): New functions readded for backwards compatibility from older ubsan. * ubsan/ubsan_interface.inc (__ubsan_handle_function_type_mismatch_v1, __ubsan_handle_function_type_mismatch_v1_abort): Readd. Jakub --- libsanitizer/ubsan/ubsan_handlers_cxx.h.jj 2023-11-14 23:52:59.417503473 +0100 +++ libsanitizer/ubsan/ubsan_handlers_cxx.h 2023-11-15 11:36:34.961739772 +0100 @@ -33,6 +33,19 @@ void __ubsan_handle_dynamic_type_cache_m extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __ubsan_handle_dynamic_type_cache_miss_abort( DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash); + +struct FunctionTypeMismatchData; + +extern "C" SANITIZER_INTERFACE_ATTRIBUTE void +__ubsan_handle_function_type_mismatch_v1(FunctionTypeMismatchData *Data, + ValueHandle Val, + ValueHandle calleeRTTI, + ValueHandle fnRTTI); +extern "C" SANITIZER_INTERFACE_ATTRIBUTE void +__ubsan_handle_function_type_mismatch_v1_abort(FunctionTypeMismatchData *Data, + ValueHandle Val, + ValueHandle calleeRTTI, + ValueHandle fnRTTI); } #endif // UBSAN_HANDLERS_CXX_H --- libsanitizer/ubsan/ubsan_handlers_cxx.cpp.jj 2023-11-14 23:52:59.417503473 +0100 +++ libsanitizer/ubsan/ubsan_handlers_cxx.cpp 2023-11-15 11:31:56.241672876 +0100 @@ -156,6 +156,50 @@ void __ubsan_handle_cfi_bad_type(CFIChec Diag(Loc, DL_Note, ET, "check failed in %0, vtable located in %1") << SrcModule << DstModule; } + +static bool handleFunctionTypeMismatch(FunctionTypeMismatchData *Data, + ValueHandle Function, + ValueHandle calleeRTTI, + ValueHandle fnRTTI, ReportOptions Opts) { + if (checkTypeInfoEquality(reinterpret_cast(calleeRTTI), + reinterpret_cast(fnRTTI))) + return false; + + SourceLocation CallLoc = Data->Loc.acquire(); + ErrorType ET = ErrorType::FunctionTypeMismatch; + + if (ignoreReport(CallLoc, Opts, ET)) + return true; + + ScopedReport R(Opts, CallLoc, ET); + + SymbolizedStackHolder FLoc(getSymbolizedLocation(Function)); + const char *FName = FLoc.get()->info.function; + if (!FName) + FName = "(unknown)"; + + Diag(CallLoc, DL_Error, ET, + "call to function %0 through pointer to incorrect function type %1") + << FName << Data->Type; + Diag(FLoc, DL_Note, ET, "%0 defined here") << FName; + return true; +} + +void __ubsan_handle_function_type_mismatch_v1(FunctionTypeMismatchData *Data, + ValueHandle Function, + ValueHandle calleeRTTI, + ValueHandle fnRTTI) { + GET_REPORT_OPTIONS(false); + handleFunctionTypeMismatch(Data, Function, calleeRTTI, fnRTTI, Opts); +} + +void __ubsan_handle_function_type_mismatch_v1_abort( + FunctionTypeMismatchData *Data, ValueHandle Function, + ValueHandle calleeRTTI, ValueHandle fnRTTI) { + GET_REPORT_OPTIONS(true); + if (handleFunctionTypeMismatch(Data, Function, calleeRTTI, fnRTTI, Opts)) + Die(); +} } // namespace __ubsan #endif // CAN_SANITIZE_UB --- libsanitizer/ubsan/ubsan_interface.inc.jj 2023-11-14 23:52:59.417503473 +0100 +++ libsanitizer/ubsan/ubsan_interface.inc 2023-11-15 11:32:57.430809418 +0100 @@ -21,6 +21,8 @@ INTERFACE_FUNCTION(__ubsan_handle_dynami INTERFACE_FUNCTION(__ubsan_handle_dynamic_type_cache_miss_abort) INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow) INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow_abort) +INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1) +INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1_abort) INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch) INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_abort) INTERFACE_FUNCTION(__ubsan_handle_implicit_conversion)