From patchwork Mon Oct 17 09:06:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 3295 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1343927wrs; Mon, 17 Oct 2022 02:07:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4vjphiq+eX9lIdIiuQ0G8uqtix7+zbtaJSyvjZbny4uOaI7BHwXmQXkwP3kI4bNqxIUwR6 X-Received: by 2002:a17:907:9603:b0:742:9ed3:3af2 with SMTP id gb3-20020a170907960300b007429ed33af2mr7867554ejc.510.1665997645995; Mon, 17 Oct 2022 02:07:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665997645; cv=none; d=google.com; s=arc-20160816; b=xGD2yb7oxOmcdGzP6p3qElFtHz6jn4rfhVnKW86LxfORe0T4cnUUeXwKkfu2el7mvX o0jFcxzG0MCb/mRtlLa6dng7LFjml8SA573yxu/vM80XMLiytjfichk/1FPd8v+97gK6 Vs7W1F5sZT069BYSvEA8MlrKJ7rA6sqMlkAAsvHRPad9WUYPS3lXYL3JKrno5xPUDJfN RFdCBn82UWMsLTHyTfc3MVLcTd0EWWNycRqnagRbryYq2dRCEWtigYa17T5dAaegTq0S OkLTK1ByRYMIoV+GeSQwEzeiofU3FvgC+xCIftIQKBm43sNcfuKipebIj12r9+9GbXUP i7Eg== 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:message-id:date:subject:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=9k7yIjZtuqQu4q78Ua8MUPeFt6/1IPxN+vaRQqiNrzI=; b=gdNc3TlanpXqtZ2ydBwR7Z7lp6GbqgV1azN5NRN+JzMPGXUD8YxmyDPL4DIl16X2fz 8uoboq5DADAOMYVydBxvuaEhGLFVAps6g7gfzaX0dIgGO9Ck+VyZHXydrKuu22BqPpbG OdI5MQHyO51I1cw50xHixnUULzBO3D23+QRgwRfIXSOYsCwMcEP1lYukyWCCWbJOm/gt EQ21HrVVgxjryrZv0XZ3YfD3PDtV6a5vpD14tFqFxQ/ipDSIKFvS8xuCIp25txW9WG5/ AkgUFzQNeVoYnyOTrdGoxb3I5Zk51NgUJXK0bxWEeXAdb8SgfUlBQSRjwztC1IIHVI2U 17fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="HS/ypUae"; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id cw10-20020a170906478a00b007314b427e96si10459277ejc.633.2022.10.17.02.07.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 02:07:25 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b="HS/ypUae"; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C258B385828B for ; Mon, 17 Oct 2022 09:07:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C258B385828B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665997644; bh=9k7yIjZtuqQu4q78Ua8MUPeFt6/1IPxN+vaRQqiNrzI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=HS/ypUaexwPUoVl/GbPLln8jsF7n/PSSRcYSy+pdt6rm6NjwTy6XljIqopd1QWFfc 6OKPZKFSMxwo87E6XcYGovCi8nZCuzdI0xhGH/CTicRY+zqtxzVibQWdpEOC9sEcOL MrsNZpzGP727cRotYdR9ihpIr6J4xq4+BcNpeHF8= 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 27C4B3858D28 for ; Mon, 17 Oct 2022 09:06:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 27C4B3858D28 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-248-xdJsDfTAP7KERkLDhXCLCA-1; Mon, 17 Oct 2022 05:06:36 -0400 X-MC-Unique: xdJsDfTAP7KERkLDhXCLCA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 85A5929AA2F1 for ; Mon, 17 Oct 2022 09:06:36 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE6464030C0 for ; Mon, 17 Oct 2022 09:06:34 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libgcc: Special-case BFD ld unwind table encodings in find_fde_tail Date: Mon, 17 Oct 2022 11:06:33 +0200 Message-ID: <87zgdun7ja.fsf@oldenburg.str.redhat.com> 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.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.3 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_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?1746925147919866537?= X-GMAIL-MSGID: =?utf-8?q?1746925147919866537?= BFD ld (and the other linkers) only produce one encoding of these values. It is not necessary to use the general read_encoded_value_with_base decoding routine. This avoids the data-dependent branches in its implementation. libgcc/ * unwind-dw2-fde-dip.c (find_fde_tail): Special-case encoding values actually used by BFD ld. --- libgcc/unwind-dw2-fde-dip.c | 58 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 10 deletions(-) base-commit: de7d6310862c6045cf2dfb0ef209ff0e0923e648 diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c index 7f9be5e6b02..f370c1279ae 100644 --- a/libgcc/unwind-dw2-fde-dip.c +++ b/libgcc/unwind-dw2-fde-dip.c @@ -396,10 +396,21 @@ find_fde_tail (_Unwind_Ptr pc, if (hdr->version != 1) return NULL; - p = read_encoded_value_with_base (hdr->eh_frame_ptr_enc, - base_from_cb_data (hdr->eh_frame_ptr_enc, - dbase), - p, &eh_frame); + if (__builtin_expect (hdr->eh_frame_ptr_enc == (DW_EH_PE_sdata4 + | DW_EH_PE_pcrel), 1)) + { + /* Specialized version of read_encoded_value_with_base, based on what + BFD ld generates. */ + signed value __attribute__ ((mode (SI))); + memcpy (&value, p, sizeof (value)); + p += sizeof (value); + dbase = value; /* No adjustment because pcrel has base 0. */ + } + else + p = read_encoded_value_with_base (hdr->eh_frame_ptr_enc, + base_from_cb_data (hdr->eh_frame_ptr_enc, + dbase), + p, &eh_frame); /* We require here specific table encoding to speed things up. Also, DW_EH_PE_datarel here means using PT_GNU_EH_FRAME start @@ -409,10 +420,20 @@ find_fde_tail (_Unwind_Ptr pc, { _Unwind_Ptr fde_count; - p = read_encoded_value_with_base (hdr->fde_count_enc, - base_from_cb_data (hdr->fde_count_enc, - dbase), - p, &fde_count); + if (__builtin_expect (hdr->fde_count_enc == DW_EH_PE_udata4, 1)) + { + /* Specialized version of read_encoded_value_with_base, based on + what BFD ld generates. */ + unsigned value __attribute__ ((mode (SI))); + memcpy (&value, p, sizeof (value)); + p += sizeof (value); + fde_count = value; + } + else + p = read_encoded_value_with_base (hdr->fde_count_enc, + base_from_cb_data (hdr->fde_count_enc, + dbase), + p, &fde_count); /* Shouldn't happen. */ if (fde_count == 0) return NULL; @@ -454,8 +475,25 @@ find_fde_tail (_Unwind_Ptr pc, f = (fde *) (table[mid].fde + data_base); f_enc = get_fde_encoding (f); f_enc_size = size_of_encoded_value (f_enc); - read_encoded_value_with_base (f_enc & 0x0f, 0, - &f->pc_begin[f_enc_size], &range); + + /* BFD ld uses DW_EH_PE_sdata4 | DW_EH_PE_pcrel on non-FDPIC targets, + so optimize for that. + + This optimization is not valid for FDPIC targets. f_enc & 0x0f as + passed to read_encoded_value_with_base masks away the base flags, + but they are implicit for FDPIC. */ +#ifndef __FDPIC__ + if (__builtin_expect (f_enc == (DW_EH_PE_sdata4 | DW_EH_PE_pcrel), + 1)) + { + signed value __attribute__ ((mode (SI))); + memcpy (&value, &f->pc_begin[f_enc_size], sizeof (value)); + range = value; + } + else +#endif + read_encoded_value_with_base (f_enc & 0x0f, 0, + &f->pc_begin[f_enc_size], &range); _Unwind_Ptr func = table[mid].initial_loc + data_base; if (pc < table[mid].initial_loc + data_base + range) {