2009-11-04 Kai Tietz <kai.tietz@onevision.com>
authorKai Tietz <kai.tietz@onevision.com>
Wed, 4 Nov 2009 18:13:05 +0000 (18:13 +0000)
committerKai Tietz <kai.tietz@onevision.com>
Wed, 4 Nov 2009 18:13:05 +0000 (18:13 +0000)
        * emulparams/arm_epoc_pe.sh: Remove ENTRY.
        * emulparams/arm_wince_pe.sh: Likewise.
        * emulparams/i386pe.sh: Likewise.
        * emulparams/i386pe_posix.sh: Likewise.
        * emulparams/mcorepe.sh: Likewise.
        * emulparams/mipspe.sh: Likewise.
        * emulparams/ppcpe.sh: Likewise.
        * emulparams/armpe.sh: Likewise.
        * emulparams/i386pep.sh: Likewise.
        * emulparams/shpe.sh: Likewise.
        Additionally cleaned up double-defined
        variables SUBSYSTEM and INITIAL_SYMBOL_CHAR.
        * emultempl/pe.em: Remove use of ENTRY.
        (pe_subsystem): New local variable.
        (gld_XXX_before_parse): Don't set default
        entry point here.
        (set_entry_point): New function to set entry
        point.
        (set_pe_subsystem): Remove code for entry point.
        (gld_XXX_after_parse): Use set_entry_point here.
        * emultempl/pep.em: Likewise.

13 files changed:
ld/ChangeLog
ld/emulparams/arm_epoc_pe.sh
ld/emulparams/arm_wince_pe.sh
ld/emulparams/armpe.sh
ld/emulparams/i386pe.sh
ld/emulparams/i386pe_posix.sh
ld/emulparams/i386pep.sh
ld/emulparams/mcorepe.sh
ld/emulparams/mipspe.sh
ld/emulparams/ppcpe.sh
ld/emulparams/shpe.sh
ld/emultempl/pe.em
ld/emultempl/pep.em

index 90fa7423c208c4cc8c83edda76c3c80b236413ec..c901357888fcd9433f30d2cb887d49484e687697 100644 (file)
@@ -1,3 +1,27 @@
+2009-11-04  Kai Tietz  <kai.tietz@onevision.com>
+
+       * emulparams/arm_epoc_pe.sh: Remove ENTRY.
+       * emulparams/arm_wince_pe.sh: Likewise.
+       * emulparams/i386pe.sh: Likewise.
+       * emulparams/i386pe_posix.sh: Likewise.
+       * emulparams/mcorepe.sh: Likewise.
+       * emulparams/mipspe.sh: Likewise.
+       * emulparams/ppcpe.sh: Likewise.
+       * emulparams/armpe.sh: Likewise.
+       * emulparams/i386pep.sh: Likewise.
+       * emulparams/shpe.sh: Likewise.
+       Additionally cleaned up double-defined
+       variables SUBSYSTEM and INITIAL_SYMBOL_CHAR.
+       * emultempl/pe.em: Remove use of ENTRY.
+       (pe_subsystem): New local variable.
+       (gld_XXX_before_parse): Don't set default
+       entry point here.
+       (set_entry_point): New function to set entry
+       point.
+       (set_pe_subsystem): Remove code for entry point.
+       (gld_XXX_after_parse): Use set_entry_point here.
+       * emultempl/pep.em: Likewise.
+
 2009-10-29  Nathan Sidwell  <nathan@codesourcery.com>
 
        * emulparams/vxworks.sh (OTHER_READONLY_SECTIONS): Move into ...
index 7cc4b220faeb9b4b2fde8f803af36db91f4fd0d2..51a3f764c7afbec763210e17f4ef1ed3f8af68d7 100644 (file)
@@ -4,7 +4,6 @@ OUTPUT_FORMAT="epoc-pei-arm-little"
 LITTLE_OUTPUT_FORMAT="epoc-pei-arm-little"
 BIG_OUTPUT_FORMAT="epoc-pei-arm-big"
 TEMPLATE_NAME=pe
-ENTRY="_mainCRTStartup"
 SUBSYSTEM=PE_DEF_SUBSYSTEM
 INITIAL_SYMBOL_CHAR=\"_\"
 TARGET_PAGE_SIZE=0x1000
