]> code.delx.au - gnu-emacs/blobdiff - src/unexw32.c
(note_mouse_highlight): Return quickly if frame's
[gnu-emacs] / src / unexw32.c
index 4cdffac287d886f10d4e82e4c19df71b997b1745..0d150cf34dbb6e5a5d60fd7c98b8644b9e85a81b 100644 (file)
@@ -99,7 +99,7 @@ _start (void)
 {
   extern void mainCRTStartup (void);
 
-#if 0
+#if 1
   /* Give us a way to debug problems with crashes on startup when
      running under the MSVC profiler. */
   if (GetEnvironmentVariable ("EMACS_DEBUG", NULL, 0) > 0)
@@ -380,13 +380,31 @@ get_section_info (file_data *p_infile)
      area for the bss section, so we can make the new image the correct
      size.  */
 
-  data_start = my_begdata;
-  data_size = my_edata - my_begdata;
-  data_section = rva_to_section (PTR_TO_RVA (my_begdata), nt_header);
-  if (data_section != rva_to_section (PTR_TO_RVA (my_edata), nt_header))
+  /* We arrange for the Emacs initialized data to be in a separate
+     section if possible, because we cannot rely on my_begdata and
+     my_edata marking out the full extent of the initialized data, at
+     least on the Alpha where the linker freely reorders variables
+     across libraries.  If we can arrange for this, all we need to do is
+     find the start and size of the EMDATA section.  */
+  data_section = find_section ("EMDATA", nt_header);
+  if (data_section)
     {
-      printf ("Initialized data is not in a single section...bailing\n");
-      exit (1);
+      data_start = (char *) nt_header->OptionalHeader.ImageBase +
+       data_section->VirtualAddress;
+      data_size = data_section->Misc.VirtualSize;
+    }
+  else
+    {
+      /* Fallback on the old method if compiler doesn't support the
+         data_set #pragma (or its equivalent).  */
+      data_start = my_begdata;
+      data_size = my_edata - my_begdata;
+      data_section = rva_to_section (PTR_TO_RVA (my_begdata), nt_header);
+      if (data_section != rva_to_section (PTR_TO_RVA (my_edata), nt_header))
+       {
+         printf ("Initialized data is not in a single section...bailing\n");
+         exit (1);
+       }
     }
 
   /* As noted in lastfile.c, the Alpha (but not the Intel) MSVC linker
@@ -429,7 +447,11 @@ get_section_info (file_data *p_infile)
     - bss_section_static->SizeOfRawData;
 
   /* Combine the bss sections into one if they overlap.  */
+#ifdef _ALPHA_
+  overlap = 1;                 /* force all bss data to be dumped */
+#else
   overlap = 0;
+#endif
   if (bss_start < bss_start_static)
     {
       if (bss_start_static < bss_start + bss_size)
@@ -499,6 +521,14 @@ copy_executable_and_dump_data (file_data *p_infile,
 #define DST_TO_OFFSET()  PTR_TO_OFFSET (dst, p_outfile)
 #define ROUND_UP_DST(align) \
   (dst = p_outfile->file_base + ROUND_UP (DST_TO_OFFSET (), (align)))
+#define ROUND_UP_DST_AND_ZERO(align)                                           \
+  do {                                                                         \
+    unsigned char *newdst = p_outfile->file_base                               \
+      + ROUND_UP (DST_TO_OFFSET (), (align));                                  \
+    /* Zero the alignment slop; it may actually initialize real data.  */      \
+    memset (dst, 0, newdst - dst);                                             \
+    dst = newdst;                                                              \
+  } while (0)
 
   /* Copy the source image sequentially, ie. section by section after
      copying the headers and section table, to simplify the process of
@@ -522,13 +552,16 @@ copy_executable_and_dump_data (file_data *p_infile,
   COPY_CHUNK ("Copying section table...", section,
              nt_header->FileHeader.NumberOfSections * sizeof (*section));
 
+  /* Align the first section's raw data area, and set the header size
+     field accordingly.  */
+  ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment);
+  dst_nt_header->OptionalHeader.SizeOfHeaders = DST_TO_OFFSET ();
+
   for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
     {
       char msg[100];
       sprintf (msg, "Copying raw data for %s...", section->Name);
 
-      /* Align the section's raw data area.  */
-      ROUND_UP_DST (dst_nt_header->OptionalHeader.FileAlignment);
       dst_save = dst;
 
       /* Update the file-relative offset for this section's raw data (if
@@ -541,6 +574,8 @@ copy_executable_and_dump_data (file_data *p_infile,
       COPY_CHUNK
        (msg, OFFSET_TO_PTR (section->PointerToRawData, p_infile),
         section->SizeOfRawData);
+      /* Ensure alignment slop is zeroed.  */
+      ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment);
 
       /* Note that various sections below may be aliases.  */
       if (section == data_section)
@@ -608,13 +643,13 @@ copy_executable_and_dump_data (file_data *p_infile,
          dst_section->Characteristics |= IMAGE_SCN_CNT_INITIALIZED_DATA;
        }
 
+      /* Align the section's raw data area.  */
+      ROUND_UP_DST (dst_nt_header->OptionalHeader.FileAlignment);
+
       section++;
       dst_section++;
     }
 
-  /* Pad out the final section raw data area.  */
-  ROUND_UP_DST (dst_nt_header->OptionalHeader.FileAlignment);
-
   /* Copy remainder of source image.  */
   do
     section--;