From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677543386; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=xi2L0zkSyTO14N2rA5qWSLxj9sVztA2BU19ZU5oAWac=; b=Gw6VCCZdY556cv0ZEGkckmQVw2YSBzOn5VFOtDVeZhwE3bBf64ue16bt7aRTcV5MkQoyIb K4X6ffKXTEZoiwMYkM05JCReL/9LHlvRFgiIPRr7G9HYaPfre0yESyD2bkfIyMhy9c4iiJ hv6AhFTR5ZczklGfXbxfWYjYoz8Buek= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677543386; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=xi2L0zkSyTO14N2rA5qWSLxj9sVztA2BU19ZU5oAWac=; b=ZTccxXLDJIxwkoKVAqABUWp6gTqU1XdqpVieF93JzRvPAHfoIv7BLLXmjBRwwkeiHurn3n I7lGgDE4X0q2G9Cg== 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 From: Tom de Vries 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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(-) 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: base-commit: d273049e140ef324be2b018e235ae0ba8021a769 -- 2.35.3