index 2d0019fc47aff7a3d2e953037f69381dd7c99b83..133a51c2f9022f5a42e9df7b7d60820bdb0c1ba1 100644 (file)
@@ -8,7 +8,6 @@ BIG_OUTPUT_FORMAT="pei-arm-wince-big"
 RELOCATEABLE_OUTPUT_FORMAT="pe-arm-wince-little"
 
 TEMPLATE_NAME=pe
-ENTRY="WinMainCRTStartup"
 SUBSYSTEM=PE_DEF_SUBSYSTEM
 INITIAL_SYMBOL_CHAR=\"\"
 TARGET_PAGE_SIZE=0x1000
index 5db5faf3468d89b4779f57763f26cb9ad949338c..0c711a5975ce4f74acc503da9f5b047b40eeec75 100644 (file)
@@ -8,7 +8,6 @@ BIG_OUTPUT_FORMAT="pei-arm-big"
 RELOCATEABLE_OUTPUT_FORMAT="pe-arm-little"
 
 TEMPLATE_NAME=pe
-ENTRY="_mainCRTStartup"
 SUBSYSTEM=PE_DEF_SUBSYSTEM
 INITIAL_SYMBOL_CHAR=\"_\"
 
index ecafd698e0ffa50ef5eef48f75d00c7a56b523fc..38191ecb24c15f1f885fdad570e3aa464937292a 100644 (file)
@@ -3,7 +3,6 @@ SCRIPT_NAME=pe
 OUTPUT_FORMAT="pei-i386"
 RELOCATEABLE_OUTPUT_FORMAT="pe-i386"
 TEMPLATE_NAME=pe
-ENTRY="_mainCRTStartup"
 SUBSYSTEM=PE_DEF_SUBSYSTEM
 INITIAL_SYMBOL_CHAR=\"_\"
 TARGET_PAGE_SIZE=0x1000
index 9348e648c7e143acfe0ce353a23f0cd8078ca97b..cde0349765debf9d5a9e804e690783d4bb34eeab 100644 (file)
@@ -3,7 +3,6 @@ SCRIPT_NAME=pe
 OUTPUT_FORMAT="pei-i386"
 RELOCATEABLE_OUTPUT_FORMAT="pe-i386"
 TEMPLATE_NAME=pe
-ENTRY="___PosixProcessStartup"
 SUBSYSTEM=7
 EXECUTABLE_NAME=a.out
 INITIAL_SYMBOL_CHAR=\"_\"
index 7145f355394d260056a6a03893b1ee93505bf1af..76a980287c744fe266f63b65ee8cbc69d234b0e2 100644 (file)
@@ -3,7 +3,6 @@ SCRIPT_NAME=pep
 OUTPUT_FORMAT="pei-x86-64"
 RELOCATEABLE_OUTPUT_FORMAT="pe-x86-64"
 TEMPLATE_NAME=pep
-ENTRY="_mainCRTStartup"
 SUBSYSTEM=PE_DEF_SUBSYSTEM
 INITIAL_SYMBOL_CHAR=\"_\"
 TARGET_PAGE_SIZE=0x1000
index 8326c2e514426883530d1284ba4c5955f8258f85..95d84e7f0499b903d8bb3c2646c83e758ab67df9 100644 (file)
@@ -4,7 +4,6 @@ OUTPUT_FORMAT="pei-mcore-little"
 LITTLE_OUTPUT_FORMAT="pei-mcore-little"
 BIG_OUTPUT_FORMAT="pei-mcore-big"
 TEMPLATE_NAME=pe
-ENTRY="_mainCRTStartup"
 SUBSYSTEM=PE_DEF_SUBSYSTEM
 INITIAL_SYMBOL_CHAR=\"_\"
 TARGET_PAGE_SIZE=0x1000
index a5cfc2ef60e4ad1eb90e9bfe5bb87ad89060b59c..95c4adb71a737779a42f845a9cb1671508df5935 100644 (file)
@@ -6,5 +6,4 @@ RELOCATEABLE_OUTPUT_FORMAT="ecoff-littlemips"
 TEMPLATE_NAME=pe
 SUBSYSTEM=PE_DEF_SUBSYSTEM
 INITIAL_SYMBOL_CHAR=\"_\"
-ENTRY="_mainCRTStartup"
 TARGET_PAGE_SIZE=0x1000
index 2e1e10207c8895879903ccb15b02511b4428a06f..ed7df88dcd262bc7e95505999fa63a497b0ef994 100644 (file)
@@ -2,7 +2,6 @@ ARCH=powerpc
 SCRIPT_NAME=ppcpe
 OUTPUT_FORMAT="pei-powerpcle"
 TEMPLATE_NAME=pe
