From patchwork Wed Nov 17 17:17:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 47838 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 720A53858033 for ; Wed, 17 Nov 2021 17:17:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 720A53858033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637169477; bh=GigbYuyikP4mMqCH3nFAalMnCPeYyzFodWUDA9Fy51Q=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=JEoyKw7fID+bP9ygLWf+p8TdBIZASFsUH4Ra4utaMtPAbMAUamBwLLsjFDD8Aneog hpJTbmABhxvBbDeaNGoDVYn+NCcrUQKNxwDg1b5rf6UuHf1cmk348u38RQEqP9x17P bwCp3OkEkQx4ba1S6TlDAWvXnNv0tfDHtrLtUURg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 4A2A43858D28 for ; Wed, 17 Nov 2021 17:17:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4A2A43858D28 Received: by mail-wm1-x329.google.com with SMTP id z200so2918121wmc.1 for ; Wed, 17 Nov 2021 09:17:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :mime-version:content-transfer-encoding; bh=GigbYuyikP4mMqCH3nFAalMnCPeYyzFodWUDA9Fy51Q=; b=kd4OAg+kCp00LI9DRFJNAfIs/eYBQw/IqQ7pq0vmdgsKGBNiB/t4LojCNRDBgelpLX BO4VOMpAkDJjN3xEwudyHHgJl49skemq6wzh8tDMDELDRtUqqaZf02HGJA7BBFc3ZKQc JodObpcKUaDkZ6fayscVZAlGKQpNl9rEVtGJkeFPjS2Y+a2QmnhieqZsL3HQBxkxIdOf x0Wu96vC6gkVFvSjTDzBd5iPKHa0uSLZW1APA9J2S0jYbj7gPjmXXrxnkUKeNrBUDAnH j43N2EwKW74smXOdp/KBCmBmC7RnGmVF645ppfp9vKH9nH4cCGsqmiasxATySK5btLq1 hHUw== X-Gm-Message-State: AOAM532qj21/JOKeJEYM1bAf9A5WRMz81tsmUDrrhmz33LxCYSL9xPq+ USrbdbxzs36vn4pRE+RBX4mIbFPB74c= X-Google-Smtp-Source: ABdhPJxwztFrE6Y4GThytTA6Hr5sZJCy0TR4J+OeCTJ1ADHcmoeYfbGU1lx5KH1IHYRej8wA/+G6fg== X-Received: by 2002:a05:600c:1d1b:: with SMTP id l27mr1321494wms.1.1637169445901; Wed, 17 Nov 2021 09:17:25 -0800 (PST) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id i17sm345860wmq.48.2021.11.17.09.17.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Nov 2021 09:17:25 -0800 (PST) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] DWARF: Match behaviour of .cfi_xxx when doing manual frame output. Date: Wed, 17 Nov 2021 17:17:18 +0000 Message-Id: <20211117171718.59536-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe , jakub@redhat.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" At present, for several reasons, it is not possible to switch Darwin to use .cfi instructions for frame output. When GCC uses .cfi_ instructions, the behaviour w.r.t frame sections (for a target with unwind frames by defaults): (no options ) .eh_frame (-g ) .eh_frame (-g -fno-unwind-tables -fno-asynchronous-unwind-tables) .debug_frame ( -fno-unwind-tables -fno-asynchronous-unwind-tables) --- However, for a target which outputs the FDEs "manually" (using output_call_frame_info()) we have: (no options ) __eh_frame (-g ) __eh_frame *and* __debug_frame (-g -fno-unwind-tables -fno-asynchronous-unwind-tables) __debug_frame ( -fno-unwind-tables -fno-asynchronous-unwind-tables) --- The first two cases are, of course, the most common and the extra frame table is (a) a waste of space and (b) actually triggers a bug when used with the LLVM assembler [with assertions enabled] for Mach-O when we have hot/cold partitioning on, since that emits Letext{.cold}0 labels *after* the __DWARF,__debug_frame and the assembler is set up reject switches to non-debug sections after the first __DWARF debug one has been seen. The following patch makes the manual output of frame data follow the same pattern as the .cfi instructions. (a) From testing on Darwin which uses the 'manual frame output' I see around 200Mb saving on gcc/ for master (5%). (b) Since Darwin defaults to unwind frames for all languages, we see only eh_frame sections before the "real debug" is emitted, so that the LLVM constraint is avoided. On testing on x86_64 and powerpc64le Linux, I see only a single test that would need amendment (it counts the number of references to the start/end local labels). Since the majority of targets are using .cfi instructions, it is hard to get wider testing. It would be possible, of course, to wrap the change in a target hook but it's not clear that we need to. Is there some case that I've missed? or - OK for master (the testcase amendments are not attached here) but are simple. thanks, Iain Signed-off-by: Iain Sandoe gcc/ChangeLog: * dwarf2out.c (output_call_frame_info): Output the FDEs when either EH or debug support is needed. (dwarf2out_frame_finish): When either EH or debug support is needed, call output_call_frame_info(). --- gcc/dwarf2out.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index e1d6a79ecd7..96307d6747a 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -283,7 +283,7 @@ static GTY(()) dw_die_ref decltype_auto_die; /* Forward declarations for functions defined in this file. */ -static void output_call_frame_info (int); +static void output_call_frame_info (bool, bool); /* Personality decl of current unit. Used only when assembler does not support personality CFI. */ @@ -750,7 +750,7 @@ fde_needed_for_eh_p (dw_fde_ref fde) location of saved registers. */ static void -output_call_frame_info (int for_eh) +output_call_frame_info (bool for_eh, bool for_debug) { unsigned int i; dw_fde_ref fde; @@ -795,7 +795,7 @@ output_call_frame_info (int for_eh) targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1); } - if (!any_eh_needed) + if (!any_eh_needed && !for_debug) return; } @@ -1271,12 +1271,9 @@ void dwarf2out_frame_finish (void) { /* Output call frame information. */ - if (targetm.debug_unwind_info () == UI_DWARF2) - output_call_frame_info (0); - - /* Output another copy for the unwinder. */ - if (do_eh_frame) - output_call_frame_info (1); + if (targetm.debug_unwind_info () == UI_DWARF2 || do_eh_frame) + output_call_frame_info (do_eh_frame, + targetm.debug_unwind_info () == UI_DWARF2); } static void var_location_switch_text_section (void);