From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway24.websitewelcome.com (gateway24.websitewelcome.com [192.185.50.252]) by sourceware.org (Postfix) with ESMTPS id 8F871394847E for ; Fri, 28 Aug 2020 16:23:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8F871394847E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 3C6795737F6 for ; Fri, 28 Aug 2020 11:23:54 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id BhAQkvzarOIGpBhAQkURTD; Fri, 28 Aug 2020 11:23:54 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8qH6oQ9/HCMnJBfrpAHW8hx8Yqz4s8lyePSbZXqPYwk=; b=Oeu5dJaaNxVLGSPZQDG1UqFmG5 E0hBdylPULKi8hq+eF9TNWZ76xtwqKior3mJyMrFJUS5ubU0rgILst2FUqeRqXQLbr244v5yPjPGJ MlSXdDow1W1h5SphyeTKxEsKh; Received: from 71-218-12-75.hlrn.qwest.net ([71.218.12.75]:33904 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kBhAQ-002WJo-0z; Fri, 28 Aug 2020 10:23:54 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 06/13] Use gdb_bfd_sections in symfile.c Date: Fri, 28 Aug 2020 10:23:42 -0600 Message-Id: <20200828162349.987-7-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200828162349.987-1-tom@tromey.com> References: <20200828162349.987-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.218.12.75 X-Source-L: No X-Exim-ID: 1kBhAQ-002WJo-0z X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-218-12-75.hlrn.qwest.net (bapiya.Home) [71.218.12.75]:33904 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3035.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2020 16:23:56 -0000 This changes some functions in symfile.c to avoid bfd_map_over_sections, in favor of iteration. Some helper types can also be removed due to this change. gdb/ChangeLog 2020-08-28 Tom Tromey * symfile.h: (find_lowest_section): Don't declare. * symfile.c (find_lowest_section): Now static. Change parameters. (struct place_section_arg): Remove. (place_section): Change parameters. (addr_info_make_relative): Use foreach. (symfile_dummy_outputs): Remove. (default_symfile_relocate): Use foreach. --- gdb/ChangeLog | 11 +++++++++++ gdb/symfile.c | 53 +++++++++++++++++---------------------------------- gdb/symfile.h | 2 -- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index 2c38ce4431a..96d8b3f0b52 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -187,7 +187,6 @@ increment_reading_symtab (void) } /* Remember the lowest-addressed loadable section we've seen. - This function is called via bfd_map_over_sections. In case of equal vmas, the section with the largest size becomes the lowest-addressed loadable section. @@ -195,11 +194,9 @@ increment_reading_symtab (void) If the vmas and sizes are equal, the last section is considered the lowest-addressed loadable section. */ -void -find_lowest_section (bfd *abfd, asection *sect, void *obj) +static void +find_lowest_section (asection *sect, asection **lowest) { - asection **lowest = (asection **) obj; - if (0 == (bfd_section_flags (sect) & (SEC_ALLOC | SEC_LOAD))) return; if (!*lowest) @@ -335,22 +332,13 @@ init_objfile_sect_indices (struct objfile *objfile) } } -/* The arguments to place_section. */ - -struct place_section_arg -{ - section_offsets *offsets; - CORE_ADDR lowest; -}; - /* Find a unique offset to use for loadable section SECT if the user did not provide an offset. */ static void -place_section (bfd *abfd, asection *sect, void *obj) +place_section (bfd *abfd, asection *sect, section_offsets &offsets, + CORE_ADDR &lowest) { - struct place_section_arg *arg = (struct place_section_arg *) obj; - section_offsets &offsets = *arg->offsets; CORE_ADDR start_addr; int done; ULONGEST align = ((ULONGEST) 1) << bfd_section_alignment (sect); @@ -364,7 +352,7 @@ place_section (bfd *abfd, asection *sect, void *obj) return; /* Otherwise, let's try to find a place for the section. */ - start_addr = (arg->lowest + align - 1) & -align; + start_addr = (lowest + align - 1) & -align; do { asection *cur_sec; @@ -405,7 +393,7 @@ place_section (bfd *abfd, asection *sect, void *obj) while (!done); offsets[gdb_bfd_section_index (abfd, sect)] = start_addr; - arg->lowest = start_addr + bfd_section_size (sect); + lowest = start_addr + bfd_section_size (sect); } /* Store section_addr_info as prepared (made relative and with SECTINDEX @@ -500,7 +488,8 @@ addr_info_make_relative (section_addr_info *addrs, bfd *abfd) /* Find lowest loadable section to be used as starting point for contiguous sections. */ lower_sect = NULL; - bfd_map_over_sections (abfd, find_lowest_section, &lower_sect); + for (asection *iter : gdb_bfd_sections (abfd)) + find_lowest_section (iter, &lower_sect); if (lower_sect == NULL) { warning (_("no loadable sections found in added symbol-file %s"), @@ -645,7 +634,6 @@ default_symfile_offsets (struct objfile *objfile, small. */ if ((bfd_get_file_flags (objfile->obfd) & (EXEC_P | DYNAMIC)) == 0) { - struct place_section_arg arg; bfd *abfd = objfile->obfd; asection *cur_sec; @@ -661,9 +649,10 @@ default_symfile_offsets (struct objfile *objfile, /* Pick non-overlapping offsets for sections the user did not place explicitly. */ - arg.offsets = &objfile->section_offsets; - arg.lowest = 0; - bfd_map_over_sections (objfile->obfd, place_section, &arg); + CORE_ADDR lowest = 0; + for (asection *sect : gdb_bfd_sections (objfile->obfd)) + place_section (objfile->obfd, sect, objfile->section_offsets, + lowest); /* Correctly filling in the section offsets is not quite enough. Relocatable files have two properties that @@ -3570,18 +3559,6 @@ simple_overlay_update (struct obj_section *osect) } } -/* Set the output sections and output offsets for section SECTP in - ABFD. The relocation code in BFD will read these offsets, so we - need to be sure they're initialized. We map each section to itself, - with no offset; this means that SECTP->vma will be honored. */ - -static void -symfile_dummy_outputs (bfd *abfd, asection *sectp, void *dummy) -{ - sectp->output_section = sectp; - sectp->output_offset = 0; -} - /* Default implementation for sym_relocate. */ bfd_byte * @@ -3599,7 +3576,11 @@ default_symfile_relocate (struct objfile *objfile, asection *sectp, /* We will handle section offsets properly elsewhere, so relocate as if all sections begin at 0. */ - bfd_map_over_sections (abfd, symfile_dummy_outputs, NULL); + for (asection *sect : gdb_bfd_sections (abfd)) + { + sect->output_section = sect; + sect->output_offset = 0; + } return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL); } diff --git a/gdb/symfile.h b/gdb/symfile.h index fe79f79a048..203620bc284 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -474,8 +474,6 @@ extern bool auto_solib_add; extern void set_initial_language (void); -extern void find_lowest_section (bfd *, asection *, void *); - extern gdb_bfd_ref_ptr symfile_bfd_open (const char *); extern int get_section_index (struct objfile *, const char *); -- 2.17.2