-ENTRY="_mainCRTStartup"
 SUBSYSTEM=PE_DEF_SUBSYSTEM
 INITIAL_SYMBOL_CHAR=\"_\"
 TARGET_PAGE_SIZE=0x1000
index d50861f55d5a8ca3ffdaed1c4811d0d22d3ddd73..89fa461efd0f868655a1ecffb59631b3d7936037 100644 (file)
@@ -4,7 +4,4 @@ OUTPUT_FORMAT="pei-shl"
 TEMPLATE_NAME=pe
 SUBSYSTEM=PE_DEF_SUBSYSTEM
 INITIAL_SYMBOL_CHAR=\"_\"
-ENTRY="_mainCRTStartup"
-SUBSYSTEM=PE_DEF_SUBSYSTEM
-INITIAL_SYMBOL_CHAR=\"_\"
 TARGET_PAGE_SIZE=0x1000
index d233bd1f9b001a136d97d4257e36b689c2b13610..f926502bb52d0ad3aa1e2b1b7e68b0495bfcc551 100644 (file)
@@ -1,6 +1,5 @@
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-test -z "${ENTRY}" && ENTRY="_mainCRTStartup"
 if [ -z "$MACHINE" ]; then
   OUTPUT_ARCH=${ARCH}
 else
@@ -122,6 +121,7 @@ fragment <<EOF
 
 static struct internal_extra_pe_aouthdr pe;
 static int dll;
+static int pe_subsystem = ${SUBSYSTEM};
 static flagword real_flags = 0;
 static int support_old_code = 0;
 static char * thumb_entry_symbol = NULL;
@@ -162,16 +162,6 @@ esac
 fragment <<EOF
   link_info.pei386_auto_import = ${default_auto_import};
   link_info.pei386_runtime_pseudo_reloc = 1; /* Use by default version 1.  */
-
-#if (PE_DEF_SUBSYSTEM == 9) || (PE_DEF_SUBSYSTEM == 2)
-#if defined TARGET_IS_mipspe || defined TARGET_IS_armpe || defined TARGET_IS_arm_wince_pe
-  lang_default_entry ("WinMainCRTStartup");
-#else
-  lang_default_entry ("_WinMainCRTStartup");
-#endif
-#else
-  lang_default_entry ("${ENTRY}");
-#endif
 #endif
 }
 \f
@@ -459,36 +449,95 @@ set_pe_name (char *name, long val)
   abort ();
 }
 
+static void
+set_entry_point (void)
+{
+  const char *entry;
+  const char *initial_symbol_char;
+  int i;
+
+  static const struct
+    {
+      const int value;
+      const char *entry;
+    }
+  v[] =
+    {
+      { 1, "NtProcessStartup"  },
+      { 2, "WinMainCRTStartup" },
+      { 3, "mainCRTStartup"    },
+      { 7, "__PosixProcessStartup"},
+      { 9, "WinMainCRTStartup" },
+      {14, "mainCRTStartup"    },
+      { 0, NULL          }
+    };
+
+  /* Entry point name for arbitrary subsystem numbers.  */
+  static const char default_entry[] = "mainCRTStartup";
+
+  if (link_info.shared || dll)
+    {
+#if defined (TARGET_IS_i386pe)
+      entry = "DllMainCRTStartup@12";
+#else
+      entry = "DllMainCRTStartup";
+#endif
+    }
+  else
+    {
+
+      for (i = 0; v[i].entry; i++)
+        if (v[i].value == pe_subsystem)
+          break;
+
+      /* If no match, use the default.  */
+      if (v[i].entry != NULL)
+        entry = v[i].entry;
+      else
+        entry = default_entry;
+    }
+
+  initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
+  if (*initial_symbol_char != '\0')
+    {
+      char *alc_entry;
+
+      /* lang_default_entry expects its argument to be permanently
+        allocated, so we don't free this string.  */
+      alc_entry = xmalloc (strlen (initial_symbol_char)
+                          + strlen (entry)
+                          + 1);
+      strcpy (alc_entry, initial_symbol_char);
+      strcat (alc_entry, entry);
+      entry = alc_entry;
+    }
+
+  lang_default_entry (entry);
+}
 
 static void
 set_pe_subsystem (void)
 {
   const char *sver;
-  const char *entry;
-  const char *initial_symbol_char;
   char *end;
   int len;
   int i;
-  int subsystem;
   unsigned long temp_subsystem;
   static const struct
     {
       const char *name;
       const int value;
-      const char *entry;
     }
   v[] =
     {
-      { "native",  1, "NtProcessStartup" },
-      { "windows", 2, "WinMainCRTStartup" },
-      { "console", 3, "mainCRTStartup" },
-      { "posix",   7, "__PosixProcessStartup"},
-      { "wince",   9, "WinMainCRTStartup" },
-      { "xbox",   14, "mainCRTStartup" },
-      { NULL, 0, NULL }
+      { "native",  1},
+      { "windows", 2},
+      { "console", 3},
+      { "posix",   7},
+      { "wince",   9},
+      { "xbox",   14},
+      { NULL, 0 }
     };
-  /* Entry point name for arbitrary subsystem numbers.  */
-  static const char default_entry[] = "mainCRTStartup";
 
   /* Check for the presence of a version number.  */
   sver = strchr (optarg, ':');
@@ -498,10 +547,10 @@ set_pe_subsystem (void)
     {
       len = sver - optarg;
       set_pe_name ("__major_subsystem_version__",
-                  strtoul (sver + 1, &end, 0));
+                   strtoul (sver + 1, &end, 0));
       if (*end == '.')
        set_pe_name ("__minor_subsystem_version__",
-                    strtoul (end + 1, &end, 0));
+                     strtoul (end + 1, &end, 0));
       if (*end != '\0')
        einfo (_("%P: warning: bad version number in -subsystem option\n"));
     }
