This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Iterate ELF sections by pointer


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e06efbf1c8198e25ef36a9787862f9720a94ba7b

commit e06efbf1c8198e25ef36a9787862f9720a94ba7b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Apr 20 08:50:01 2015 -0700

    Iterate ELF sections by pointer
    
    Iterate ELF sections by pointer without section counter.  It removes
    "i++".
    
    	* elf.c (assign_file_positions_for_non_load_sections): Iterate
    	sections by pointer.
    	(_bfd_elf_assign_file_positions_for_non_load): Likewise.

Diff:
---
 bfd/ChangeLog |  6 ++++++
 bfd/elf.c     | 17 ++++++++---------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index abb87dc..09231bf 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2015-04-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* elf.c (assign_file_positions_for_non_load_sections): Iterate
+	sections by pointer.
+	(_bfd_elf_assign_file_positions_for_non_load): Likewise.
+
 2015-04-14  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* bfd-in.h (compressed_debug_section_type): New.
diff --git a/bfd/elf.c b/bfd/elf.c
index 85a4b6b..4258c6e 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5101,7 +5101,7 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
 {
   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   Elf_Internal_Shdr **i_shdrpp;
-  Elf_Internal_Shdr **hdrpp;
+  Elf_Internal_Shdr **hdrpp, **end_hdrpp;
   Elf_Internal_Phdr *phdrs;
   Elf_Internal_Phdr *p;
   struct elf_segment_map *m;
@@ -5109,14 +5109,12 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
   bfd_vma filehdr_vaddr, filehdr_paddr;
   bfd_vma phdrs_vaddr, phdrs_paddr;
   file_ptr off;
-  unsigned int num_sec;
-  unsigned int i;
   unsigned int count;
 
   i_shdrpp = elf_elfsections (abfd);
-  num_sec = elf_numsections (abfd);
+  end_hdrpp = i_shdrpp + elf_numsections (abfd);
   off = elf_next_file_pos (abfd);
-  for (i = 1, hdrpp = i_shdrpp + 1; i < num_sec; i++, hdrpp++)
+  for (hdrpp = i_shdrpp + 1; hdrpp < end_hdrpp; hdrpp++)
     {
       Elf_Internal_Shdr *hdr;
 
@@ -5308,6 +5306,7 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
 	}
       else if (m->count != 0)
 	{
+	  unsigned int i;
 	  if (p->p_type != PT_LOAD
 	      && (p->p_type != PT_NOTE
 		  || bfd_get_format (abfd) != bfd_core))
@@ -5559,15 +5558,15 @@ static bfd_boolean
 _bfd_elf_assign_file_positions_for_non_load (bfd *abfd)
 {
   file_ptr off;
-  unsigned int i, num_sec;
-  Elf_Internal_Shdr **shdrpp;
+  Elf_Internal_Shdr **shdrpp, **end_shdrpp;
   Elf_Internal_Ehdr *i_ehdrp;
   const struct elf_backend_data *bed;
 
   off = elf_next_file_pos (abfd);
 
-  num_sec = elf_numsections (abfd);
-  for (i = 1, shdrpp = elf_elfsections (abfd) + 1; i < num_sec; i++, shdrpp++)
+  shdrpp = elf_elfsections (abfd);
+  end_shdrpp = shdrpp + elf_numsections (abfd);
+  for (shdrpp++; shdrpp < end_shdrpp; shdrpp++)
     {
       Elf_Internal_Shdr *shdrp;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]