From patchwork Tue Feb 28 00:16:31 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: 62205 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2719604wrd; Mon, 27 Feb 2023 16:17:22 -0800 (PST) X-Google-Smtp-Source: AK7set+XzdJak6DaUsOG/sdZYyzFcAh2sOXelb4xOams31pP5IKlh9+/kzZN13irIunBivCAuXnH X-Received: by 2002:a17:906:5dad:b0:881:d1ad:1640 with SMTP id n13-20020a1709065dad00b00881d1ad1640mr829570ejv.57.1677543442099; Mon, 27 Feb 2023 16:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677543442; cv=none; d=google.com; s=arc-20160816; b=YZ44VLdEDUZFcZpvw53DOONUJgAxqqhwExJZAlI8iIE8NDHfo7obcBJAcQrs1g0xWR xd6EW27YEI/YbLOB3rYPjdjmHu9tfmr9koNapFHvnDJaykNIE3Wl+/XgkozdS2vF3fXY 00Y8mpza8l7msSfKuDhVvTyqHbBfGUuCENT5w0yPQqhDzh2b5Fhl2uHdbnwwk44oPtsn FwnHG7Pvefhl9ggN0MhCrsrm2f/Pwqi2Na7s/7uVEni7mQt6fzmR7LBDXVx4Tqs8jsvU QxZyA1aZmXV+2Rv6qtJMzJUPRonoNJSDqX1XKP3qJfKam7nj+6uXojAKTjofdkcCz+mb mmfQ== 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:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xi2L0zkSyTO14N2rA5qWSLxj9sVztA2BU19ZU5oAWac=; b=ZvFNr/qcWyTBVJge2rmwe7ITg42bh6OF6ppMgrkb/d7GAYqjB+woYYobaXkPMaxJKf ZlrWcf3oa3VbyNyygHv8T6vr38jMdpxHpF34v8Sa8Ofx3+ulVlo6T4kCd8EqdYtskIzN QYEWcDU2tkCu+8HLuJ+XsjYBsd0oL609YURKg2pTbcanldBXkkI2MXQ0H7Z/2VIXGsGV ASaGwAzx7XI4fBOrDUm+ZsQ8Ps4rEEE4/qP69qeimr0XjIzbIWBwU7IUUiv+YiGF+8JI DUO54ubZDJDanYeLgok6m6pHUHsqy6krscuhvD/guMMwJ4Ng6yPIWUXlOPL1edrkOcyO ny0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=vzZG7cXa; 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 d14-20020a170906c20e00b008c9c6ba8ac5si7621397ejz.840.2023.02.27.16.17.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 16:17:22 -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=vzZG7cXa; 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 154433858426 for ; Tue, 28 Feb 2023 00:17:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 154433858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677543441; bh=xi2L0zkSyTO14N2rA5qWSLxj9sVztA2BU19ZU5oAWac=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vzZG7cXaS18qg3jl2x7sz6+fy7Q3QYRI9PDxRA8zSbuWTubXCNhkMfPYXzgdpH3cf 8tYRR1HqrgGDl8X8ka2V7Vh3S0KvSG1e6/VCz6owv822obuCecl/LjR9sx+CO1hKbr VYjxAlMvkoLseWyzTeI0sIHVy2xeGiJWlJM0mZ90= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 2235A3858D3C for ; Tue, 28 Feb 2023 00:16:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2235A3858D3C 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-out1.suse.de (Postfix) with ESMTPS id 5366B21A3C 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 3F38313582 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 ltMJDdpH/WPNdgAAMHmgww (envelope-from ) for ; Tue, 28 Feb 2023 00:16:26 +0000 To: binutils@sourceware.org Subject: [PATCH v2 1/3] gas: Unify parsing of --compress-debug-sections Date: Tue, 28 Feb 2023 01:16:31 +0100 Message-Id: <20230228001633.3602-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 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?1759031792225169379?= X-GMAIL-MSGID: =?utf-8?q?1759031792225169379?= There are three related option forms: * --compress-debug-sections= * --compress-debug-sections * --nocompress-debug-sections where the last two are documented as being equivalent to: * --compress-debug-section=zlib-gabi * --compress-debug-section=none However, the three related option forms are handled independently in parse_args, and there are minor differences in handling. For instance, in case !defined OBJ_ELF && !defined OBJ_MAYBE_ELF, using --compress-debug-section=zlib-gabi or --compress-debug-section=none will trigger as_fatal ("--compress-debug-sections=%s is unsupported"), while that's not the case for --compress-debug-sections and --nocompress-debug-sections. Fix this by: - factoring out a new function parse_compress_debug_optarg, and - using it to handle all three options forms. Also make the code easier to read by not nesting preprocessor conditionals. --- gas/as.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) base-commit: d273049e140ef324be2b018e235ae0ba8021a769 diff --git a/gas/as.c b/gas/as.c index 598bfd56cf5..40742b13511 100644 --- a/gas/as.c +++ b/gas/as.c @@ -418,6 +418,32 @@ Options:\n\ fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO); } +static void +parse_compress_debug_optarg (const char *optarg) +{ +#if !defined OBJ_ELF && !defined OBJ_MAYBE_ELF + as_fatal (_("--compress-debug-sections=%s is unsupported"), + optarg); +#endif + + gas_assert (optarg != NULL); + + enum compressed_debug_section_type tmp + = bfd_get_compression_algorithm (optarg); + +#ifndef HAVE_ZSTD + if (tmp == COMPRESS_DEBUG_ZSTD) + as_fatal (_ ("--compress-debug-sections=zstd: gas is not " + "built with zstd support")); +#endif + + if (tmp == COMPRESS_UNKNOWN) + as_fatal (_("Invalid --compress-debug-sections option: `%s'"), + optarg); + + flag_compress_debug = tmp; +} + /* Since it is easy to do here we interpret the special arg "-" to mean "use stdin" and we set that argv[] pointing to "". After we have munged argv[], the only things left are source file @@ -747,28 +773,13 @@ This program has absolutely no warranty.\n")); case OPTION_COMPRESS_DEBUG: if (optarg) - { -#if defined OBJ_ELF || defined OBJ_MAYBE_ELF - flag_compress_debug = bfd_get_compression_algorithm (optarg); -#ifndef HAVE_ZSTD - if (flag_compress_debug == COMPRESS_DEBUG_ZSTD) - as_fatal (_ ("--compress-debug-sections=zstd: gas is not " - "built with zstd support")); -#endif - if (flag_compress_debug == COMPRESS_UNKNOWN) - as_fatal (_("Invalid --compress-debug-sections option: `%s'"), - optarg); -#else - as_fatal (_("--compress-debug-sections=%s is unsupported"), - optarg); -#endif - } + parse_compress_debug_optarg (optarg); else - flag_compress_debug = COMPRESS_DEBUG_GABI_ZLIB; + parse_compress_debug_optarg ("zlib-gabi"); break; case OPTION_NOCOMPRESS_DEBUG: - flag_compress_debug = COMPRESS_DEBUG_NONE; + parse_compress_debug_optarg ("none"); break; case OPTION_DEBUG_PREFIX_MAP: From patchwork Tue Feb 28 00:16:32 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: 62206 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2719622wrd; Mon, 27 Feb 2023 16:17:23 -0800 (PST) X-Google-Smtp-Source: AK7set/n9cSeZuWoBmcy52EvhJC8acS35MVHPtiVNsDkJUB7ex9OCa/ZGFenT0LuV6mD1hLCRmaK X-Received: by 2002:a05:6402:322:b0:4ac:b4f3:b8a7 with SMTP id q2-20020a056402032200b004acb4f3b8a7mr1321685edw.7.1677543443680; Mon, 27 Feb 2023 16:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677543443; cv=none; d=google.com; s=arc-20160816; b=DL0lZDYmf5b9JjloadK+UHZyV1Xj17NiJzux2+V2DHkJn8q8CnX6ZLdlASLh/2/Z2s f84rrRr42bQHCtzMAaR/ZydlQIsLy2rv+l5ChHve9sJFYqLsJSri93W9BZZ2K/NMbbYG ndLeA1qaP8DB9pt8t+QeCHA/v7q4Ep0aENCQI7vRjwT+icyRfuRsxDiNm5G8vE6wj3qC Xr2mGuWHWwuRHtHs7GDZWuPHHnZrdskI6n445GMf8wgsnvcZvAY8XN7S866yuPGUu114 QPH66LnoX6ws4b4n+LDz/b0h94lc+ujrg5DPcEPhypg9RB9Tz+3t6dfF+HvP7azXkxG9 /zrA== 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=WlbxrzzUMoTfXOFm/I402mUnHFtTN/OJyB6e0BZtABs=; b=bia+eJvepSlWXvqrGBreEu/x1EfnPpuSO4WkZx/gXNSqqJazwymvanf0Fyw83Oj6NH 9+3PdvJlpMKfq6ctm4s6JU4lFdhWGz+KsxL/Gn9yc7QADDZCZeVRQc6lrrUWmBfrqvAZ IA/v0/hgVXu3ftGQKNP2fV8xdkvLBoBZLbSJbaaIYqTxw/qUDN/42E3xBD6j8X52lk8X pTQOZUpAMpny9NP1QZZtoP80LxtQ4u0vTH8W8eg0GmBk69asNZbcpsFJRE8XmhZLc8JA KJrLZkJh3yDCeeGDUrKsOnRIjpe7lDi3CU1ESakzkgaeyQk3scDJrJqu+/PDe56VkdAP RiMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=OKpzQYan; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i7-20020aa7c707000000b004aef1baf38asi9905196edq.96.2023.02.27.16.17.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 16:17:23 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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=@sourceware.org header.s=default header.b=OKpzQYan; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 8842A3858296 for ; Tue, 28 Feb 2023 00:17:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8842A3858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677543441; bh=WlbxrzzUMoTfXOFm/I402mUnHFtTN/OJyB6e0BZtABs=; 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=OKpzQYanvJJdtwYXAk85CD52smENV7+UdKARCH0YX4TpNo5IDfgF5DLUlkE+Pvqeh E+BLapRv4y3zbWSYao54zZaQnvGFyyFceKm6r1scKnZZ6nv8oskuTerEWdNuyq8wfl UgFD3ncaAP8DDhPz6bBA5j6Vg8pRqhEi6VK9rSF0= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 35EB63858C52 for ; Tue, 28 Feb 2023 00:16:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35EB63858C52 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-out1.suse.de (Postfix) with ESMTPS id 6CA3821A3D 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 57C6513912 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 SCxPFNpH/WPNdgAAMHmgww (envelope-from ) for ; Tue, 28 Feb 2023 00:16:26 +0000 To: binutils@sourceware.org Subject: [PATCH v2 2/3] gas: Handle --compress-debug-sections=subopt1,subopt2 Date: Tue, 28 Feb 2023 01:16:32 +0100 Message-Id: <20230228001633.3602-2-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.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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?1759031793930427533?= X-GMAIL-MSGID: =?utf-8?q?1759031793930427533?= Add the possibility to specify more than one --compress-debug-sections subopt at a time, using a comma separator. Using --compress-debug-sections=subopt1,subopt2 is equivalent to using --compress-debug-sections=subopt1 --compress-debug-sections=subopt2. --- gas/as.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/gas/as.c b/gas/as.c index 40742b13511..c159c5d0d0a 100644 --- a/gas/as.c +++ b/gas/as.c @@ -419,13 +419,8 @@ Options:\n\ } static void -parse_compress_debug_optarg (const char *optarg) +parse_compress_debug_optarg_1 (const char *optarg) { -#if !defined OBJ_ELF && !defined OBJ_MAYBE_ELF - as_fatal (_("--compress-debug-sections=%s is unsupported"), - optarg); -#endif - gas_assert (optarg != NULL); enum compressed_debug_section_type tmp @@ -444,6 +439,45 @@ parse_compress_debug_optarg (const char *optarg) flag_compress_debug = tmp; } +static void +parse_compress_debug_optarg (const char *optarg) +{ +#if !defined OBJ_ELF && !defined OBJ_MAYBE_ELF + as_fatal (_("--compress-debug-sections=%s is unsupported"), + optarg); +#endif + + gas_assert (optarg != NULL); + + /* Tokenize subopts pass to parse_compress_debug_optarg_1. */ + char sep = ','; + while (true) + { + const char *idx = optarg; + while (*idx != '\0' && *idx != sep) + idx++; + + size_t len = idx - optarg; + if (len == 0) + { + /* Generate error. */ + parse_compress_debug_optarg_1 (""); + break; + } + + char *tmp = xstrndup (optarg, len); + parse_compress_debug_optarg_1 (tmp); + free (tmp); + + if (*idx == '\0') + break; + + /* Step over separator and continue tokenizing. */ + gas_assert (*idx == sep); + optarg = idx + 1; + } +} + /* Since it is easy to do here we interpret the special arg "-" to mean "use stdin" and we set that argv[] pointing to "". After we have munged argv[], the only things left are source file 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. */