From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id AE52B384F4A5 for ; Wed, 7 Dec 2022 05:57:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AE52B384F4A5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102e.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so488669pjs.4 for ; Tue, 06 Dec 2022 21:57:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=SmdUYyfCGdlHnGJ08LJY8lBBfrnEqQTmQo3S4Y8kUOU=; b=GhJ3ctCGMXtkk5tvSxmoF4WeuP6mrXy/4bFvYAbPntVd225ITbIw6HO5zT8SSh2ve5 OJl+q587E38wm9g47mLp9N5fAL/1w9Mh/jHzj1qhznFHKDIHQGrVYO5o6jnKLDwY3eEO AAPAD/3EnIpdkDi9zCR8ABhlejIvG0Xa+m59v05qzM/ETjOjv5vvFSeBDTvkMpx6Wy4g xmj/3iv6Ww8EEVAgklE+qPEIZ1RJvlh8DqFeM8eCjBvHvZAoxj/967IcmPCa54Rgy8xm rz853s74K56RjBeWyqIR/w4K/ODqTkk7DEWKuSp1+Gdv5Y/JPw74AELhOTF7x0T+zqvk JYqQ== 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=SmdUYyfCGdlHnGJ08LJY8lBBfrnEqQTmQo3S4Y8kUOU=; b=z95ejc/MvaZZDXZWTYSb3P3qoo6qoLCMWxhu03bYss6jDnsCgHEVijJkP6xDM8OSz7 FGPFWEJKnhwDKbZlN12xCRV272FJSdg/PKLH5y8kSr0FeMcm7vrCcUJzPIrVpPKwyUZQ 7uSMVF8CokYolRx8rLBhLP/QuesZCbN3JLntC+RVDVGvl+Mrs1lJVAPm/L2rnIQEbHIk xaOQ+Z2AV7Q0npjzkGgYUSIy4Gn73OdSgUJpDyfokVcfu0gm/PAOylM2LcZvOkPaxQiR 1aUI83jJ0FCUFDrbXAEhSw360CxU3k6Xi7+s6EiUBurnQbUSrooOG+5Vb4pBGmEqu7rt vSNg== X-Gm-Message-State: ANoB5pkb3erVNsK5P/G2hsC/lKYnBQPr3KAYnhFHdLAyuVJ+pboMH3Eq ZVl5LGISPiU95Yarg/Iikf3AXFD2v2I= X-Google-Smtp-Source: AA0mqf7C0X5VaMsnR6Ar3QsexBnDE7DdBBpr/1Pw5M13TkhqxowLIqZpNtD5penSD40J5KMK6+eWsg== X-Received: by 2002:a17:902:d413:b0:189:eb37:253 with SMTP id b19-20020a170902d41300b00189eb370253mr6099686ple.23.1670392647520; Tue, 06 Dec 2022 21:57:27 -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 a10-20020a1709027e4a00b0018913417ba2sm13565525pln.130.2022.12.06.21.57.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 21:57:27 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id D139E1142D14; Wed, 7 Dec 2022 16:27:24 +1030 (ACDT) Date: Wed, 7 Dec 2022 16:27:24 +1030 From: Alan Modra To: binutils@sourceware.org Subject: coff make_a_section_from_file tidy Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 List-Id: Also support compressing a few more sections. * coffgen.c (make_a_section_from_file): Rename return_section to newsect. Don't try to be clever matching section name. Compress .gnu.debuglto_.debug_ and .gnu.linkonce.wi. too. Only rename debug sections when decompressing for linker. diff --git a/bfd/coffgen.c b/bfd/coffgen.c index e072e168cb8..09f5a28c435 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -51,7 +51,7 @@ make_a_section_from_file (bfd *abfd, struct internal_scnhdr *hdr, unsigned int target_index) { - asection *return_section; + asection *newsect; char *name; bool result = true; flagword flags; @@ -107,34 +107,33 @@ make_a_section_from_file (bfd *abfd, name[sizeof (hdr->s_name)] = 0; } - return_section = bfd_make_section_anyway (abfd, name); - if (return_section == NULL) + newsect = bfd_make_section_anyway (abfd, name); + if (newsect == NULL) return false; - return_section->vma = hdr->s_vaddr; - return_section->lma = hdr->s_paddr; - return_section->size = hdr->s_size; - return_section->filepos = hdr->s_scnptr; - return_section->rel_filepos = hdr->s_relptr; - return_section->reloc_count = hdr->s_nreloc; + newsect->vma = hdr->s_vaddr; + newsect->lma = hdr->s_paddr; + newsect->size = hdr->s_size; + newsect->filepos = hdr->s_scnptr; + newsect->rel_filepos = hdr->s_relptr; + newsect->reloc_count = hdr->s_nreloc; - bfd_coff_set_alignment_hook (abfd, return_section, hdr); + bfd_coff_set_alignment_hook (abfd, newsect, hdr); - return_section->line_filepos = hdr->s_lnnoptr; + newsect->line_filepos = hdr->s_lnnoptr; - return_section->lineno_count = hdr->s_nlnno; - return_section->userdata = NULL; - return_section->next = NULL; - return_section->target_index = target_index; + newsect->lineno_count = hdr->s_nlnno; + newsect->userdata = NULL; + newsect->next = NULL; + newsect->target_index = target_index; - if (! bfd_coff_styp_to_sec_flags_hook (abfd, hdr, name, return_section, - & flags)) + if (!bfd_coff_styp_to_sec_flags_hook (abfd, hdr, name, newsect, &flags)) result = false; /* At least on i386-coff, the line number count for a shared library section must be ignored. */ if ((flags & SEC_COFF_SHARED_LIBRARY) != 0) - return_section->lineno_count = 0; + newsect->lineno_count = 0; if (hdr->s_nreloc != 0) flags |= SEC_RELOC; @@ -142,20 +141,19 @@ make_a_section_from_file (bfd *abfd, if (hdr->s_scnptr != 0) flags |= SEC_HAS_CONTENTS; - return_section->flags = flags; + newsect->flags = flags; - /* Compress/decompress DWARF debug sections with names: .debug_* and - .zdebug_*, after the section flags is set. */ + /* Compress/decompress DWARF debug sections. */ if ((flags & SEC_DEBUGGING) != 0 && (flags & SEC_HAS_CONTENTS) != 0 - && strlen (name) > 7 - && ((name[1] == 'd' && name[6] == '_') - || (strlen (name) > 8 && name[1] == 'z' && name[7] == '_'))) + && (startswith (name, ".debug_") + || startswith (name, ".zdebug_") + || startswith (name, ".gnu.debuglto_.debug_") + || startswith (name, ".gnu.linkonce.wi."))) { enum { nothing, compress, decompress } action = nothing; - char *new_name = NULL; - if (bfd_is_section_compressed (abfd, return_section)) + if (bfd_is_section_compressed (abfd, newsect)) { /* Compressed section. Check if we should decompress. */ if ((abfd->flags & BFD_DECOMPRESS)) @@ -164,50 +162,40 @@ make_a_section_from_file (bfd *abfd, else { /* Normal section. Check if we should compress. */ - if ((abfd->flags & BFD_COMPRESS) && return_section->size != 0) + if ((abfd->flags & BFD_COMPRESS) && newsect->size != 0) action = compress; } - switch (action) + if (action == compress) { - case nothing: - break; - case compress: - if (!bfd_init_section_compress_status (abfd, return_section)) + if (!bfd_init_section_compress_status (abfd, newsect)) { _bfd_error_handler - /* xgettext: c-format */ - (_("%pB: unable to compress section %s"), - abfd, name); + /* xgettext:c-format */ + (_("%pB: unable to compress section %s"), abfd, name); return false; } - if (return_section->compress_status == COMPRESS_SECTION_DONE - && name[1] != 'z') - { - new_name = bfd_debug_name_to_zdebug (abfd, name); - if (new_name == NULL) - return false; - } - break; - case decompress: - if (!bfd_init_section_decompress_status (abfd, return_section)) + } + else if (action == decompress) + { + if (!bfd_init_section_decompress_status (abfd, newsect)) { _bfd_error_handler - /* xgettext: c-format */ - (_("%pB: unable to decompress section %s"), - abfd, name); + /* xgettext:c-format */ + (_("%pB: unable to decompress section %s"), abfd, name); return false; } - if (name[1] == 'z') + if (abfd->is_linker_input + && name[1] == 'z') { - new_name = bfd_zdebug_name_to_debug (abfd, name); + /* Rename section from .zdebug_* to .debug_* so that ld + scripts will see this section as a debug section. */ + char *new_name = bfd_zdebug_name_to_debug (abfd, name); if (new_name == NULL) return false; + bfd_rename_section (newsect, new_name); } - break; } - if (new_name != NULL) - bfd_rename_section (return_section, new_name); } return result; -- Alan Modra Australia Development Lab, IBM