From patchwork Sun Dec 4 21:51:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 29461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1951551wrr; Sun, 4 Dec 2022 13:51:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4QDGzqT9rkY8j/lrPaFXN+N8wjYaO3My04GUBcZPnk+forCKHbKwP2cDgXzlHHeH068WAw X-Received: by 2002:a17:906:9f10:b0:7ad:86f9:1d70 with SMTP id fy16-20020a1709069f1000b007ad86f91d70mr45846287ejc.179.1670190701989; Sun, 04 Dec 2022 13:51:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670190701; cv=none; d=google.com; s=arc-20160816; b=ZuJ839kIK2wi6Mt3tkqOBQsr/PGJeew4XlBmVVUo3TV2gWGyrB4YEbrD2PpY9NL9et FWfNSSlHIel4Vkd1oreQrG8IkT2+LFvKgbKqV3NWkCfMEPDPkgGjaZXCuslZdDV+xBGx zPx+Q2K4Gd4yXP6pfHkPORYAgnLP21YAK19n0I1DZWCSLqJy529cszfJn3MDjjuUe6E0 1QlSieWHvIW+RVLMWpeH47ggQYUJynu8u/hyQ3at/eByDr+0P7VKItad9DoMtnHJKnyw A6toaxXeS/nSB7m74rhz2OH03ftgJpERSOD4jx9LQkf14cJx0V5GljJKVlbmqp+IfzSD mR4Q== 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=cW6Cn30tEfH7sssoK/lXj0wBGmhFwPfOaAv1rriTWYM=; b=YcupwwwFbJLg7A0asqjKwGb80DbA3/TeeYUB74ioBD32WNZA6P1NhBvzljNYuY0qqB bypftCz9G74vICXno7zUXYDS9f8VP3UqNQu71NNvPU6OGUV5XaPul1Ob1RKIJ05RVGeu ObO0abdY7YysviIUZ3uBhr4VUdgEMuw0cdjfhG/jfNfqJIrRZqhkYoWUsKBIzvTo2er5 NjkxL7f/VlIjTDpEvIAA3TDX6jJa/AeIg/talR9YuRW6bPCEM5uXF71CpyYl0MHRiZPz //q6ALMO/6nbvwBJgZbY9dizDd+cZ2lmKQGnZWwLWMrue0Vcc5sgzo+7uNYKYYxnTK6M mY3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=g2ScyUc7; 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 d26-20020aa7c1da000000b00460ce6c3a1asi7954475edp.454.2022.12.04.13.51.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 13:51:41 -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=g2ScyUc7; 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 AAB4238425B3 for ; Sun, 4 Dec 2022 21:51:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAB4238425B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670190700; bh=cW6Cn30tEfH7sssoK/lXj0wBGmhFwPfOaAv1rriTWYM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=g2ScyUc7zZ6HnUphRSl1wB9cmcUpaFJwlGGv18S3wuzAAOAxuY9v1evMvI38+g/BW dG5ss8aUJFEIP6lY3JaDR0MgC24bg54xuR7T8Jhi6VD+fURlU30FewJWm1qQC5lYwz HtjMU+fF+eWA4wTmUBPTwYfwrpHkuFfD52jOB4V8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 300C938432F0 for ; Sun, 4 Dec 2022 21:51:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 300C938432F0 Received: by mail-pf1-x42d.google.com with SMTP id c15so9607855pfb.13 for ; Sun, 04 Dec 2022 13:51:32 -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=cW6Cn30tEfH7sssoK/lXj0wBGmhFwPfOaAv1rriTWYM=; b=33ayBNUwSXNCGjgNOBR8uyLQ9x8mKW7+utYHCJxQVT/TqQ9EihZj4FM4SeSAfkH9b7 +sXK06foPuGFKOvYXqLFdhdC3uGTE5XMt2KBOMtGOSusasVUBwzHJarppmnYRzkH3rrE /uKUSogpwBjYD1111QbJOP95d/aTHWVwSDpKxjyM1oPa3VYlcQP1i6CebaX0ADkV8HVL j4wgf0iD8VgARhfPilh+Ud5mTsUR2eGvd2ma1k5iWxV8T7B3Aeii5Oexq4j35CoqpWyw QFW1oAYbGkmjp98cmbG8IgQRuTh3GZeNaFZLMvuCJeN5cYf+ox/2oZiq3gl6Xfy8zyDi eK7A== X-Gm-Message-State: ANoB5pn4w5juh1B4fpvPmHBAnc7UxkYE9qxpBeBfZDEk4HVZ38XZIQ3I Owt65hHw8jdTHhy9Ut5c6w4VuL0Hg4w= X-Received: by 2002:a63:5d63:0:b0:462:85d6:6276 with SMTP id o35-20020a635d63000000b0046285d66276mr54817585pgm.293.1670190690620; Sun, 04 Dec 2022 13:51:30 -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 q4-20020a170902dac400b00189651e5c26sm9189814plx.236.2022.12.04.13.51.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 13:51:29 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id D5FD91142D17; Mon, 5 Dec 2022 08:21:26 +1030 (ACDT) Date: Mon, 5 Dec 2022 08:21:26 +1030 To: binutils@sourceware.org Subject: Renaming .debug to .zdebug and vice versa 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?1751321885426418438?= X-GMAIL-MSGID: =?utf-8?q?1751321885426418438?= Move a couple of elf.c functions to compress.c. * compress.c (bfd_debug_name_to_zdebug): New inline function. (bfd_zdebug_name_to_debug): Likewise. * elf.c (convert_debug_to_zdebug, convert_zdebug_to_debug): Delete. (_bfd_elf_make_section_from_shdr, elf_fake_sections), (_bfd_elf_assign_file_positions_for_non_load): Adjust to suit. * coffgen.c (make_a_section_from_file): Use new inlines here. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 0b071dda1e5..48451175364 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -7963,6 +7963,31 @@ bfd_byte *bfd_simple_get_relocated_section_contents (bfd *abfd, asection *sec, bfd_byte *outbuf, asymbol **symbol_table); /* Extracted from compress.c. */ +static inline char * +bfd_debug_name_to_zdebug (bfd *abfd, const char *name) +{ + size_t len = strlen (name); + char *new_name = bfd_alloc (abfd, len + 2); + if (new_name == NULL) + return NULL; + new_name[0] = '.'; + new_name[1] = 'z'; + memcpy (new_name + 2, name + 1, len); + return new_name; +} + +static inline char * +bfd_zdebug_name_to_debug (bfd *abfd, const char *name) +{ + size_t len = strlen (name); + char *new_name = bfd_alloc (abfd, len); + if (new_name == NULL) + return NULL; + new_name[0] = '.'; + memcpy (new_name + 1, name + 2, len - 1); + return new_name; +} + bool bfd_get_full_section_contents (bfd *abfd, asection *section, bfd_byte **ptr); diff --git a/bfd/coffgen.c b/bfd/coffgen.c index aab41c34ec7..f2c71b19880 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -181,19 +181,12 @@ make_a_section_from_file (bfd *abfd, abfd, name); return false; } - if (return_section->compress_status == COMPRESS_SECTION_DONE) + if (return_section->compress_status == COMPRESS_SECTION_DONE + && name[1] != 'z') { - if (name[1] != 'z') - { - unsigned int len = strlen (name); - - new_name = bfd_alloc (abfd, len + 2); - if (new_name == NULL) - return false; - new_name[0] = '.'; - new_name[1] = 'z'; - memcpy (new_name + 2, name + 1, len); - } + new_name = bfd_debug_name_to_zdebug (abfd, name); + if (new_name == NULL) + return false; } break; case decompress: @@ -207,13 +200,9 @@ make_a_section_from_file (bfd *abfd, } if (name[1] == 'z') { - unsigned int len = strlen (name); - - new_name = bfd_alloc (abfd, len); + new_name = bfd_zdebug_name_to_debug (abfd, name); if (new_name == NULL) return false; - new_name[0] = '.'; - memcpy (new_name + 1, name + 2, len - 1); } break; } diff --git a/bfd/compress.c b/bfd/compress.c index ad3feeafc6c..95579847cf3 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -30,6 +30,35 @@ #define MAX_COMPRESSION_HEADER_SIZE 24 +/* +CODE_FRAGMENT +.static inline char * +.bfd_debug_name_to_zdebug (bfd *abfd, const char *name) +.{ +. size_t len = strlen (name); +. char *new_name = bfd_alloc (abfd, len + 2); +. if (new_name == NULL) +. return NULL; +. new_name[0] = '.'; +. new_name[1] = 'z'; +. memcpy (new_name + 2, name + 1, len); +. return new_name; +.} +. +.static inline char * +.bfd_zdebug_name_to_debug (bfd *abfd, const char *name) +.{ +. size_t len = strlen (name); +. char *new_name = bfd_alloc (abfd, len); +. if (new_name == NULL) +. return NULL; +. new_name[0] = '.'; +. memcpy (new_name + 1, name + 2, len - 1); +. return new_name; +.} +. +*/ + static bool decompress_contents (bool is_zstd, bfd_byte *compressed_buffer, bfd_size_type compressed_size, diff --git a/bfd/elf.c b/bfd/elf.c index 87ec1623313..9e490c968c1 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -968,31 +968,6 @@ bfd_elf_group_name (bfd *abfd ATTRIBUTE_UNUSED, const asection *sec) return NULL; } -static char * -convert_debug_to_zdebug (bfd *abfd, const char *name) -{ - unsigned int len = strlen (name); - char *new_name = bfd_alloc (abfd, len + 2); - if (new_name == NULL) - return NULL; - new_name[0] = '.'; - new_name[1] = 'z'; - memcpy (new_name + 2, name + 1, len); - return new_name; -} - -static char * -convert_zdebug_to_debug (bfd *abfd, const char *name) -{ - unsigned int len = strlen (name); - char *new_name = bfd_alloc (abfd, len); - if (new_name == NULL) - return NULL; - new_name[0] = '.'; - memcpy (new_name + 1, name + 2, len - 1); - return new_name; -} - /* This a copy of lto_section defined in GCC (lto-streamer.h). */ struct lto_section @@ -1285,7 +1260,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, /* Convert section name from .zdebug_* to .debug_* so that linker will consider this section as a debug section. */ - char *new_name = convert_zdebug_to_debug (abfd, name); + char *new_name = bfd_zdebug_name_to_debug (abfd, name); if (new_name == NULL) return false; bfd_rename_section (newsect, new_name); @@ -3233,7 +3208,7 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) needed. */ if (name[1] == 'z') { - char *new_name = convert_zdebug_to_debug (abfd, name); + char *new_name = bfd_zdebug_name_to_debug (abfd, name); if (new_name == NULL) { arg->failed = true; @@ -3249,7 +3224,7 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) section smaller. So only rename the section when compression has actually taken place. If input section name is .zdebug_*, we should never compress it again. */ - char *new_name = convert_debug_to_zdebug (abfd, name); + char *new_name = bfd_debug_name_to_zdebug (abfd, name); if (new_name == NULL) { arg->failed = true; @@ -6729,8 +6704,7 @@ _bfd_elf_assign_file_positions_for_non_load (bfd *abfd) { /* If section is compressed with zlib-gnu, convert section name from .debug_* to .zdebug_*. */ - char *new_name - = convert_debug_to_zdebug (abfd, name); + char *new_name = bfd_debug_name_to_zdebug (abfd, name); if (new_name == NULL) return false; name = new_name;