--- bfd/coffcode.h.orig	Mon Jul  8 05:34:08 2002
+++ bfd/coffcode.h	Wed Aug  7 15:01:26 2002
@@ -3372,6 +3372,10 @@
 
 #endif /* COFF_IMAGE_WITH_PE */
 
+#if defined (__MSDOS__)
+#define COFF_PAD_SECTION_HEADERS
+#endif
+
 /* SUPPRESS 558 */
 /* SUPPRESS 529 */
 static boolean
@@ -3759,6 +3763,19 @@
 #endif
 #endif
 
+#ifdef COFF_PAD_SECTION_HEADERS
+  if ((abfd->flags & EXEC_P) != 0)
+    {
+      file_ptr cur_ptr = scn_base
+                         + abfd->section_count * bfd_coff_scnhsz (abfd);
+      long fill_size = (abfd->sections->filepos - cur_ptr);
+      bfd_byte *b = bfd_zmalloc (fill_size);
+      if (b)
+        bfd_bwrite ((PTR)b, fill_size, abfd);
+      free (b);
+    }
+#endif
+
   /* OK, now set up the filehdr...  */
 
   /* Don't include the internal abs section in the section count */
*** gas/write.c.orig	Sat Jun  8 03:37:14 2002
--- gas/write.c	Tue Aug 13 14:36:32 2002
*************** set_segment_vma (abfd, sec, xxx)
*** 1419,1429 ****
       PTR xxx ATTRIBUTE_UNUSED;
  {
    static bfd_vma addr = 0;
  
!   bfd_set_section_vma (abfd, sec, addr);
!   addr += bfd_section_size (abfd, sec);
  }
! #endif /* BFD_ASSEMBLER && OBJ_COFF && !TE_PE  */
  
  /* Finish the subsegments.  After every sub-segment, we fake an
     ".align ...".  This conforms to BSD4.2 brane-damage.  We then fake
--- 1419,1456 ----
       PTR xxx ATTRIBUTE_UNUSED;
  {
    static bfd_vma addr = 0;
+   flagword flags;
+   int debug_section, maybe_debug_section;
  
!   flags = bfd_get_section_flags (abfd, sec);
!   debug_section = (flags & SEC_DEBUGGING) != 0;
! 
!   /* SEC_DEBUGGING may not be set for DWARF2 sections.
!      Check for them by name to be certain.  */
!   maybe_debug_section = (flags & SEC_ALLOC) == 0
!                         && (flags & SEC_HAS_CONTENTS) != 0;
! 
!   /* Set the vma of debugging sections to zero to keep
!      BFD's DWARF2 reader from complaining about bad data
!      when an undefined symbol is reported by the linker.  */
!   if (!debug_section && maybe_debug_section)
!     {
!       const char *sec_name = bfd_get_section_name (abfd, sec);
!       if (strncmp (sec_name, ".debug", 6) == 0
!           || strncmp (sec_name, ".gnu.linkonce.wi.", 17) == 0)
!             debug_section = 1;
!     }
! 
!   if (debug_section)
!     {
!       bfd_set_section_vma (abfd, sec, 0);
!       return;
!     }
! 
!     bfd_set_section_vma (abfd, sec, addr);
!     addr += bfd_section_size (abfd, sec);
  }
! #endif /* BFD_ASSEMBLER && OBJ_COFF && !TE_GO32  */
  
  /* Finish the subsegments.  After every sub-segment, we fake an
     ".align ...".  This conforms to BSD4.2 brane-damage.  We then fake




--- bfd/bfdio.c~1	2003-06-12 21:43:10.000000000 +0000
+++ bfd/bfdio.c	2003-06-12 21:46:38.000000000 +0000
@@ -325,6 +325,29 @@ bfd_seek (abfd, position, direction)
   if (direction == SEEK_SET && abfd->my_archive != NULL)
     file_position += abfd->origin;
 
+#ifdef __DJGPP__
+  /* Temporary workaround for DOS fill with garbage on
+     seek over file end bug  */
+  if (direction == SEEK_SET)
+    {
+        fseek (f, 0, SEEK_END);
+        result = ftell (f);
+        if (result < file_position)
+        {
+            char tmp[128];
+            int length, len2;
+            memset (tmp, 0, 128);
+            length = file_position - result;
+            /* Don't fill for too far seeks  */
+            while (length > 0 && length<16384)
+              {
+                  int len2 = length>128 ? 128 : length;
+                  fwrite (tmp, 1, len2, f);
+		  length -= len2;
+              }
+        }
+    }
+#endif
   result = fseek (f, file_position, direction);
   if (result != 0)
     {
