[Gd-chatter] r11489 - trunk/fundev/sources/harp/coff-manager

andreas at gwydiondylan.org andreas at gwydiondylan.org
Wed Nov 14 04:33:41 CET 2007


Author: andreas
Date: Wed Nov 14 04:33:41 2007
New Revision: 11489

Modified:
   trunk/fundev/sources/harp/coff-manager/coff-sizes.dylan
   trunk/fundev/sources/harp/coff-manager/coff-writer.dylan
Log:
job: fd

Support for more than 64k relocations per section in COFF
object files.


Modified: trunk/fundev/sources/harp/coff-manager/coff-sizes.dylan
==============================================================================
--- trunk/fundev/sources/harp/coff-manager/coff-sizes.dylan	(original)
+++ trunk/fundev/sources/harp/coff-manager/coff-sizes.dylan	Wed Nov 14 04:33:41 2007
@@ -118,11 +118,19 @@
 
 define method total-relocation-size 
     (section :: <coff-section>) => (size :: <integer>)
-  reduce(method (val :: <integer>, reloc :: <coff-relocation>)
-           val + reloc.unit-size
-         end method,
-         0,
-         section.relocations);
+  let reloc-size =
+    reduce(method (val :: <integer>, reloc :: <coff-relocation>)
+             val + reloc.unit-size
+           end method,
+           0,
+           section.relocations);
+  if (section.relocations.size > 65535)
+    // COFF section header only allows SHORT for number
+    // of relocations, so we need an ugly hack
+    reloc-size + section.relocations.first.unit-size
+  else
+    reloc-size
+  end
 end method;
 
 

Modified: trunk/fundev/sources/harp/coff-manager/coff-writer.dylan
==============================================================================
--- trunk/fundev/sources/harp/coff-manager/coff-writer.dylan	(original)
+++ trunk/fundev/sources/harp/coff-manager/coff-writer.dylan	Wed Nov 14 04:33:41 2007
@@ -72,6 +72,11 @@
   end for;
 end method;
 
+// When there are more than 64k relocation entries, we need to set a flag
+// and write the actual number of relocations into the virtual address
+// of the first relocation.  See:
+//   http://msdn2.microsoft.com/en-us/library/ms680341.aspx
+//
 define method write-coff-section-header
      (stream :: <stream>, coff-file :: <coff-file>, 
       section :: <coff-section>, base :: <integer>) => ()
@@ -88,9 +93,11 @@
   write-word(stream, coff-file, base-of-raw-data);
   write-word(stream, coff-file, if (reloc-size > 0) base-of-relocs else 0 end); 
   write-word(stream, coff-file, if (lines-size > 0) base-of-lines  else 0 end); 
-  write-short(stream, coff-file, reloc-size);
+  write-short(stream, coff-file, min(65535, reloc-size)); // $lnk-nreloc-ovfl
   write-short(stream, coff-file, lines-size);
-  write-word(stream, coff-file, section.section-flags);
+  write-word(stream,
+             coff-file,
+             generic-+(section.section-flags, if (reloc-size > 65535) $lnk-nreloc-ovfl else 0 end));
 end method;
 
 
@@ -136,6 +143,13 @@
 define method write-relocations
     (stream :: <stream>,  coff-file :: <coff-file>, section :: <coff-section>)
     => ()
+  if (section.relocations.size > 65535)
+    // overflow of SHORT header field for number of
+    // relocations.  See write-coff-section-header above.
+    write-word(stream, coff-file, section.relocations.size);
+    write-word(stream, coff-file, 0);
+    write-short(stream, coff-file, 0);
+  end;
   for (reloc :: <coff-relocation> in section.relocations)
     write-relocation(stream, coff-file, reloc);
   end for;
@@ -255,7 +269,8 @@
   end for;
 end method;
 
-
+// no support for more than 64k relocations.  Fortunately,
+// we don't use this.
 define method write-one-symbol
      (stream :: <stream>, 
       coff-file :: <coff-file>, 



More information about the chatter mailing list