diff src/unexcw.c @ 446:1ccc32a20af4 r21-2-38

Import from CVS: tag r21-2-38
author cvs
date Mon, 13 Aug 2007 11:37:21 +0200
parents 576fb035e263
children 3078fd1074e8
line wrap: on
line diff
--- a/src/unexcw.c	Mon Aug 13 11:36:20 2007 +0200
+++ b/src/unexcw.c	Mon Aug 13 11:37:21 2007 +0200
@@ -53,7 +53,11 @@
 ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)
 /* Note that all sections must be aligned on a 0x1000 boundary so
    this is the minimum size that our dummy bss can be. */
+#ifdef BROKEN_GDB
 #define BSS_PAD_SIZE	0x1000
+#else
+#define BSS_PAD_SIZE	0
+#endif
 
 /* To prevent zero-initialized variables from being placed into the bss
    section, use non-zero values to represent an uninitialized state.  */
@@ -121,7 +125,7 @@
     }
 
   if ((a_new = open (new_name, O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
-		     CREAT_MODE)) < 0)
+		     0755)) < 0)
     {
       PERROR (new_name);
     }
@@ -306,6 +310,9 @@
   lseek (a_new, 0, SEEK_SET);
   /* write file header */
   f_hdr.f_symptr += file_sz_change;
+#ifndef BROKEN_GDB
+  f_hdr.f_nscns--;
+#endif
 
   printf("writing file header\n");
   if (write(a_new, &f_hdr, sizeof(f_hdr)) != sizeof(f_hdr))
@@ -333,7 +340,7 @@
     {
       PERROR("failed to write text header");
     }
-
+#ifdef BROKEN_GDB
   /* Write small bss section. */
   if (!sections_reversed)
     {
@@ -345,7 +352,7 @@
 	  PERROR("failed to write bss header");
 	}
     }
-
+#endif
   /* write new data header */
   printf("writing .data header\n");
 
@@ -353,7 +360,7 @@
     {
       PERROR("failed to write data header");
     }
-
+#ifdef BROKEN_GDB
   /* Write small bss section. */
   if (sections_reversed)
     {
@@ -365,7 +372,7 @@
 	  PERROR("failed to write bss header");
 	}
     }
-
+#endif
   printf("writing following data header\n");
   f_nextdata.s_scnptr += file_sz_change;
   if (f_nextdata.s_lnnoptr != 0) f_nextdata.s_lnnoptr += file_sz_change;
@@ -392,7 +399,14 @@
 	  PERROR("failed to write data header");
 	}
     }
-
+#ifndef BROKEN_GDB
+  /* dump bss to maintain offsets */
+  memset(&f_bss, 0, sizeof(f_bss));
+  if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss))
+    {
+      PERROR("failed to write bss header");
+    }
+#endif
   size=lseek(a_new, 0, SEEK_CUR);
   CHECK_AOUT_POS(size);