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: