From patchwork Thu Sep 22 12:51:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp178261wrt; Thu, 22 Sep 2022 05:51:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7zVXGkswfEj0qfHsfbtBJCTloeHGAGBncyQykEfjJMVxLRnIIE8TvpTiR9N2ZxrD2v1eqf X-Received: by 2002:a17:907:168d:b0:782:68d1:f091 with SMTP id hc13-20020a170907168d00b0078268d1f091mr1333326ejc.714.1663851096030; Thu, 22 Sep 2022 05:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663851096; cv=none; d=google.com; s=arc-20160816; b=dZJ4CrlXGF/Fg5iLww/9WQqKAzaS8N+JruHmoIEb6o5l8ax0J9LhdAhHLaTRYTbUC4 lspVN3SchLhJ+kpw3ld4HYNxoAnBstSZ5jBNqlEMqvKb8ZcyqW3XTZTzpg14UJCdWZqv rtiMvMylLOuN7N56xYLES5I12wG7of6rUO7vbjJc4sEhGkhnk13FtVYW2DSssnT8+P2a ItFq/dh6JDpP9TwEhfVSUzIvGjGfP9r08t15JKcQJhvc7o7lLTcZkDjGSV8BSjY7HH3x z5WDyj2Vx3LigwkII3PBiRd50mA70DwVlqoCAl8d6B/vsG/fWK/TLJeU3ylHiZHUmoyD pkdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :in-reply-to:content-language:references:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=+EELO5q3Yz9sFCXVWuA2ix86/Vden50CvYyn5Pn4nWc=; b=zBCmV5wJ0UcU/Bs71qjXnNgVG5TPKVcePWVu8LzkNaNwrhluilUXjZcCEah4lNsTfk HXBvK0JkZxX/3/NIeMnyVhybLfhw1kZvLHarOhk+L+iku/75Xn/Na6+wo/wXKXDJPx6A WE7SE5AnWnNdHm4qR037JKrqsykpzNmuBnn7/05/IIy2VdjEi1NjfsjWr5Uv9ExNq3Jk fJqdyRrdl6qifQp7G6m1wv49+HkwD3u5UkmLFyL2N1eJhAk8C7s89mvjNwVcQBEljiuX wrgbx7IiKHJL9PntyqEbFLr8LJi/u0rJqaAMca9Bx2Sgz3B4PVD3DxaWZfUuFb2rneDU rCdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@suse.cz header.s=susede2_rsa header.b=GTkxbfzW; dkim=neutral (no key) header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a15-20020aa7cf0f000000b004545e78ff0fsi4938589edy.81.2022.09.22.05.51.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 05:51:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.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=fail header.i=@suse.cz header.s=susede2_rsa header.b=GTkxbfzW; dkim=neutral (no key) header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C56F3857B9D for ; Thu, 22 Sep 2022 12:51:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 632443858422 for ; Thu, 22 Sep 2022 12:51:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 632443858422 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz 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 128821F8F9; Thu, 22 Sep 2022 12:51:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1663851066; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+EELO5q3Yz9sFCXVWuA2ix86/Vden50CvYyn5Pn4nWc=; b=GTkxbfzWQU0Hfuyil3cxt0WznKyNCsCeBtD1/2FuLtTc6uQcAlXrECSSSlhd1rohrOBzmT OMgY1CAr95REv6ow404fKbyUKhnZj6Awe+zhCGy5beHeWE0BOjATYL25m0qE88GdaIyoAF G/GL6Zlh2twqrxxg6eV8D2MiUJvjsx8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1663851066; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+EELO5q3Yz9sFCXVWuA2ix86/Vden50CvYyn5Pn4nWc=; b=YWrtmrlENzpn0s/Xfh/sy7ixRcFdffF+YoPrMrml0sKD7DrzQyR9g7y5xhSdOqpxel72zH S6Y/WUXHDHTdcLBw== 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 F19E81346B; Thu, 22 Sep 2022 12:51:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AB/1OTlaLGNWZAAAMHmgww (envelope-from ); Thu, 22 Sep 2022 12:51:05 +0000 Message-ID: <19677278-9d77-d0ab-1257-225f2d33e6cd@suse.cz> Date: Thu, 22 Sep 2022 14:51:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] support -gz=zstd for both linker and assembler To: gcc-patches@gcc.gnu.org References: Content-Language: en-US In-Reply-To: X-Spam-Status: No, score=-11.9 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: 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744674326893514669?= X-GMAIL-MSGID: =?utf-8?q?1744674326893514669?= Hi. Tested with Fangrui's patch set sent to binutils ML and mold linker. $ gcc -g -gz=zstd a.c --save-temps --verbose 2>&1 | grep debug-sections /home/marxin/Programming/binutils/objdir/gas/as-new -v --gdwarf-5 --compress-debug-sections=zstd --64 -o a.o a.s /home/marxin/bin/gcc/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/collect2 -plugin /home/marxin/bin/gcc/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/liblto_plugin.so -plugin-opt=/home/marxin/bin/gcc/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper -plugin-opt=-fresolution=a.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 --compress-debug-sections=zstd /lib/../lib64/crt1.o /lib/../lib64/crti.o /home/marxin/bin/gcc/lib64/gcc/x86_64-pc-linux-gnu/13.0.0/crtbegin.o -L/home/marxin/bin/gcc/lib64/gcc/x86_64-pc-linux-gnu/13.0.0 -L/home/marxin/bin/gcc/lib64/gcc/x86_64-pc-linux-gnu/13.0.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/marxin/bin/gcc/lib64/gcc/x86_64-pc-linux-gnu/13.0.0/../../.. a.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /home/marxin/bin/gcc/lib64/gcc/x86_64-pc-linux-gnu/13.0.0/crtend.o /lib/../lib64/crtn.o $ gdb a.out ... BFD: /home/marxin/Programming/testcases/a.out: unable to initialize decompress status for section .debug_abbrev BFD: /home/marxin/Programming/testcases/a.out: unable to initialize decompress status for section .debug_abbrev "/home/marxin/Programming/testcases/a.out": not in executable format: file format not recognized So it's really compressed with zstd. I'm going to write ChangeLog entry for zlib-gnu once this gets merged as well. Ready to be installed? Thanks, Martin PR driver/106897 gcc/ChangeLog: * common.opt: Add -gz=zstd value. * configure.ac: Detect --compress-debug-sections=zstd for both linker and assembler. * configure: Regenerate. * gcc.cc (LINK_COMPRESS_DEBUG_SPEC): Handle -gz=zstd. (ASM_COMPRESS_DEBUG_SPEC): Likewise. --- gcc/common.opt | 5 ++++- gcc/configure | 11 +++++++++-- gcc/configure.ac | 11 +++++++++-- gcc/gcc.cc | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 06ef768ab78..68370db816b 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -3419,7 +3419,10 @@ EnumValue Enum(compressed_debug_sections) String(zlib) Value(1) EnumValue -Enum(compressed_debug_sections) String(zlib-gnu) Value(2) +Enum(compressed_debug_sections) String(zstd) Value(2) + +EnumValue +Enum(compressed_debug_sections) String(zlib-gnu) Value(3) gz Common Driver diff --git a/gcc/configure b/gcc/configure index 70a013e9a30..ce4e1859e1f 100755 --- a/gcc/configure +++ b/gcc/configure @@ -29727,13 +29727,16 @@ else if $gcc_cv_as --compress-debug-sections -o conftest.o conftest.s 2>&1 | grep -i warning > /dev/null then gcc_cv_as_compress_debug=0 - # Since binutils 2.26, gas supports --compress-debug-sections=zlib, - # defaulting to the ELF gABI format. elif $gcc_cv_as --compress-debug-sections=zlib -o conftest.o conftest.s > /dev/null 2>&1 then gcc_cv_as_compress_debug=1 gcc_cv_as_compress_debug_option="--compress-debug-sections" gcc_cv_as_no_compress_debug_option="--nocompress-debug-sections" + # Since binutils 2.40, gas supports --compress-debug-sections=zstd. + if $gcc_cv_as --compress-debug-sections=zstd -o conftest.o conftest.s > /dev/null 2>&1 + then + gcc_cv_as_compress_debug=2 + fi else gcc_cv_as_compress_debug=0 fi @@ -30251,6 +30254,10 @@ $as_echo_n "checking linker for compressed debug sections... " >&6; } if $gcc_cv_ld --help 2>&1 | grep -- '--compress-debug-sections.*\' > /dev/null; then gcc_cv_ld_compress_debug=1 gcc_cv_ld_compress_debug_option="--compress-debug-sections" + # Detect zstd debug section compression support + if $gcc_cv_ld --help 2>&1 | grep -- '--compress-debug-sections.*\' > /dev/null; then + gcc_cv_ld_compress_debug=2 + fi else case "${target}" in *-*-solaris2*) diff --git a/gcc/configure.ac b/gcc/configure.ac index 96e10d7c194..b6bafa8b7d6 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5732,13 +5732,16 @@ gcc_GAS_CHECK_FEATURE([compressed debug sections], if $gcc_cv_as --compress-debug-sections -o conftest.o conftest.s 2>&1 | grep -i warning > /dev/null then gcc_cv_as_compress_debug=0 - # Since binutils 2.26, gas supports --compress-debug-sections=zlib, - # defaulting to the ELF gABI format. elif $gcc_cv_as --compress-debug-sections=zlib -o conftest.o conftest.s > /dev/null 2>&1 then gcc_cv_as_compress_debug=1 gcc_cv_as_compress_debug_option="--compress-debug-sections" gcc_cv_as_no_compress_debug_option="--nocompress-debug-sections" + # Since binutils 2.40, gas supports --compress-debug-sections=zstd. + if $gcc_cv_as --compress-debug-sections=zstd -o conftest.o conftest.s > /dev/null 2>&1 + then + gcc_cv_as_compress_debug=2 + fi else gcc_cv_as_compress_debug=0 fi]) @@ -6127,6 +6130,10 @@ AC_MSG_CHECKING(linker for compressed debug sections) if $gcc_cv_ld --help 2>&1 | grep -- '--compress-debug-sections.*\' > /dev/null; then gcc_cv_ld_compress_debug=1 gcc_cv_ld_compress_debug_option="--compress-debug-sections" + # Detect zstd debug section compression support + if $gcc_cv_ld --help 2>&1 | grep -- '--compress-debug-sections.*\' > /dev/null; then + gcc_cv_ld_compress_debug=2 + fi else changequote(,)dnl case "${target}" in diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 7578988efa9..2ffbbc0bf2a 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -835,6 +835,14 @@ proper position among the other output files. */ #define LINK_COMPRESS_DEBUG_SPEC \ " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \ " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \ + " %{gz*:%e-gz=zstd is not supported in this configuration} " \ + " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ +#elif HAVE_LD_COMPRESS_DEBUG == 2 +/* ELF gABI style and ZSTD. */ +#define LINK_COMPRESS_DEBUG_SPEC \ + " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \ + " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \ + " %{gz=zstd:" LD_COMPRESS_DEBUG_OPTION "=zstd}" \ " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ #else #error Unknown value for HAVE_LD_COMPRESS_DEBUG. @@ -890,6 +898,13 @@ proper position among the other output files. */ " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \ " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \ " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ +#elif HAVE_AS_COMPRESS_DEBUG == 2 +/* ELF gABI style and ZSTD. */ +#define ASM_COMPRESS_DEBUG_SPEC \ + " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \ + " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \ + " %{gz=zstd:" AS_COMPRESS_DEBUG_OPTION "=zstd}" \ + " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ #else #error Unknown value for HAVE_AS_COMPRESS_DEBUG. #endif