This is the mail archive of the binutils@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]

[PATCH] Create just one PT_NOTE for consecutive loadable .note* sections instead of one for each section


Hi!

Roland noted that we generate one PT_NOTE segment for each .note*
output section.  That should be unnecessary if the sections
are consecutive.  As Roland plans to add a new loadable .note*
section to basically every binary and library, we'd unnecessarily
have two PT_NOTE sections in most binaries (one for this new note,
one for .note.ABI-tag).

2007-06-28  Jakub Jelinek  <jakub@redhat.com>

	* elf.c (get_program_header_size): Adjacent loadable .note*
	sections need just one PT_NOTE segment.
	(_bfd_elf_map_sections_to_segments): Likewise.

--- bfd/elf.c.jj	2007-06-28 12:52:44.000000000 +0200
+++ bfd/elf.c	2007-06-28 16:53:52.000000000 +0200
@@ -3681,6 +3681,14 @@ get_program_header_size (bfd *abfd, stru
 	{
 	  /* We need a PT_NOTE segment.  */
 	  ++segs;
+	  /* Try to create just one PT_NOTE segment
+	     for all adjacent loadable .note* sections.  */
+	  if (s->alignment_power == 2)
+	    while (s->next != NULL
+		   && s->next->alignment_power == 2
+		   && (s->next->flags & SEC_LOAD) != 0
+		   && CONST_STRNEQ (s->next->name, ".note"))
+	      s = s->next;
 	}
     }
 
@@ -4055,25 +4063,43 @@ _bfd_elf_map_sections_to_segments (bfd *
 	  pm = &m->next;
 	}
 
-      /* For each loadable .note section, add a PT_NOTE segment.  We don't
-	 use bfd_get_section_by_name, because if we link together
-	 nonloadable .note sections and loadable .note sections, we will
-	 generate two .note sections in the output file.  FIXME: Using
-	 names for section types is bogus anyhow.  */
+      /* For each batch of consecutive loadable .note sections,
+	 add a PT_NOTE segment.  We don't use bfd_get_section_by_name,
+	 because if we link together nonloadable .note sections and
+	 loadable .note sections, we will generate two .note sections
+	 in the output file.  FIXME: Using names for section types is
+	 bogus anyhow.  */
       for (s = abfd->sections; s != NULL; s = s->next)
 	{
 	  if ((s->flags & SEC_LOAD) != 0
 	      && CONST_STRNEQ (s->name, ".note"))
 	    {
+	      asection *s2;
+	      unsigned count = 1;
 	      amt = sizeof (struct elf_segment_map);
+	      if (s->alignment_power == 2)
+		for (s2 = s; s2->next != NULL; s2 = s2->next)
+		  if (s2->next->alignment_power == 2
+		      && (s2->next->flags & SEC_LOAD) != 0
+		      && CONST_STRNEQ (s2->next->name, ".note")
+		      && align_power (s2->vma + s2->size, 2) == s2->next->vma)
+		    count++;
+		  else
+		    break;
+	      amt += (count - 1) * sizeof (asection *);
 	      m = bfd_zalloc (abfd, amt);
 	      if (m == NULL)
 		goto error_return;
 	      m->next = NULL;
 	      m->p_type = PT_NOTE;
-	      m->count = 1;
-	      m->sections[0] = s;
-
+	      m->count = count;
+	      while (count > 1)
+		{
+		  m->sections[m->count - count--] = s;
+		  BFD_ASSERT ((s->flags & SEC_THREAD_LOCAL) == 0);
+		  s = s->next;
+		}
+	      m->sections[m->count - 1] = s;
 	      *pm = m;
 	      pm = &m->next;
 	    }

	Jakub


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