emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs/src ChangeLog unexelf.c


From: Andreas Schwab
Subject: [Emacs-diffs] emacs/src ChangeLog unexelf.c
Date: Mon, 02 Feb 2009 16:07:01 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Andreas Schwab <schwab> 09/02/02 16:07:00

Modified files:
        src            : ChangeLog unexelf.c 

Log message:
        (unexec): Handle unaligned bss offset.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/src/ChangeLog?cvsroot=emacs&r1=1.7334&r2=1.7335
http://cvs.savannah.gnu.org/viewcvs/emacs/src/unexelf.c?cvsroot=emacs&r1=1.69&r2=1.70

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/src/ChangeLog,v
retrieving revision 1.7334
retrieving revision 1.7335
diff -u -b -r1.7334 -r1.7335
--- ChangeLog   2 Feb 2009 12:33:07 -0000       1.7334
+++ ChangeLog   2 Feb 2009 16:06:58 -0000       1.7335
@@ -1,3 +1,7 @@
+2009-02-02  Andreas Schwab  <address@hidden>
+
+       * unexelf.c (unexec): Handle unaligned bss offset.
+
 2009-02-01  Adrian Robert  <address@hidden>
 
        * nsterm.m (ns_read_socket): Copy 2009-01-29 and 2009-01-30

Index: unexelf.c
===================================================================
RCS file: /sources/emacs/emacs/src/unexelf.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -b -r1.69 -r1.70
--- unexelf.c   8 Jan 2009 03:16:02 -0000       1.69
+++ unexelf.c   2 Feb 2009 16:07:00 -0000       1.70
@@ -680,6 +680,8 @@
   ElfW(Word) old_bss_size, new_data2_size;
   ElfW(Off)  new_data2_offset;
   ElfW(Addr) new_data2_addr;
+  ElfW(Off)  old_bss_offset;
+  ElfW(Word) new_data2_incr;
 
   int n, nn;
   int old_bss_index, old_sbss_index, old_plt_index;
@@ -754,6 +756,7 @@
     {
       old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr;
       old_bss_size = OLD_SECTION_H (old_bss_index).sh_size;
+      old_bss_offset = OLD_SECTION_H (old_bss_index).sh_offset;
       new_data2_index = old_bss_index;
     }
   else if (old_plt_index != -1
@@ -766,6 +769,7 @@
        + OLD_SECTION_H (old_plt_index).sh_size;
       if (old_sbss_index != -1)
        old_bss_size += OLD_SECTION_H (old_sbss_index).sh_size;
+      old_bss_offset = OLD_SECTION_H (old_plt_index).sh_offset;
       new_data2_index = old_plt_index;
     }
   else
@@ -773,6 +777,7 @@
       old_bss_addr = OLD_SECTION_H (old_sbss_index).sh_addr;
       old_bss_size = OLD_SECTION_H (old_bss_index).sh_size
        + OLD_SECTION_H (old_sbss_index).sh_size;
+      old_bss_offset = OLD_SECTION_H (old_sbss_index).sh_offset;
       new_data2_index = old_sbss_index;
     }
 
@@ -789,17 +794,24 @@
 #endif
   new_data2_addr = old_bss_addr;
   new_data2_size = new_bss_addr - old_bss_addr;
-  new_data2_offset  = OLD_SECTION_H (old_data_index).sh_offset +
-    (new_data2_addr - OLD_SECTION_H (old_data_index).sh_addr);
+  new_data2_offset = OLD_SECTION_H (old_data_index).sh_offset
+    + (new_data2_addr - OLD_SECTION_H (old_data_index).sh_addr);
+  /* This is the amount by which the sections following the bss sections
+     must be shifted in the image.  It can differ from new_data2_size if
+     the end of the old .data section (and thus the offset of the .bss
+     section) was unaligned.  */
+  new_data2_incr = new_data2_size + (new_data2_offset - old_bss_offset);
 
 #ifdef DEBUG
   fprintf (stderr, "old_bss_index %d\n", old_bss_index);
   fprintf (stderr, "old_bss_addr %x\n", old_bss_addr);
   fprintf (stderr, "old_bss_size %x\n", old_bss_size);