@@ -515,14 +564,8 @@ set_pe_subsystem (void)
        if (v[i].value == (int) temp_subsystem)
          break;
 
-      /* If no match, use the default.  */
-      if (v[i].name != NULL)
-       entry = v[i].entry;
-      else
-       entry = default_entry;
-
       /* Use this subsystem.  */
-      subsystem = (int) temp_subsystem;
+      pe_subsystem = (int) temp_subsystem;
     }
   else
     {
@@ -538,28 +581,10 @@ set_pe_subsystem (void)
          return;
        }
 
-      entry = v[i].entry;
-      subsystem = v[i].value;
+      pe_subsystem = v[i].value;
     }
 
-  set_pe_name ("__subsystem__", subsystem);
-
-  initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
-  if (*initial_symbol_char != '\0')
-    {
-      char *alc_entry;
-
-      /* lang_default_entry expects its argument to be permanently
-        allocated, so we don't free this string.  */
-      alc_entry = xmalloc (strlen (initial_symbol_char)
-                          + strlen (entry)
-                          + 1);
-      strcpy (alc_entry, initial_symbol_char);
-      strcat (alc_entry, entry);
-      entry = alc_entry;
-    }
-
-  lang_default_entry (entry);
+  set_pe_name ("__subsystem__", pe_subsystem);
 
   return;
 }
@@ -889,6 +914,8 @@ gld_${EMULATION_NAME}_after_parse (void)
     einfo (_("%P: warning: --export-dynamic is not supported for PE "
       "targets, did you mean --export-all-symbols?\n"));
 
+  set_entry_point ();
+
   after_parse_default ();
 }
 
index 656ff4820510765109fbf5945666128174c52247..a7ea8e110a0a2d87cb8597ad5ca73069e88a9239 100644 (file)
@@ -1,6 +1,5 @@
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-test -z "${ENTRY}" && ENTRY="_mainCRTStartup"
 if [ -z "$MACHINE" ]; then
   OUTPUT_ARCH=${ARCH}
 else
@@ -102,6 +101,7 @@ fragment <<EOF
 
 static struct internal_extra_pe_aouthdr pep;
 static int dll;
+static int pep_subsystem = ${SUBSYSTEM};
 static flagword real_flags = IMAGE_FILE_LARGE_ADDRESS_AWARE;
 static int support_old_code = 0;
 static lang_assignment_statement_type *image_base_statement = 0;
@@ -127,12 +127,6 @@ gld_${EMULATION_NAME}_before_parse (void)
   config.has_shared = 1;
   link_info.pei386_auto_import = -1;
   link_info.pei386_runtime_pseudo_reloc = 2; /* Use by default version 2.  */
-
-#if (PE_DEF_SUBSYSTEM == 9) || (PE_DEF_SUBSYSTEM == 2)
-  lang_default_entry ("_WinMainCRTStartup");
-#else
-  lang_default_entry ("${ENTRY}");
-#endif
 #endif
 }
 \f
