From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 BE1DE3858D1E for ; Tue, 3 Jan 2023 12:05:44 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672747544; 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:in-reply-to:in-reply-to: references:references; bh=+Pcue5tbMhnvOtFVzhufCUpFG4lIRxLsweSPdsty6Eg=; b=SEEAXh/Bm4pnFvUbmiqWMfEvw62Hnswasxbl+XYbJ2oBgov52TN1Gsi1E+5ztCS81umJnm rm5ZnLrFe9Tk7Vp1GZWoEZMbI+9M6TQxvffm5FaDs4UzX97USX+/y+xKd973zPqiY7lmJd g4th8KR3T8FVS+KqFX11SzP5+BRJy38= 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-392--aP6nKjqNJW78kDP1rZWwA-1; Tue, 03 Jan 2023 07:05:37 -0500 X-MC-Unique: -aP6nKjqNJW78kDP1rZWwA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D8F93857D0D; Tue, 3 Jan 2023 12:05:36 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8890140C2064; Tue, 3 Jan 2023 12:05:36 +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 303C5Xlk279885 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 3 Jan 2023 13:05:33 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 303C5WEW279884; Tue, 3 Jan 2023 13:05:32 +0100 Date: Tue, 3 Jan 2023 13:05:32 +0100 From: Jakub Jelinek To: Florian Weimer Cc: gcc-patches@gcc.gnu.org, Andre Vieira , Andrew Pinski , Jeff Law Subject: Re: [PATCH] Various fixes for DWARF register size computation Message-ID: Reply-To: Jakub Jelinek References: <87pmbvx41g.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 In-Reply-To: <87pmbvx41g.fsf@oldenburg.str.redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.5 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_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 List-Id: On Tue, Jan 03, 2023 at 12:15:23PM +0100, Florian Weimer wrote: > --- a/gcc/debug.h > +++ b/gcc/debug.h > @@ -245,7 +245,18 @@ extern const struct gcc_debug_hooks vmsdbg_debug_hooks; > > /* Dwarf2 frame information. */ > > -extern int dwarf_reg_sizes_constant (); > +/* Query size information about DWARF registers. */ > +struct dwarf_single_register_size > +{ > + dwarf_single_register_size(); Formatting, space before ( > @@ -334,27 +333,39 @@ 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 () > +dwarf_single_register_size::dwarf_single_register_size() Likewise. > + for (int i = DWARF_FRAME_REGISTERS; i >= 0; --i) > + { > + unsigned short value; > + if (!sizes[i].is_constant (&value) || value != 0) if (!known_eq (sizes[i], 0)) ? Though, I still wonder, because all of this is a hack for a single target - x86_64-linux -m64 - I think no other target has similar constant sizes, whether it wouldn't be better to revert all this compiler side stuff and handle it purely on the libgcc side - allow target headers to specify a simple expression how to compute dwarf_reg_size + don't define dwarf_reg_size_table array in that case and instead in a testcase verify that __builtin_init_dwarf_reg_size_table initializes an array to the exact same values as the libgcc/config/**/*.h overridden dwarf_reg_size version. That way, for x86_64-linux we can use ((index) <= __LIBGCC_DWARF_FRAME_REGISTERS__ ? 8 : 0) but could provide something reasonable even for other targets if it improves the unwinder sufficiently. Say s390x-linux -m64 is ((index) <= 32 ? 8 : (index) == 33 ? 4 : 0) etc. Or, if you want to do it on the compiler side, instead of predefining __LIBGCC_DWARF_REG_SIZES_CONSTANT__ and __LIBGCC_DWARF_REG_MAXIMUM__ register conditionally a new builtin, __builtin_dwarf_reg_size, which would be defined only if -fbuilding-libgcc and the compiler determines dwarf_reg_size is desirable to be computed inline without a table and would fold the builtin to say that index <= 16U ? 8 : 0 on x86_64 -m64, index <= 9U ? 4 : index - 11U <= 5U ? 12 : 0 on x86_64 -m32 etc. and if the expression is too large/complex, wouldn't predefine the builtin. Then you can #if __has_builtin(__builtin_dwarf_reg_size) use the builtin and don't provide the table + initialize it, otherwise initialize + use the table. Or, is it actually the use of table that is bad on the unwinder side, or lack of a small upper bound for what you get from the table? In that case you could predefine upper bound on the sizes instead (if constant) and simply add if (size > __LIBGCC_DWARF_REG_SIZE_MAX__) __builtin_unreachable ()). Jakub