From patchwork Tue Feb 28 00:16:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 62204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2719472wrd; Mon, 27 Feb 2023 16:17:02 -0800 (PST) X-Google-Smtp-Source: AK7set+Ky1+ZdQDi3h9sSHIiFJ9Wcc6etlcTH/UuDcNh5qcWQsEwnQ1Ruqtrro1I4+ne5eIx9JnG X-Received: by 2002:a17:906:1246:b0:8b1:7eb7:d53d with SMTP id u6-20020a170906124600b008b17eb7d53dmr586341eja.49.1677543422047; Mon, 27 Feb 2023 16:17:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677543422; cv=none; d=google.com; s=arc-20160816; b=jAzFgfik330SCud1aCWccl+sfBQ0AL/NrAJaomC1sb5R+kghycW+195h7s7dcl5jAA NU7OW90UXvvVItYxoGXmsJsKkCWzB95e8fQf4EzxK1w53XnFC42d1fJcwNM7BSfq1wEP 8daXwHN9WWB7R6q6ffX9UP7hIvZsqYk4kDeVkgxUPlQrnUf4GFHROUgjdgjZv6tDcIy6 P1j0SrHHDovpXCnW2GpPlRlagGXdkWKe1oubPJolhMWLS7DBnHOMnt0IvodfCEfLhY4w hsIoHNjF76/0B04W4mIx2NwytzBwSmpIBoD29YyvxEvQa816Wk55grmuMfjo76WLZCDt +YOA== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=hpRw0rT5P3te4mvRJqdqF0z5abH2vTWnqiTEvpXjQ/s=; b=EA2XKl1wBmHl3kEmrwNPzC0omWgHnLNEi9UNYOjnrvfC/+k9DMbBLSuhC4b6xGicvK +lDE8kMu7kgZp4n6XTSWaBveHZXNdo20RBAzpcDYiv3/9PcXOkdrea/4McVkTvHN8UrE 76PKc7k6Fyv+62YDAhkSlp9IVmK5T+6ONJzuKRCBRHpQe857GOB1tBqWgbTtPo2zeccG ECKyUy0GM4O2848VDIgoYRKVFX78+jjEJDjhwHoq810m86PTPQOO1NcHuXbechovnrnZ 4kLrrHwRyCG33CTYnS+I0/vfQkObiZQcmHaEizaTH82+uH+/hBTIcqAHyiWAcY9bm3+n BIbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=cj+9q9Vp; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g5-20020a170906348500b008de4a641fe0si9153350ejb.938.2023.02.27.16.17.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 16:17:02 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=cj+9q9Vp; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1FB6D3858C62 for ; Tue, 28 Feb 2023 00:17:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1FB6D3858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677543421; bh=hpRw0rT5P3te4mvRJqdqF0z5abH2vTWnqiTEvpXjQ/s=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=cj+9q9VprC51X0PYs20YtNj6F+5eI1ojefp/r7aECp2oXTzXBi8GUcrQo0ZM8mzeR aElpGiKxqPSvXmC4xvXm/GfevJxko6GF827UmRTgBcBHgZHIKadeKqrnnKcCiiN+dT 6M64RzACbPHY85XkOHTim9R3ehJGPHxiodLUUPXk= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 7AA5E3858C53 for ; Tue, 28 Feb 2023 00:16:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AA5E3858C53 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 839C01FDA7 for ; Tue, 28 Feb 2023 00:16:26 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7075713582 for ; Tue, 28 Feb 2023 00:16:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +N1VGtpH/WPNdgAAMHmgww (envelope-from ) for ; Tue, 28 Feb 2023 00:16:26 +0000 To: binutils@sourceware.org Subject: [PATCH v2 3/3] gas: Add --compress-debug-sections={heuristic-always, heuristic-sizewin} Date: Tue, 28 Feb 2023 01:16:33 +0100 Message-Id: <20230228001633.3602-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230228001633.3602-1-tdevries@suse.de> References: <20230228001633.3602-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Binutils From: Tom de Vries Reply-To: Tom de Vries Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759031771446446845?= X-GMAIL-MSGID: =?utf-8?q?1759031771446446845?= Gas has an option --compress-debug-sections that allows it to generate compressed debug sections. That does not guarantee that the debug sections are in fact compressed: ... $ gcc hello.c -Wa,-gdwarf-5 -c -Wa,--compress-debug-sections=zstd $ readelf -S -W hello.o | grep " .debug" [ 9] .debug_line PROGBITS 0000a8 000053 00 0 0 1 [11] .debug_line_str PROGBITS 0000fb 000025 01 MS 0 0 1 [12] .debug_info PROGBITS 000120 000039 00 0 0 1 [14] .debug_abbrev PROGBITS 000159 000028 00 0 0 1 [15] .debug_aranges PROGBITS 000190 000030 00 0 0 16 [17] .debug_str PROGBITS 0001c0 000039 01 MS 0 0 1 ... Sensibly so, they're only compressed if that provides a size benefit. However, for the purpose of testing components consuming dwarf we may want the sections to be compressed regardless. Add a new suboption --compress-debug-sections=heuristic-always that ignores the size heuristic, such that we have instead: ... $ gcc hello.c -Wa,-gdwarf-5 -c -Xassembler \ --compress-debug-sections=zstd,heuristic-always $ readelf -S -W hello.o | grep " .debug" [ 9] .debug_line PROGBITS 0000a8 000064 00 C 0 0 8 [11] .debug_line_str PROGBITS 000110 000046 01 MSC 0 0 8 [12] .debug_info PROGBITS 000158 000046 00 C 0 0 8 [14] .debug_abbrev PROGBITS 0001a0 000049 00 C 0 0 8 [15] .debug_aranges PROGBITS 0001f0 000034 00 C 0 0 8 [17] .debug_str PROGBITS 000228 00005a 01 MSC 0 0 8 ... Also add an option --compress-debug-sections=heuristic-sizewin that represents the current default. Advertised as: ... $ as --help ... --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi|zstd|heuristic-always|heuristic-sizewin}] compress DWARF debug sections Default: zlib ... Tested on x86_64-linux. --- gas/as.c | 16 +++++++++++++++- gas/as.h | 8 ++++++++ gas/write.c | 7 +++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/gas/as.c b/gas/as.c index c159c5d0d0a..a766f864707 100644 --- a/gas/as.c +++ b/gas/as.c @@ -230,6 +230,8 @@ enum compressed_debug_section_type flag_compress_debug = DEFAULT_COMPRESSED_DEBUG_ALGORITHM; #endif +enum compress_debug_heuristic compress_debug_heuristic = cdh_sizewin; + static void show_usage (FILE * stream) { @@ -252,7 +254,7 @@ Options:\n\ fprintf (stream, _("\ --alternate initially turn on alternate macro syntax\n")); fprintf (stream, _("\ - --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi|zstd}]\n\ + --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi|zstd|heuristic-sizewin|heuristic-always}]\n\ compress DWARF debug sections\n")), fprintf (stream, _("\ Default: %s\n"), @@ -423,6 +425,18 @@ parse_compress_debug_optarg_1 (const char *optarg) { gas_assert (optarg != NULL); + if (strcmp (optarg, "heuristic-sizewin") == 0) + { + compress_debug_heuristic = cdh_sizewin; + return; + } + + if (strcmp (optarg, "heuristic-always") == 0) + { + compress_debug_heuristic = cdh_always; + return; + } + enum compressed_debug_section_type tmp = bfd_get_compression_algorithm (optarg); diff --git a/gas/as.h b/gas/as.h index 4c5fa9ecf7d..cd852500197 100644 --- a/gas/as.h +++ b/gas/as.h @@ -331,6 +331,14 @@ COMMON int flag_traditional_format; /* Type of compressed debug sections we should generate. */ COMMON enum compressed_debug_section_type flag_compress_debug; +/* Debug sections compression heuristics. */ +enum compress_debug_heuristic +{ + cdh_sizewin, + cdh_always +}; +COMMON enum compress_debug_heuristic compress_debug_heuristic; + /* TRUE if .note.GNU-stack section with SEC_CODE should be created */ COMMON int flag_execstack; diff --git a/gas/write.c b/gas/write.c index 8273b7a42f1..34ea5746284 100644 --- a/gas/write.c +++ b/gas/write.c @@ -1463,9 +1463,11 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) segment_info_type *seginfo = seg_info (sec); bfd_size_type uncompressed_size = sec->size; flagword flags = bfd_section_flags (sec); + bool compress_debug_heuristic_sizewin + = compress_debug_heuristic == cdh_sizewin; if (seginfo == NULL - || uncompressed_size < 32 + || (compress_debug_heuristic_sizewin && uncompressed_size < 32) || (flags & SEC_HAS_CONTENTS) == 0) return; @@ -1582,7 +1584,8 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) /* PR binutils/18087: If compression didn't make the section smaller, just keep it uncompressed. */ - if (compressed_size >= uncompressed_size) + if (compress_debug_heuristic_sizewin + && compressed_size >= uncompressed_size) return; /* Replace the uncompressed frag list with the compressed frag list. */