From patchwork Wed Feb 15 11:35:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 57486 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp138617wrn; Wed, 15 Feb 2023 03:35:31 -0800 (PST) X-Google-Smtp-Source: AK7set86qVjIWL0PvQ1IJReHt212Xf0GkF34yPIlXdXo3M63ZCfOznCirewa+Aa5IcBwyF144Sfq X-Received: by 2002:a17:907:9868:b0:87d:eff1:acc8 with SMTP id ko8-20020a170907986800b0087deff1acc8mr1899459ejc.48.1676460931039; Wed, 15 Feb 2023 03:35:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676460931; cv=none; d=google.com; s=arc-20160816; b=cJjdm/2DPfVgMlW7nOVE7qAzLInNezF5zmaJSZMoplRiDfvd5Pu7wV5hdfV45VE/Qi pO5JCIqsWNwB+XIdN+xQMGwJmlQckoEfYF7VtdRDmXr3F0eBFv0y2oZcgTOgC4x0omi1 xc4QvNtDp+owXGiWLx+xZRC5r1Y560O/Gxi2mlQhR1UWuTfiXx3xFdsqXGaFCad9LogQ hjror4bPYRPpkUub21SR5FI6YQbC1aWmyaDTgJW3lGJhbsa2ftPaaCRWoDwnT/fUdTyk VUYDZ/0RcHB9TWUSw9NthhOQTPsKcWQggl2YibytWIWHu1kck7NJv8/03JhVQti5vPVH bUeg== 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=G65QIT5unfGbXgRGOdXKefG0wzPi3ux4XSIahBIgr7c=; b=ujWqsSpLhU8pRZsfu4nShwlatru2B7GTuZ8E55ZOHaaYIaT5GwCAy3RqcxE94Jdiha Bo+veDpvGzj6mPirpKKZTY0aegEZndUEa8HCitscxlTCg7AyNWhlgsofVq4kx2ZKsJNW IBSsSzhNfFMuh6HfysZrmiJxLVS/jDrvsjjzEfUcF/25h4/X8HcUlLYyUYtQ6gjMut7X VLE3hyutsaSjLvqZUu5zf8j8LJEYkOmjOqL+mfyUZPapvuCEsm/hyKPEF5mM4+/9BLdv gaziVzCjygeb1rIuDPnXrqqjfeaZCwpG+rNRK6Xn5zRIX+z+jrpzslUvMV1tm3qgXksU sNEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=YtnHXG4q; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id up31-20020a170907cc9f00b008b14b54b103si623903ejc.266.2023.02.15.03.35.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 03:35:31 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=YtnHXG4q; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 C7FE43858281 for ; Wed, 15 Feb 2023 11:35:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7FE43858281 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676460929; bh=G65QIT5unfGbXgRGOdXKefG0wzPi3ux4XSIahBIgr7c=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YtnHXG4qEUEBIx0W0ufcvZojsYxuWLGOY0/tnfnAqbyps2XzH86O8pm001bQXHx8V ylxBG/9ckVCoZPcSfDwC12cxeZO0wVZj1ycHxOsREt3ch9uHUwzQZGoXl8pasln/Bl F7P8U4e+pT8HJF0ezeu4rbXJfwt6zUYPvTCqzRU8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 397793858005 for ; Wed, 15 Feb 2023 11:35:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 397793858005 Received: by mail-pl1-x631.google.com with SMTP id r8so19975227pls.2 for ; Wed, 15 Feb 2023 03:35:11 -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=G65QIT5unfGbXgRGOdXKefG0wzPi3ux4XSIahBIgr7c=; b=qDgc1dexZLJJEPE4FSSE2ppoLEsakxbtRyYYlJ5zlOs1FGXFGPiE2T6ujks7tWN764 J1kw23XX/Nad6SeK7fi8Yp+L+3thf4PHBxko/VCKJzSbXnPjNvMhimmEusJeWmSxKHpu av0AvJxuMVoIgo4l4a8xe/wCVZAmdiImGh+mEmgN5jgG00SHEvSNwp0TL4e5B0zKQJzQ N9mx8UgqXfJkm17uPqKFqZydF5Ao2JZBjMeEB/LcPSz7KQvQhRvcphhoZZEUcSdS1+T8 tiloRVniGYbKXS9aAPJ+kMchg6UQ27fNTSnm4pa+QFOfeClUb0YBWibUvzvuHhhckLP4 temQ== X-Gm-Message-State: AO0yUKV2pqzbaLyMOypv2rHwMcLddynPRUZahXkfn+V74yuj9L7MKxVH vbfbxSYe1Zw2adri7exqJyQYvR6XKCc= X-Received: by 2002:a17:902:e80e:b0:19a:59d1:389e with SMTP id u14-20020a170902e80e00b0019a59d1389emr2576201plg.23.1676460909428; Wed, 15 Feb 2023 03:35:09 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:1b9c:c91c:471:5eb]) by smtp.gmail.com with ESMTPSA id b2-20020a170902d30200b0019a733a75a2sm9935323plc.60.2023.02.15.03.35.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 03:35:09 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id CEC891142CCD; Wed, 15 Feb 2023 22:05:06 +1030 (ACDT) Date: Wed, 15 Feb 2023 22:05:06 +1030 To: binutils@sourceware.org Subject: objdump read_section_stabs Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.9 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?1757896697225027355?= X-GMAIL-MSGID: =?utf-8?q?1757896697225027355?= This function is used to read sections other than stabs, and there is now another version of it that extracts different info from the bfd section. Rename it and return the bfd section instead of assorted fields of the bfd section. * objcopy.c (read_section): Renamed from read_section_stabs. Delete size_ptr and entsize_ptr params, add contents param. Return asection pointer. Don't unnecessarily free contents on failure from bfd_malloc_and_get_section. (find_stabs_section): Use read_section. (dump_ctf, dump_section_sframe): Likewise. (read_section_sframe): Delete. diff --git a/binutils/objdump.c b/binutils/objdump.c index 8a8bfba5c76..8cf9d059801 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -4443,39 +4443,32 @@ dump_dwarf (bfd *abfd, bool is_mainfile) bfd_map_over_sections (abfd, dump_dwarf_section, (void *) &is_mainfile); } -/* Read ABFD's stabs section STABSECT_NAME, and return a pointer to - it. Return NULL on failure. */ +/* Read ABFD's section SECT_NAME into *CONTENTS, and return a pointer to + the section. Return NULL on failure. */ -static bfd_byte * -read_section_stabs (bfd *abfd, const char *sect_name, bfd_size_type *size_ptr, - bfd_size_type *entsize_ptr) +static asection * +read_section (bfd *abfd, const char *sect_name, bfd_byte **contents) { - asection *stabsect; - bfd_byte *contents; + asection *sec; - stabsect = bfd_get_section_by_name (abfd, sect_name); - if (stabsect == NULL) + *contents = NULL; + sec = bfd_get_section_by_name (abfd, sect_name); + if (sec == NULL) { - printf (_("No %s section present\n\n"), - sanitize_string (sect_name)); - return false; + printf (_("No %s section present\n\n"), sanitize_string (sect_name)); + return NULL; } - if (!bfd_malloc_and_get_section (abfd, stabsect, &contents)) + if (!bfd_malloc_and_get_section (abfd, sec, contents)) { non_fatal (_("reading %s section of %s failed: %s"), sect_name, bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ())); exit_status = 1; - free (contents); return NULL; } - *size_ptr = bfd_section_size (stabsect); - if (entsize_ptr) - *entsize_ptr = stabsect->entsize; - - return contents; + return sec; } /* Stabs entries use a 12 byte format: @@ -4595,15 +4588,20 @@ find_stabs_section (bfd *abfd, asection *section, void *names) && (section->name[len] == 0 || (section->name[len] == '.' && ISDIGIT (section->name[len + 1])))) { + asection *s; if (strtab == NULL) - strtab = read_section_stabs (abfd, sought->string_section_name, - &stabstr_size, NULL); + { + s = read_section (abfd, sought->string_section_name, &strtab); + if (s != NULL) + stabstr_size = bfd_section_size (s); + } if (strtab) { - stabs = read_section_stabs (abfd, section->name, &stab_size, NULL); - if (stabs) + s = read_section (abfd, section->name, &stabs); + if (s != NULL) { + stab_size = bfd_section_size (s); print_section_stabs (abfd, section->name, &sought->string_offset); free (stabs); } @@ -4776,9 +4774,9 @@ dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, ctf_dict_t *parent, static void dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name) { + asection *sec; ctf_archive_t *ctfa = NULL; - bfd_byte *ctfdata = NULL; - bfd_size_type ctfsize; + bfd_byte *ctfdata; ctf_sect_t ctfsect; ctf_dict_t *parent; ctf_dict_t *fp; @@ -4790,13 +4788,14 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name) if (sect_name == NULL) sect_name = ".ctf"; - if ((ctfdata = read_section_stabs (abfd, sect_name, &ctfsize, NULL)) == NULL) - bfd_fatal (bfd_get_filename (abfd)); + sec = read_section (abfd, sect_name, &ctfdata); + if (sec == NULL) + bfd_fatal (bfd_get_filename (abfd)); /* Load the CTF file and dump it. Preload the parent dict, since it will need to be imported into every child in turn. */ - ctfsect = make_ctfsect (sect_name, ctfdata, ctfsize); + ctfsect = make_ctfsect (sect_name, ctfdata, bfd_section_size (sec)); if ((ctfa = ctf_bfdopen_ctfsect (abfd, &ctfsect, &err)) == NULL) { dump_ctf_errs (NULL); @@ -4831,54 +4830,25 @@ dump_ctf (bfd *abfd ATTRIBUTE_UNUSED, const char *sect_name ATTRIBUTE_UNUSED, const char *parent_name ATTRIBUTE_UNUSED) {} #endif -static bfd_byte* -read_section_sframe (bfd *abfd, const char *sect_name, bfd_size_type *size_ptr, - bfd_vma *sframe_vma) -{ - asection *sframe_sect; - bfd_byte *contents; - - sframe_sect = bfd_get_section_by_name (abfd, sect_name); - if (sframe_sect == NULL) - { - printf (_("No %s section present\n\n"), - sanitize_string (sect_name)); - return NULL; - } - - if (!bfd_malloc_and_get_section (abfd, sframe_sect, &contents)) - { - non_fatal (_("reading %s section of %s failed: %s"), - sect_name, bfd_get_filename (abfd), - bfd_errmsg (bfd_get_error ())); - exit_status = 1; - free (contents); - return NULL; - } - - *size_ptr = bfd_section_size (sframe_sect); - *sframe_vma = bfd_section_vma (sframe_sect); - - return contents; -} - static void dump_section_sframe (bfd *abfd ATTRIBUTE_UNUSED, const char * sect_name) { + asection *sec; sframe_decoder_ctx *sfd_ctx = NULL; bfd_size_type sf_size; - bfd_byte *sframe_data = NULL; + bfd_byte *sframe_data; bfd_vma sf_vma; int err = 0; if (sect_name == NULL) sect_name = ".sframe"; - sframe_data = read_section_sframe (abfd, sect_name, &sf_size, &sf_vma); - - if (sframe_data == NULL) + sec = read_section (abfd, sect_name, &sframe_data); + if (sec == NULL) bfd_fatal (bfd_get_filename (abfd)); + sf_size = bfd_section_size (sec); + sf_vma = bfd_section_vma (sec); /* Decode the contents of the section. */ sfd_ctx = sframe_decode ((const char*)sframe_data, sf_size, &err);