From patchwork Tue May 5 20:08:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1283898 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Ps/tXH5A; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49GrQG5Rfhz9sRf for ; Wed, 6 May 2020 06:08:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E1FA3890C34; Tue, 5 May 2020 20:08:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id 7659C3890C12 for ; Tue, 5 May 2020 20:08:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7659C3890C12 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x72e.google.com with SMTP id g185so3734050qke.7 for ; Tue, 05 May 2020 13:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:cc:from:subject:message-id:date:user-agent:mime-version :content-language; bh=dnJ624vewJvzEVXWnZGdF/aJPfxOUytguOD2MgVB8UU=; b=Ps/tXH5A7BPk9wxR54ri8UDDhe5qba++VvDxHTCT1MoyiYXlaNSGS8+Aw+dAoD2lSe yKGBaEMRzz41+ouFmKQUpff1lvMDa/PuZkBZWE6ExlH1ObhZSQv/GHMA42t7FSr4NND+ cpHXGTh9snaP1neJZVzoq64pd4zK6MpdxAylJGQYqdlu7NC0+z3XS0Rnr9dmSI3B5Q/C C26oGxfMLDFEfrLRzFvYKTh5TPVxRKikxyCf1F3Sw2siHS6fmBZO3dgiGnmFwozdkULl VBKJ4hAmX5bdXLiDHB+9AKA68UE+vdk8RC4hfu/uhiqYLTZDNZKB+QBlNSlsNBZziKY3 gUvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version:content-language; bh=dnJ624vewJvzEVXWnZGdF/aJPfxOUytguOD2MgVB8UU=; b=RGbLjTTXtXS4w9H+baMaUnM9fH39KQz/JqYIm2kTH+7oLe1V9u5Y8T+fM4O9elSSxV 75SA5hf24jD6PsgNqt4mRqfz3X9kTnKPCdWP4yLXVrdDjPsZirxgFhkGqLQamOa8AC8/ Bf4Q7ddDvCjQHV1Yxpb/Ehu/8PUdTjiDMvaJL2HdHMiYAoXtIzMXo/sxBtWmy7a9A/YN fUCPiL/8/wJTRFoX2UHAMknPqQIunOPpn5avb+QT9M2rpC/Aybf6CVvRNbLEPeLah33/ aIziDy3ijrTJ4u+DBOgIc+P3DdtDJuH+oJt0CRQZ+spYZn6QL1IDdMEdxfrwsFWWFs+E +W+A== X-Gm-Message-State: AGi0PuZDZ016XrBJK3e/tZfh6/6PYgnoU1qGBvOUcJL6UmQj5xVOjg6Z 9/td8//BzZ6OP5MJPCjeJtE= X-Google-Smtp-Source: APiQypLWkmmscvSYdGErJpRXtOw9aI5Td9qAQCnlVcaONYXgmyTbJ1Hgk+6eVAbsTDimIUkV0zr5rQ== X-Received: by 2002:a37:a806:: with SMTP id r6mr5289947qke.171.1588709309175; Tue, 05 May 2020 13:08:29 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:3566:64a6:afbf:84b5? ([2620:10d:c091:480::1:1b5e]) by smtp.googlemail.com with ESMTPSA id x19sm2732618qkb.136.2020.05.05.13.08.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 May 2020 13:08:28 -0700 (PDT) To: triegel@redhat.com From: Nathan Sidwell Subject: [libitm] eh specifications are lax Message-ID: Date: Tue, 5 May 2020 16:08:27 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jakub Jelinek , GCC Patches Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" I discovered that libitm: (a) declares __cxa_allocate_exception and friends directly, (b) doesn't mark them as 'throw()' (c) doesn't mark the replacment fns _ITM_$foo as nothrow either We happen to get away with it because of code in the compiler that, although it checks the parameter types, doesn't check the exception specification. (One reason being they used to not be part of the language's type system, but now they are.) I suspect this can lead us to generate pessimal code later, if we've seen one of these decls earlier. Anyway, with modules it becomes trickier[*], so I'm trying to clean it up and not be a problem. I see Jakub fixed part of the problem (https://gcc.gnu.org/pipermail/gcc-patches/2018-December/513302.html) AFAICT, he did fix libitm's decls, but left the lax parm-type checking in the compiler. libitm.h is not very informative about specification: in version 1 of http://www.intel.com/some/path/here.pdf. */ Anyway, it was too fiddly to have libitm pick up the declarations from libsupc++. Besides it makes them weak declarations, and then provides definitions for non-elf systems. So this patch adds the expected 'throw()' While I can't be sure, I suspect the _ITM entry points are supposed to have the same exception specification as the original entry points. So those are also made 'throw ()'. libstdc++'s _GLIBCXX_NOTHROW didn't seem available, so I make use of a new _ITM_NOTHROW macro, suitably defined. Because of the lax checking in the compiler, and old compiler with a patched libitm.h will be ok... Until I change the compiler :) booted & tested on x86_64-linux, ok? nathan [*] modules make it harder to have ODR violations, that's why it finds ODR violations in existing code. 2020-05-05 Nathan Sidwell Fix throw specifiers on interface. * libitm/libitm.h (_ITM_NOTHROW): Define. (_ITM_cxa_allocate_exception, _ITM_cxa_free_exception) (_ITM_cxa_begin_catch): Use it. * eh_cpp.cc: Add throw() to __cxa_allocate_exception, __cxa_free_exception, __cxa_begin_catch, __cxa_tm_cleanup, __cxa_get_globals. (_ITM_cxa_allocate_exception, _ITM_cxa_free_exception) (_ITM_cxa_begin_catch): Likewise. diff --git a/libitm/eh_cpp.cc b/libitm/eh_cpp.cc index 7d570e74fc2..6c9da2d06e4 100644 --- a/libitm/eh_cpp.cc +++ b/libitm/eh_cpp.cc @@ -87,23 +87,23 @@ struct __cxa_eh_globals unsigned int uncaughtExceptions; }; -extern void *__cxa_allocate_exception (size_t) WEAK; -extern void __cxa_free_exception (void *) WEAK; +extern void *__cxa_allocate_exception (size_t) _ITM_NOTHROW WEAK; +extern void __cxa_free_exception (void *) _ITM_NOTHROW WEAK; extern void __cxa_throw (void *, void *, void (*) (void *)) WEAK; -extern void *__cxa_begin_catch (void *) WEAK; +extern void *__cxa_begin_catch (void *) _ITM_NOTHROW WEAK; extern void __cxa_end_catch (void) WEAK; -extern void __cxa_tm_cleanup (void *, void *, unsigned int) WEAK; -extern __cxa_eh_globals *__cxa_get_globals (void) WEAK; +extern void __cxa_tm_cleanup (void *, void *, unsigned int) throw () WEAK; +extern __cxa_eh_globals *__cxa_get_globals (void) _ITM_NOTHROW WEAK; #if !defined (HAVE_ELF_STYLE_WEAKREF) -void *__cxa_allocate_exception (size_t) { return NULL; } -void __cxa_free_exception (void *) { return; } +void *__cxa_allocate_exception (size_t) _ITM_NOTHROW { return NULL; } +void __cxa_free_exception (void *) _ITM_NOTHROW { return; } void __cxa_throw (void *, void *, void (*) (void *)) { return; } -void *__cxa_begin_catch (void *) { return NULL; } +void *__cxa_begin_catch (void *) _ITM_NOTHROW { return NULL; } void __cxa_end_catch (void) { return; } -void __cxa_tm_cleanup (void *, void *, unsigned int) { return; } +void __cxa_tm_cleanup (void *, void *, unsigned int) throw () { return; } void _Unwind_DeleteException (_Unwind_Exception *) { return; } -__cxa_eh_globals *__cxa_get_globals (void) { return NULL; } +__cxa_eh_globals *__cxa_get_globals (void) _ITM_NOTHROW { return NULL; } #endif /* HAVE_ELF_STYLE_WEAKREF */ } @@ -117,7 +117,7 @@ free_any_exception (void *exc_ptr) } void * -_ITM_cxa_allocate_exception (size_t size) +_ITM_cxa_allocate_exception (size_t size) _ITM_NOTHROW { void *r = __cxa_allocate_exception (size); gtm_thr()->record_allocation (r, free_any_exception); @@ -125,7 +125,7 @@ _ITM_cxa_allocate_exception (size_t size) } void -_ITM_cxa_free_exception (void *exc_ptr) +_ITM_cxa_free_exception (void *exc_ptr) _ITM_NOTHROW { // __cxa_free_exception can be called from user code directly if // construction of an exception object throws another exception, in which @@ -143,7 +143,7 @@ _ITM_cxa_throw (void *obj, void *tinfo, void (*dest) (void *)) } void * -_ITM_cxa_begin_catch (void *exc_ptr) +_ITM_cxa_begin_catch (void *exc_ptr) _ITM_NOTHROW { // If this exception object has been allocated by this transaction, we // discard the undo log entry for the allocation; we are entering phase (3) diff --git a/libitm/libitm.h b/libitm/libitm.h index 69f551e2675..4f8051bdfb7 100644 --- a/libitm/libitm.h +++ b/libitm/libitm.h @@ -45,6 +45,15 @@ extern "C" { #define ITM_NORETURN __attribute__((noreturn)) #define ITM_PURE __attribute__((transaction_pure)) +#ifdef _GLIBCXX_NOTHROW +# define _ITM_NOTHROW _GLIBCXX_NOTHROW +#elif !defined (__cplusplus) +# define _ITM_NOTHROW __attribute__((__nothrow__)) +#elif __cplusplus < 201103L +# define _ITM_NOTHROW throw () +#else +# define _ITM_NOTHROW noexcept +#endif /* The following are externally visible definitions and functions, though only very few of these should be called by user code. */ @@ -282,11 +291,11 @@ extern void *_ITM_getTMCloneSafe (void *) ITM_REGPARM; extern void _ITM_registerTMCloneTable (void *, size_t); extern void _ITM_deregisterTMCloneTable (void *); -extern void *_ITM_cxa_allocate_exception (size_t); -extern void _ITM_cxa_free_exception (void *exc_ptr); +extern void *_ITM_cxa_allocate_exception (size_t) _ITM_NOTHROW; +extern void _ITM_cxa_free_exception (void *exc_ptr) _ITM_NOTHROW; extern void _ITM_cxa_throw (void *obj, void *tinfo, void (*dest) (void *)); -extern void *_ITM_cxa_begin_catch (void *exc_ptr); -extern void _ITM_cxa_end_catch (void); +extern void *_ITM_cxa_begin_catch (void *exc_ptr) _ITM_NOTHROW; +extern void _ITM_cxa_end_catch (void); /* This can throw. */ extern void _ITM_commitTransactionEH(void *exc_ptr) ITM_REGPARM; #ifdef __cplusplus