From patchwork Wed Dec 7 05:56:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 30641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1679wrr; Tue, 6 Dec 2022 21:56:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ukWZKPRjITPdmkFm9i0HfPIXh3P3Lm5EBVlh0p6tiDKn6L+jcNi6Tb9k0RyrmBeuSrtZD X-Received: by 2002:aa7:c986:0:b0:46b:b010:3f43 with SMTP id c6-20020aa7c986000000b0046bb0103f43mr27465080edt.215.1670392599729; Tue, 06 Dec 2022 21:56:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670392599; cv=none; d=google.com; s=arc-20160816; b=Ygn7U67eAyHiY7MHWMeeXR111D5mANNYML30o3HmsCNm8Fb/aCucdbJsx2kB26o2FE M+/RNi+JtOpW51VWPb9ZPROiEyZ2W9lf5eE5UrKvWtMqVAEuqJ+vsNyrc8JqYy6h3CpV MpCmUGuDB/t0DkEFWE5kvO0IU2SB7o7U3Q2yNq35PF7AI8g5M6wb7uO5vUlkz7OpxHvX NmOJC4mX64F3gyOF3/purx5/Q/GnlhQUsK1FHWWTRYjFcFugIfSUxtg4OR2ZPpPgRaPJ MFz2eMQiKvdKezDPc5id4x9aOT1l1cODJ3yS61rGYPgEr+vH/jZqAXSlDgLOrPByUIUy dXWQ== 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-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=jnVKZy/AxHxaT+V0GrvMRGa7aJ5rvCnqcBm/UhaGsek=; b=xS8iBpMv1MWg3fMID8VFx4dGrS6cEIiGre8MUAS8Vrs00+D3TDLRHfq9L7Qgtnzj/z UBfyM+x9ozT7bxeQp0THF2u/cEKjL4GvyHfYr9FuUW9RhuXMV4963Perd2H/ngfzJIuY m+38ZXrYl6KJib7cOEQqSV8TAiPQrrAnIHx/536WSC4Xa35nDjdmDWhQrfbK8ug0UUGT 6e0R9yfXtkUdYyYeJZ6lfn/ZWRuVVG2xmpzJcOc6OC1TqaU8tTavJDf0bhBVu2agpWrh aZn8gtzxLf3PphSFzz9HlDW0f53Nuh6fuY8nMzvjRTwWcp/B1QA+gwdESbW6VX2uQF8h QwyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=MIHSa2HN; 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 bt6-20020a0564020a4600b0046c094d9b85si3025332edb.348.2022.12.06.21.56.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 21:56:39 -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=MIHSa2HN; 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 8A72F3835E1A for ; Wed, 7 Dec 2022 05:56:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A72F3835E1A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670392598; bh=jnVKZy/AxHxaT+V0GrvMRGa7aJ5rvCnqcBm/UhaGsek=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MIHSa2HNfZQZxehKCAl/69izPHw+r6BfxlrtEm9aMAoF5ZOb4Jhv1wR6Loq99W9as 8L2c/zKDSKbiH4n2wfT7tQQUdHFGIkIhNmSXrt63qOC2/Yle9PNeT5NrGXkVQ1agcO bKWyfBsJLq04tN7Qc64VpeDp/abIAIAzOrafTtFs= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 65D8C384EF5D for ; Wed, 7 Dec 2022 05:56:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 65D8C384EF5D Received: by mail-pf1-x42a.google.com with SMTP id c13so9511589pfp.5 for ; Tue, 06 Dec 2022 21:56:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jnVKZy/AxHxaT+V0GrvMRGa7aJ5rvCnqcBm/UhaGsek=; b=VmdnnvN5kehT8bcGvWkfISjZlmACgrHtMTR94q8gPRWLGtBPGd/rl514Qgsl1ozyiD 92e9waI/Vcip5V9Iv9s7CsQwehczdsC1lltio0B5S25JuG+pekJ5ThClmsY20mZt4g1x 9IV9PPsOTVdIyaxg+AyFhPIAHn5cgqcZEwC9ZtY3WmtlZv0UJxsZt/wjYk4gt6p8/zo5 M3nZ/EFsp9i0nsG7j0h2oqDY02cYz+CNYKGroR6zJ9sZIdYZW2XFUC/uRqNHIH+jj43f sTSqMXMyUjsF58h3wZ8tO++CuuDCpIdXTLmWX2m+WPvzGyn0ELEIElHaHFQ9bua8/3DH ENkQ== X-Gm-Message-State: ANoB5pnftyLHk0woRey2iXV2OkSSZWN192yOOvoKc+H1wY/QYSbMEPfz PW5t2+k3MbL/SFEF36vGv8ccYrINdbg= X-Received: by 2002:a63:da10:0:b0:477:ccac:6eb5 with SMTP id c16-20020a63da10000000b00477ccac6eb5mr54090837pgh.41.1670392588130; Tue, 06 Dec 2022 21:56:28 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id t123-20020a628181000000b00561dcfa700asm12640079pfd.107.2022.12.06.21.56.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 21:56:27 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 4DD131142D11; Wed, 7 Dec 2022 16:26:25 +1030 (ACDT) Date: Wed, 7 Dec 2022 16:26:25 +1030 To: binutils@sourceware.org Subject: gas compress_debug tidy Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3036.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra 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?1751533590908084820?= X-GMAIL-MSGID: =?utf-8?q?1751533590908084820?= * write.c (compress_debug): Don't set up "ob" until after seginfo NULL check. Simplify SEC_CONTENTS test. Localise variables. Use bfd_debug_name_to_zdebug. diff --git a/gas/write.c b/gas/write.c index 573e0244459..30545b01f5e 100644 --- a/gas/write.c +++ b/gas/write.c @@ -1461,25 +1461,15 @@ static void compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) { segment_info_type *seginfo = seg_info (sec); - fragS *f; - fragS *first_newf; - fragS *last_newf; - struct obstack *ob = &seginfo->frchainP->frch_obstack; - bfd_size_type uncompressed_size = (bfd_size_type) sec->size; - bfd_size_type compressed_size; - const char *section_name; - char *compressed_name; - char *header; - int x; + bfd_size_type uncompressed_size = sec->size; flagword flags = bfd_section_flags (sec); - unsigned int header_size; if (seginfo == NULL - || sec->size < 32 - || (flags & (SEC_ALLOC | SEC_HAS_CONTENTS)) == SEC_ALLOC) + || uncompressed_size < 32 + || (flags & SEC_HAS_CONTENTS) == 0) return; - section_name = bfd_section_name (sec); + const char *section_name = bfd_section_name (sec); if (!startswith (section_name, ".debug_") && !startswith (section_name, ".gnu.debuglto_.debug_") && !startswith (section_name, ".gnu.linkonce.wi.")) @@ -1490,13 +1480,15 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) if (ctx == NULL) return; + unsigned int header_size; if ((abfd->flags & BFD_COMPRESS_GABI) == 0) header_size = 12; else header_size = bfd_get_compression_header_size (stdoutput, NULL); /* Create a new frag to contain the compression header. */ - first_newf = frag_alloc (ob); + struct obstack *ob = &seginfo->frchainP->frch_obstack; + fragS *first_newf = frag_alloc (ob); if (obstack_room (ob) < header_size) first_newf = frag_alloc (ob); if (obstack_room (ob) < header_size) @@ -1504,16 +1496,16 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) "can't extend frag %lu chars", (unsigned long) header_size), (unsigned long) header_size); - last_newf = first_newf; + fragS *last_newf = first_newf; obstack_blank_fast (ob, header_size); last_newf->fr_type = rs_fill; last_newf->fr_fix = header_size; - header = last_newf->fr_literal; - compressed_size = header_size; + char *header = last_newf->fr_literal; + bfd_size_type compressed_size = header_size; /* Stream the frags through the compression engine, adding new frags as necessary to accommodate the compressed output. */ - for (f = seginfo->frchainP->frch_root; + for (fragS *f = seginfo->frchainP->frch_root; f; f = f->fr_next) { @@ -1573,7 +1565,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) as_fatal (_("can't extend frag")); next_out = obstack_next_free (ob); obstack_blank_fast (ob, avail_out); - x = compress_finish (use_zstd, ctx, &next_out, &avail_out, &out_size); + int x = compress_finish (use_zstd, ctx, &next_out, &avail_out, &out_size); if (x < 0) return; @@ -1599,12 +1591,12 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) /* Update the section size and its name. */ bfd_update_compression_header (abfd, (bfd_byte *) header, sec); - x = bfd_set_section_size (sec, compressed_size); + bool x = bfd_set_section_size (sec, compressed_size); gas_assert (x); if ((abfd->flags & BFD_COMPRESS_GABI) == 0 && section_name[1] == 'd') { - compressed_name = concat (".z", section_name + 1, (char *) NULL); + char *compressed_name = bfd_debug_name_to_zdebug (abfd, section_name); bfd_rename_section (sec, compressed_name); } }