@@ -403,36 +397,90 @@ set_pep_name (char *name, bfd_vma val)
   abort ();
 }
 
+static void
+set_entry_point (void)
+{
+  const char *entry;
+  const char *initial_symbol_char;
+  int i;
+
+  static const struct
+    {
+      const int value;
+      const char *entry;
+    }
+  v[] =
+    {
+      { 1, "NtProcessStartup"  },
+      { 2, "WinMainCRTStartup" },
+      { 3, "mainCRTStartup"    },
+      { 7, "__PosixProcessStartup" },
+      { 9, "WinMainCRTStartup" },
+      {14, "mainCRTStartup"    },
+      { 0, NULL          }
+    };
+
+  /* Entry point name for arbitrary subsystem numbers.  */
+  static const char default_entry[] = "mainCRTStartup";
+
+  if (link_info.shared || dll)
+    {
+      entry = "DllMainCRTStartup";
+    }
+  else
+    {
+      for (i = 0; v[i].entry; i++)
+        if (v[i].value == pep_subsystem)
+          break;
+
+      /* If no match, use the default.  */
+      if (v[i].entry != NULL)
+        entry = v[i].entry;
+      else
+        entry = default_entry;
+    }
+
+  initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
+  if (*initial_symbol_char != '\0')
+    {
+      char *alc_entry;
+
+      /* lang_default_entry expects its argument to be permanently
+        allocated, so we don't free this string.  */
+      alc_entry = xmalloc (strlen (initial_symbol_char)
+                          + strlen (entry)
+                          + 1);
+      strcpy (alc_entry, initial_symbol_char);
+      strcat (alc_entry, entry);
+      entry = alc_entry;
+    }
+
+  lang_default_entry (entry);
+}
 
 static void
 set_pep_subsystem (void)
 {
   const char *sver;
-  const char *entry;
-  const char *initial_symbol_char;
   char *end;
   int len;
   int i;
-  int subsystem;
   unsigned long temp_subsystem;
   static const struct
     {
       const char *name;
       const int value;
-      const char *entry;
     }
   v[] =
     {
-      { "native",  1, "NtProcessStartup" },
-      { "windows", 2, "WinMainCRTStartup" },
-      { "console", 3, "mainCRTStartup" },
-      { "posix",   7, "__PosixProcessStartup"},
-      { "wince",   9, "_WinMainCRTStartup" },
-      { "xbox",   14, "mainCRTStartup" },
-      { NULL, 0, NULL }
+      { "native",  1 },
+      { "windows", 2 },
+      { "console", 3 },
+      { "posix",   7 },
+      { "wince",   9 },
+      { "xbox",   14 },
+      { NULL, 0 }
     };
-  /* Entry point name for arbitrary subsystem numbers.  */
-  static const char default_entry[] = "mainCRTStartup";
 
   /* Check for the presence of a version number.  */
   sver = strchr (optarg, ':');
@@ -459,14 +507,8 @@ set_pep_subsystem (void)
        if (v[i].value == (int) temp_subsystem)
          break;
 
-      /* If no match, use the default.  */
-      if (v[i].name != NULL)
-       entry = v[i].entry;
-      else
-       entry = default_entry;
-
       /* Use this subsystem.  */
-      subsystem = (int) temp_subsystem;
+      pep_subsystem = (int) temp_subsystem;
     }
   else
     {
@@ -482,28 +524,10 @@ set_pep_subsystem (void)
          return;
        }
 
-      entry = v[i].entry;
-      subsystem = v[i].value;
-    }
-
-  set_pep_name ("__subsystem__", subsystem);
-
-  initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
-  if (*initial_symbol_char != '\0')
-    {
-      char *alc_entry;
-
-      /* lang_default_entry expects its argument to be permanently
-        allocated, so we don't free this string.  */
-      alc_entry = xmalloc (strlen (initial_symbol_char)
-                          + strlen (entry)
-                          + 1);
-      strcpy (alc_entry, initial_symbol_char);
-      strcat (alc_entry, entry);
-      entry = alc_entry;
+      pep_subsystem = v[i].value;
     }
 
-  lang_default_entry (entry);
+  set_pep_name ("__subsystem__", pep_subsystem);
 
   return;
 }
@@ -827,6 +851,8 @@ gld_${EMULATION_NAME}_after_parse (void)
     einfo (_("%P: warning: --export-dynamic is not supported for PE+ "
       "targets, did you mean --export-all-symbols?\n"));
 
+  set_entry_point ();
+  
   after_parse_default ();
 }