From patchwork Tue Nov 8 18:05:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 17149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2865327wru; Tue, 8 Nov 2022 10:07:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM7He8TT6GtdCiJQ8R9JQ0gLfPvtC93wSziab8DHuIfDni19nHsxrA7vCo58ipAARk/XiTw5 X-Received: by 2002:a05:6402:1cc1:b0:453:1517:94e4 with SMTP id ds1-20020a0564021cc100b00453151794e4mr57184374edb.399.1667930859055; Tue, 08 Nov 2022 10:07:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667930859; cv=none; d=google.com; s=arc-20160816; b=TXpkwqRfvHhdE9zpQfOz3QJrOtc2/Ccws4snH5j0I1kAAYGdPISiGGwG3WcQT7ZpLQ VP6V9X8MVftdPyhfUcbDbWSO+IF2zZsgFPIUtDCf7ToFV0TC7Jhmu9O2c2OCyhg7SsBN ffEGOnTsiZvn+XfuxdTL5yKg8us8GIpuq0nMiqg0T6e+ig5R420GWoZ8Z2ZrO/2ubl8W R7bwwGTCqaxXmTvDokgq260gLI06aNywEXwRD9bLqqxZL5fdT7WaW6sWARDUVr0hrl4F ofdB3q5d2Aqb4lrrQ/EuYNUIh7HrKnP4X7jt1H/FPtdWFSU9wV0YIg5fbLeUDcro6axl mBbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:date:message-id:references:in-reply-to:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=G+YCq2UwM0n2qWe9CJOsZX8aOPoR2yUyx/P1s3OJv3g=; b=QimJnJMnaFPfUG58D3xrz6vLt/yoPWnc2/8Szstj1nq+XswN3omuFFqIHMARfk/cyh 5aV6QNsmGMLHX8BcOHBmXEHjmdFBCVKKGFNoUtg4Wg5k7XcZWZnQFM4foxgmLQ0TEo2m CE1mq3YXiHkSqim+7B07rg1PZGzUhlRauDb6hOviEDSif/TqMs+cuxC5oLSoQ/t9kq96 Xt/drckba9r0xccejGy+WkEB7qU3MYrMCSWpzW8aAuC03XNhge5BicW3/4+XAV/ROuHH NvxP7cN+2mSonwJ5gblS41Pw4RBfAJBQKt6ipTpAvtyr83wSqX/bDly5VkpEmN4AjJtY QD6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=u01Htie6; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l6-20020a056402254600b0045a16f47a9fsi14011211edb.624.2022.11.08.10.07.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 10:07:39 -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=@gcc.gnu.org header.s=default header.b=u01Htie6; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A4148385841D for ; Tue, 8 Nov 2022 18:07:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4148385841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667930847; bh=G+YCq2UwM0n2qWe9CJOsZX8aOPoR2yUyx/P1s3OJv3g=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=u01Htie6HBoU/M6OJNLKbrnqCnlim9wlHAPSs/arV0Qvy5OBaIIiV6bMYudxZMoKN uXWwDdOopXJs12/2MAfghxHMBuPS8el6IBkT6vaKWpGsZALyyXWo7GklnOvztNEYkJ raK2fOokafwKKE5c74mjm27Ze45DHV4h2LbTi2rU= 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 C4DB53858432 for ; Tue, 8 Nov 2022 18:05:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C4DB53858432 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-306-_kTpN6D1MsKVsSOyxPNwXg-1; Tue, 08 Nov 2022 13:05:37 -0500 X-MC-Unique: _kTpN6D1MsKVsSOyxPNwXg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 00BDF8027FD for ; Tue, 8 Nov 2022 18:05:33 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D26C112C062 for ; Tue, 8 Nov 2022 18:05:32 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/3] Define __LIBGCC_DWARF_REG_SIZES_CONSTANT__ if DWARF register size is constant In-Reply-To: References: X-From-Line: f08400a5054aadb4fa6e2da62a2768700944b591 Mon Sep 17 00:00:00 2001 Message-Id: Date: Tue, 08 Nov 2022 19:05:30 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-36.1 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Gcc-patches From: Florian Weimer Reply-To: Florian Weimer Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748952268494765635?= X-GMAIL-MSGID: =?utf-8?q?1748952268494765635?= And use that to speed up the libgcc unwinder. * gcc/debug.h (dwarf_reg_sizes_constant): Declare. * gcc/dwarf2cfi.cc (dwarf_reg_sizes_constant): New function. * gcc/c-family/c-cppbuiltin.c (__LIBGCC_DWARF_REG_SIZES_CONSTANT__): Define if constant is known. libgcc/ * unwind-dw2.c (dwarf_reg_size): New function. (_Unwind_GetGR, _Unwind_SetGR, _Unwind_SetGRPtr) (_Unwind_SetSpColumn, uw_install_context_1): Use it. (uw_init_context_1): Do not initialize dwarf_reg_size_table if not in use. --- gcc/c-family/c-cppbuiltin.cc | 6 ++++++ gcc/debug.h | 2 ++ gcc/dwarf2cfi.cc | 23 ++++++++++++++++++++ libgcc/unwind-dw2.c | 41 +++++++++++++++++++++++++----------- 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc index cdb658f6ac9..ab98bf3b059 100644 --- a/gcc/c-family/c-cppbuiltin.cc +++ b/gcc/c-family/c-cppbuiltin.cc @@ -1515,6 +1515,12 @@ c_cpp_builtins (cpp_reader *pfile) #endif builtin_define_with_int_value ("__LIBGCC_DWARF_FRAME_REGISTERS__", DWARF_FRAME_REGISTERS); + { + int value = dwarf_reg_sizes_constant (); + if (value > 0) + builtin_define_with_int_value ("__LIBGCC_DWARF_REG_SIZES_CONSTANT__", + value); + } #ifdef EH_RETURN_STACKADJ_RTX cpp_define (pfile, "__LIBGCC_EH_RETURN_STACKADJ_RTX__"); #endif diff --git a/gcc/debug.h b/gcc/debug.h index fe85115d5f3..6bcc8da1f76 100644 --- a/gcc/debug.h +++ b/gcc/debug.h @@ -245,6 +245,8 @@ extern const struct gcc_debug_hooks vmsdbg_debug_hooks; /* Dwarf2 frame information. */ +extern int dwarf_reg_sizes_constant (); + extern void dwarf2out_begin_prologue (unsigned int, unsigned int, const char *); extern void dwarf2out_vms_end_prologue (unsigned int, const char *); diff --git a/gcc/dwarf2cfi.cc b/gcc/dwarf2cfi.cc index b29173b2156..d45d20478b4 100644 --- a/gcc/dwarf2cfi.cc +++ b/gcc/dwarf2cfi.cc @@ -334,6 +334,29 @@ generate_dwarf_reg_sizes (poly_uint16 *sizes) targetm.init_dwarf_reg_sizes_extra (sizes); } +/* Return 0 if the DWARF register sizes are not constant, otherwise + return the size constant. */ + +int +dwarf_reg_sizes_constant () +{ + poly_uint16 *sizes = XALLOCAVEC (poly_uint16, DWARF_FRAME_REGISTERS); + generate_dwarf_reg_sizes (sizes); + + int result; + for (unsigned int i = 0; i < DWARF_FRAME_REGISTERS; i++) + { + unsigned short value; + if (!sizes[i].is_constant (&value)) + return 0; + if (i == 0) + result = value; + else if (result != value) + return 0; + } + return result; +} + /* Generate code to initialize the dwarf register size table located at the provided ADDRESS. */ diff --git a/libgcc/unwind-dw2.c b/libgcc/unwind-dw2.c index eaceace2029..c370121bb29 100644 --- a/libgcc/unwind-dw2.c +++ b/libgcc/unwind-dw2.c @@ -148,9 +148,25 @@ struct _Unwind_Context char by_value[__LIBGCC_DWARF_FRAME_REGISTERS__+1]; }; +#ifdef __LIBGCC_DWARF_REG_SIZES_CONSTANT__ +static inline unsigned char +dwarf_reg_size (int index __attribute__ ((__unused__))) +{ + return __LIBGCC_DWARF_REG_SIZES_CONSTANT__; +} +#else /* Byte size of every register managed by these routines. */ static unsigned char dwarf_reg_size_table[__LIBGCC_DWARF_FRAME_REGISTERS__+1]; + +static inline unsigned char +dwarf_reg_size (unsigned index) +{ + gcc_assert (index < sizeof (dwarf_reg_size_table)); + return dwarf_reg_size_table[index]; +} +#endif + /* Read unaligned data from the instruction buffer. */ @@ -232,8 +248,7 @@ _Unwind_GetGR (struct _Unwind_Context *context, int regno) #endif index = DWARF_REG_TO_UNWIND_COLUMN (regno); - gcc_assert (index < (int) sizeof(dwarf_reg_size_table)); - size = dwarf_reg_size_table[index]; + size = dwarf_reg_size (index); val = context->reg[index]; if (_Unwind_IsExtendedContext (context) && context->by_value[index]) @@ -280,8 +295,7 @@ _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val) void *ptr; index = DWARF_REG_TO_UNWIND_COLUMN (index); - gcc_assert (index < (int) sizeof(dwarf_reg_size_table)); - size = dwarf_reg_size_table[index]; + size = dwarf_reg_size (index); if (_Unwind_IsExtendedContext (context) && context->by_value[index]) { @@ -329,9 +343,8 @@ _Unwind_SetGRValue (struct _Unwind_Context *context, int index, _Unwind_Word val) { index = DWARF_REG_TO_UNWIND_COLUMN (index); - gcc_assert (index < (int) sizeof(dwarf_reg_size_table)); /* Return column size may be smaller than _Unwind_Context_Reg_Val. */ - gcc_assert (dwarf_reg_size_table[index] <= sizeof (_Unwind_Context_Reg_Val)); + gcc_assert (dwarf_reg_size (index) <= sizeof (_Unwind_Context_Reg_Val)); context->by_value[index] = 1; context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val); @@ -1387,7 +1400,7 @@ static inline void _Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa, _Unwind_SpTmp *tmp_sp) { - int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()]; + int size = dwarf_reg_size (__builtin_dwarf_sp_column ()); if (size == sizeof(_Unwind_Ptr)) tmp_sp->ptr = (_Unwind_Ptr) cfa; @@ -1573,11 +1586,13 @@ uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs) } \ while (0) +#ifndef __LIBGCC_DWARF_REG_SIZES_CONSTANT__ static inline void init_dwarf_reg_size_table (void) { __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table); } +#endif static void __attribute__((noinline)) uw_init_context_1 (struct _Unwind_Context *context, @@ -1596,16 +1611,18 @@ uw_init_context_1 (struct _Unwind_Context *context, code = uw_frame_state_for (context, &fs); gcc_assert (code == _URC_NO_REASON); -#if __GTHREADS +#ifndef __LIBGCC_DWARF_REG_SIZES_CONSTANT__ +# if __GTHREADS { static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT; if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0 && dwarf_reg_size_table[0] == 0) init_dwarf_reg_size_table (); } -#else +# else if (dwarf_reg_size_table[0] == 0) init_dwarf_reg_size_table (); +# endif #endif /* Force the frame state to use the known cfa value. */ @@ -1682,20 +1699,20 @@ uw_install_context_1 (struct _Unwind_Context *current, { _Unwind_Word w; _Unwind_Ptr p; - if (dwarf_reg_size_table[i] == sizeof (_Unwind_Word)) + if (dwarf_reg_size (i) == sizeof (_Unwind_Word)) { w = (_Unwind_Internal_Ptr) t; memcpy (c, &w, sizeof (_Unwind_Word)); } else { - gcc_assert (dwarf_reg_size_table[i] == sizeof (_Unwind_Ptr)); + gcc_assert (dwarf_reg_size (i) == sizeof (_Unwind_Ptr)); p = (_Unwind_Internal_Ptr) t; memcpy (c, &p, sizeof (_Unwind_Ptr)); } } else if (t && c && t != c) - memcpy (c, t, dwarf_reg_size_table[i]); + memcpy (c, t, dwarf_reg_size (i)); } /* If the current frame doesn't have a saved stack pointer, then we