From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5079 invoked by alias); 15 Jul 2013 22:42:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 5054 invoked by uid 89); 15 Jul 2013 22:42:43 -0000 X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_50,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,RDNS_NONE,SPF_PASS autolearn=no version=3.3.1 Received: from Unknown (HELO mail-vc0-f201.google.com) (209.85.220.201) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 15 Jul 2013 22:42:42 +0000 Received: by mail-vc0-f201.google.com with SMTP id gf11so1131430vcb.4 for ; Mon, 15 Jul 2013 15:42:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type :x-gm-message-state; bh=w28lgFG98xs+hRumj9K+si9UuyjYAijQtSou9fTjXbk=; b=SXQr0hDtlLqFBme5rLYg+ScIP4zlJOj1u32cUPg6Ty6sUA1dgu6zujOYujuA0lA8cx 2UbzZFq/TzfkuPCylr7vZvcq1jRrdheUbYfNJlRUI6ZAm0ZLJJUFqzbhN4dygCtS/QEs ic7AAmYa6Lymh76xLSiZ5ovgkbFIwN0eZGbfYN1XPNsAcczWxYZcVxpEqrirjsg+fpVn UHMVu0S8NZ6Erd3q84f1XaSzTD7MDJxyLylAoneAOLjR94+Fm7zJGXilWKyU1B9JZkm1 IF1uJgjWV2nTUZn768059L4iBswx4KgSQlCcCqqF2+9JUfCdK0427eW/79at/1/eR0jJ hSHQ== X-Received: by 10.236.139.3 with SMTP id b3mr9015444yhj.3.1373928154397; Mon, 15 Jul 2013 15:42:34 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id b80si9563210yhi.2.2013.07.15.15.42.34 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Mon, 15 Jul 2013 15:42:34 -0700 (PDT) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.44]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 0A79F5A417A for ; Mon, 15 Jul 2013 15:42:33 -0700 (PDT) From: Doug Evans To: gdb-patches@sourceware.org Subject: [RFA] Remove target_section.bfd Date: Mon, 15 Jul 2013 22:42:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQlzUZ+ZexlCskiwgbCYjb0t8zqr43h14B+ufYJ4H/O1kGne6583nwCRWTUWzYGah2rqAoHlQb7I2O1VJZJzLGfZ1HHYE+Ie4sIQVf1gvp1Anc+iQGTYE2cdN1w8ao+tWyr92oPRsPcjCOYiJAFet9x1QlslJC5/RnV9R8tIGANm2tj326zDnT/7gKsQFqcRWLitJDiW9BXy8xvAmPtM5567rF4nOCZ05yuo+MkawB3khlqmtu0= X-SW-Source: 2013-07/txt/msg00357.txt.bz2 Hi. While reviewing the remove-symbol-file patchset I came across target_section.bfd. Unnecessarily storing copies of things can lead to confusion and bugs. This patch isn't intended to be a space savings, simply a cleanup. We already liberally reference bfd_section.owner, so I have no problem with adding more references here. [Ideally bfd would provide accessor functions/macros for struct bfd_section, but none exist at all, and I'm not inclined to add all of them just for this patch.] Regression tested on amd64-linux. Ok to check in? 2013-07-15 Doug Evans * target.h (struct target_section): Delete member bfd. All users updated to use the_bfd_section->owner instead. * exec.c (add_to_section_table): Assert bfd is expected value. Remove initialization of target_section.bfd. (remove_target_sections): Update. (section_table_available_memory): Update. (section_table_xfer_memory_partial): Update. (print_section_info): Update. (exec_set_section_address): Update. * record-full.c (record_full_core_xfer_partial): Update. * solib-svr4.c (svr4_relocate_section_addresses): Update. * solib-target.c (solib_target_relocate_section_addresses): Update. * symfile.c (build_section_addr_info_from_section_table): Update. * target.c (memory_xfer_live_readonly_partial): Update. (memory_xfer_partial_1): Update. Index: target.h =================================================================== RCS file: /cvs/src/src/gdb/target.h,v retrieving revision 1.264 diff -u -p -r1.264 target.h --- target.h 27 Jun 2013 19:52:41 -0000 1.264 +++ target.h 15 Jul 2013 22:30:09 -0000 @@ -1898,8 +1898,6 @@ struct target_section just some convenient pointer that can be used to differentiate the BFDs. These are managed only by convention. */ void *key; - - bfd *bfd; /* BFD file pointer */ }; /* Holds an array of target sections. Defined by [SECTIONS..SECTIONS_END[. */ Index: exec.c =================================================================== RCS file: /cvs/src/src/gdb/exec.c,v retrieving revision 1.125 diff -u -p -r1.125 exec.c --- exec.c 6 May 2013 14:15:49 -0000 1.125 +++ exec.c 15 Jul 2013 22:30:08 -0000 @@ -328,6 +328,8 @@ add_to_section_table (bfd *abfd, struct struct target_section **table_pp = (struct target_section **) table_pp_char; flagword aflag; + gdb_assert (abfd == asect->owner); + /* Check the section flags, but do not discard zero-length sections, since some symbols may still be attached to this section. For instance, we encountered on sparc-solaris 2.10 a shared library with an empty .bss @@ -338,7 +340,6 @@ add_to_section_table (bfd *abfd, struct return; (*table_pp)->key = NULL; - (*table_pp)->bfd = abfd; (*table_pp)->the_bfd_section = asect; (*table_pp)->addr = bfd_section_vma (abfd, asect); (*table_pp)->endaddr = (*table_pp)->addr + bfd_section_size (abfd, asect); @@ -436,7 +437,7 @@ remove_target_sections (void *key, bfd * dest = table->sections; for (src = table->sections; src < table->sections_end; src++) - if (src->key != key || src->bfd != abfd) + if (src->key != key || src->the_bfd_section->owner != abfd) { /* Keep this section. */ if (dest < src) @@ -479,7 +480,8 @@ section_table_available_memory (VEC(mem_ for (p = sections; p < sections_end; p++) { - if ((bfd_get_section_flags (p->bfd, p->the_bfd_section) + if ((bfd_get_section_flags (p->the_bfd_section->owner, + p->the_bfd_section) & SEC_READONLY) == 0) continue; @@ -523,7 +525,10 @@ section_table_xfer_memory_partial (gdb_b for (p = sections; p < sections_end; p++) { - if (section_name && strcmp (section_name, p->the_bfd_section->name) != 0) + struct bfd_section *asect = p->the_bfd_section; + bfd *abfd = asect->owner; + + if (section_name && strcmp (section_name, asect->name) != 0) continue; /* not the section we need. */ if (memaddr >= p->addr) { @@ -531,11 +536,11 @@ section_table_xfer_memory_partial (gdb_b { /* Entire transfer is within this section. */ if (writebuf) - res = bfd_set_section_contents (p->bfd, p->the_bfd_section, + res = bfd_set_section_contents (abfd, asect, writebuf, memaddr - p->addr, len); else - res = bfd_get_section_contents (p->bfd, p->the_bfd_section, + res = bfd_get_section_contents (abfd, asect, readbuf, memaddr - p->addr, len); return (res != 0) ? len : 0; @@ -550,11 +555,11 @@ section_table_xfer_memory_partial (gdb_b /* This section overlaps the transfer. Just do half. */ len = p->endaddr - memaddr; if (writebuf) - res = bfd_set_section_contents (p->bfd, p->the_bfd_section, + res = bfd_set_section_contents (abfd, asect, writebuf, memaddr - p->addr, len); else - res = bfd_get_section_contents (p->bfd, p->the_bfd_section, + res = bfd_get_section_contents (abfd, asect, readbuf, memaddr - p->addr, len); return (res != 0) ? len : 0; @@ -610,17 +615,18 @@ print_section_info (struct target_sectio for (p = t->sections; p < t->sections_end; p++) { - asection *asect = p->the_bfd_section; + struct bfd_section *psect = p->the_bfd_section; + bfd *pbfd = psect->owner; - if ((bfd_get_section_flags (abfd, asect) & (SEC_ALLOC | SEC_LOAD)) + if ((bfd_get_section_flags (pbfd, psect) & (SEC_ALLOC | SEC_LOAD)) != (SEC_ALLOC | SEC_LOAD)) continue; - if (bfd_get_section_vma (abfd, asect) <= abfd->start_address - && abfd->start_address < (bfd_get_section_vma (abfd, asect) - + bfd_get_section_size (asect))) + if (bfd_get_section_vma (pbfd, psect) <= abfd->start_address + && abfd->start_address < (bfd_get_section_vma (pbfd, psect) + + bfd_get_section_size (psect))) { - displacement = p->addr - bfd_get_section_vma (abfd, asect); + displacement = p->addr - bfd_get_section_vma (pbfd, psect); break; } } @@ -636,6 +642,9 @@ print_section_info (struct target_sectio } for (p = t->sections; p < t->sections_end; p++) { + struct bfd_section *psect = p->the_bfd_section; + bfd *pbfd = psect->owner; + printf_filtered ("\t%s", hex_string_custom (p->addr, wid)); printf_filtered (" - %s", hex_string_custom (p->endaddr, wid)); @@ -647,11 +656,10 @@ print_section_info (struct target_sectio /* FIXME: i18n: Need to rewrite this sentence. */ if (info_verbose) printf_filtered (" @ %s", - hex_string_custom (p->the_bfd_section->filepos, 8)); - printf_filtered (" is %s", bfd_section_name (p->bfd, - p->the_bfd_section)); - if (p->bfd != abfd) - printf_filtered (" in %s", bfd_get_filename (p->bfd)); + hex_string_custom (psect->filepos, 8)); + printf_filtered (" is %s", bfd_section_name (pbfd, psect)); + if (pbfd != abfd) + printf_filtered (" in %s", bfd_get_filename (pbfd)); printf_filtered ("\n"); } } @@ -720,7 +728,7 @@ exec_set_section_address (const char *fi table = current_target_sections; for (p = table->sections; p < table->sections_end; p++) { - if (filename_cmp (filename, p->bfd->filename) == 0 + if (filename_cmp (filename, p->the_bfd_section->owner->filename) == 0 && index == p->the_bfd_section->index) { p->endaddr += address - p->addr; Index: record-full.c =================================================================== RCS file: /cvs/src/src/gdb/record-full.c,v retrieving revision 1.9 diff -u -p -r1.9 record-full.c --- record-full.c 14 May 2013 20:30:48 -0000 1.9 +++ record-full.c 15 Jul 2013 22:30:08 -0000 @@ -2219,9 +2219,10 @@ record_full_core_xfer_partial (struct ta xmalloc (sizeof (struct record_full_core_buf_entry)); entry->p = p; - if (!bfd_malloc_and_get_section (p->bfd, - p->the_bfd_section, - &entry->buf)) + if (!bfd_malloc_and_get_section + (p->the_bfd_section->owner, + p->the_bfd_section, + &entry->buf)) { xfree (entry); return 0; Index: solib-svr4.c =================================================================== RCS file: /cvs/src/src/gdb/solib-svr4.c,v retrieving revision 1.180 diff -u -p -r1.180 solib-svr4.c --- solib-svr4.c 24 Jun 2013 22:18:32 -0000 1.180 +++ solib-svr4.c 15 Jul 2013 22:30:09 -0000 @@ -2907,10 +2907,10 @@ static void svr4_relocate_section_addresses (struct so_list *so, struct target_section *sec) { - sec->addr = svr4_truncate_ptr (sec->addr + lm_addr_check (so, - sec->bfd)); - sec->endaddr = svr4_truncate_ptr (sec->endaddr + lm_addr_check (so, - sec->bfd)); + bfd *abfd = sec->the_bfd_section->owner; + + sec->addr = svr4_truncate_ptr (sec->addr + lm_addr_check (so, abfd)); + sec->endaddr = svr4_truncate_ptr (sec->endaddr + lm_addr_check (so, abfd)); } Index: solib-target.c =================================================================== RCS file: /cvs/src/src/gdb/solib-target.c,v retrieving revision 1.30 diff -u -p -r1.30 solib-target.c --- solib-target.c 24 Jun 2013 22:18:32 -0000 1.30 +++ solib-target.c 15 Jul 2013 22:30:09 -0000 @@ -456,8 +456,9 @@ Could not relocate shared library \"%s\" } } - offset = so->lm_info->offsets->offsets[gdb_bfd_section_index (sec->bfd, - sec->the_bfd_section)]; + offset = so->lm_info->offsets->offsets[gdb_bfd_section_index + (sec->the_bfd_section->owner, + sec->the_bfd_section)]; sec->addr += offset; sec->endaddr += offset; } Index: symfile.c =================================================================== RCS file: /cvs/src/src/gdb/symfile.c,v retrieving revision 1.380 diff -u -p -r1.380 symfile.c --- symfile.c 19 Jun 2013 22:20:58 -0000 1.380 +++ symfile.c 15 Jul 2013 22:30:09 -0000 @@ -229,15 +229,15 @@ build_section_addr_info_from_section_tab for (stp = start, oidx = 0; stp != end; stp++) { - if (bfd_get_section_flags (stp->bfd, - stp->the_bfd_section) & (SEC_ALLOC | SEC_LOAD) + struct bfd_section *asect = stp->the_bfd_section; + bfd *abfd = asect->owner; + + if (bfd_get_section_flags (abfd, asect) & (SEC_ALLOC | SEC_LOAD) && oidx < end - start) { sap->other[oidx].addr = stp->addr; - sap->other[oidx].name - = xstrdup (bfd_section_name (stp->bfd, stp->the_bfd_section)); - sap->other[oidx].sectindex - = gdb_bfd_section_index (stp->bfd, stp->the_bfd_section); + sap->other[oidx].name = xstrdup (bfd_section_name (abfd, asect)); + sap->other[oidx].sectindex = gdb_bfd_section_index (abfd, asect); oidx++; } } Index: target.c =================================================================== RCS file: /cvs/src/src/gdb/target.c,v retrieving revision 1.338 diff -u -p -r1.338 target.c --- target.c 27 Jun 2013 19:52:41 -0000 1.338 +++ target.c 15 Jul 2013 22:30:09 -0000 @@ -1396,7 +1396,8 @@ memory_xfer_live_readonly_partial (struc secp = target_section_by_addr (ops, memaddr); if (secp != NULL - && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section) + && (bfd_get_section_flags (secp->the_bfd_section->owner, + secp->the_bfd_section) & SEC_READONLY)) { struct target_section *p; @@ -1475,7 +1476,8 @@ memory_xfer_partial_1 (struct target_ops secp = target_section_by_addr (ops, memaddr); if (secp != NULL - && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section) + && (bfd_get_section_flags (secp->the_bfd_section->owner, + secp->the_bfd_section) & SEC_READONLY)) { table = target_get_section_table (ops);