+  fprintf (stderr, "old_bss_offset %x\n", old_bss_offset);
   fprintf (stderr, "new_bss_addr %x\n", new_bss_addr);
   fprintf (stderr, "new_data2_addr %x\n", new_data2_addr);
   fprintf (stderr, "new_data2_size %x\n", new_data2_size);
   fprintf (stderr, "new_data2_offset %x\n", new_data2_offset);
+  fprintf (stderr, "new_data2_incr %x\n", new_data2_incr);
 #endif
 
   if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size)
@@ -813,7 +825,7 @@
   if (new_file < 0)
     fatal ("Can't creat (%s): errno %d\n", new_name, errno);
 
-  new_file_size = stat_buf.st_size + old_file_h->e_shentsize + new_data2_size;
+  new_file_size = stat_buf.st_size + old_file_h->e_shentsize + new_data2_incr;
 
   if (ftruncate (new_file, new_file_size))
     fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);
@@ -826,7 +838,7 @@
   new_file_h = (ElfW(Ehdr) *) new_base;
   new_program_h = (ElfW(Phdr) *) ((byte *) new_base + old_file_h->e_phoff);
   new_section_h = (ElfW(Shdr) *)
-    ((byte *) new_base + old_file_h->e_shoff + new_data2_size);
+    ((byte *) new_base + old_file_h->e_shoff + new_data2_incr);
 
   /* Make our new file, program and section headers as copies of the
      originals.  */
@@ -841,7 +853,7 @@
   /* Fix up file header.  We'll add one section.  Section header is
      further away now.  */
 
-  new_file_h->e_shoff += new_data2_size;
+  new_file_h->e_shoff += new_data2_incr;
   new_file_h->e_shnum += 1;
 
 #ifdef DEBUG
@@ -901,7 +913,7 @@
        NEW_PROGRAM_H (n).p_vaddr += new_data2_size - old_bss_size;
 
       if (NEW_PROGRAM_H (n).p_offset >= new_data2_offset)
-       NEW_PROGRAM_H (n).p_offset += new_data2_size;
+       NEW_PROGRAM_H (n).p_offset += new_data2_incr;
     }
 #endif
 
@@ -957,10 +969,8 @@
          )
        {
          /* NN should be `old_s?bss_index + 1' at this point. */
-         NEW_SECTION_H (nn).sh_offset =
-           NEW_SECTION_H (new_data2_index).sh_offset + new_data2_size;
-         NEW_SECTION_H (nn).sh_addr =
-           NEW_SECTION_H (new_data2_index).sh_addr + new_data2_size;
+         NEW_SECTION_H (nn).sh_offset = new_data2_offset + new_data2_size;
+         NEW_SECTION_H (nn).sh_addr = new_data2_addr + new_data2_size;
          /* Let the new bss section address alignment be the same as the
             section address alignment followed the old bss section, so
             this section will be placed in exactly the same place. */
@@ -970,16 +980,15 @@
       else
        {
          /* Any section that was originally placed after the .bss
-            section should now be off by NEW_DATA2_SIZE.  If a
+            section should now be off by NEW_DATA2_INCR.  If a
             section overlaps the .bss section, consider it to be
             placed after the .bss section.  Overlap can occur if the
             section just before .bss has less-strict alignment; this
             was observed between .symtab and .bss on Solaris 2.5.1
             (sparc) with GCC snapshot 960602.  */
 
-         if (NEW_SECTION_H (nn).sh_offset + NEW_SECTION_H (nn).sh_size
-             > new_data2_offset)
-           NEW_SECTION_H (nn).sh_offset += new_data2_size;
+         if (NEW_SECTION_H (nn).sh_offset >= old_bss_offset)
+           NEW_SECTION_H (nn).sh_offset += new_data2_incr;
 
          /* Any section that was originally placed after the section
             header table should now be off by the size of one section




reply via email to

[Prev in Thread] Current Thread [Next in Thread]