winnt.c (DLL_IMPORT_PREFIX): New define.
authorDanny Smith <dannysmith@users.sourceforge.net>
Wed, 12 Mar 2003 08:59:29 +0000 (08:59 +0000)
committerDanny Smith <dannysmith@gcc.gnu.org>
Wed, 12 Mar 2003 08:59:29 +0000 (08:59 +0000)
* config/i386/winnt.c (DLL_IMPORT_PREFIX): New define.
Use throughout instead of DLL_IMPORT_EXPORT_PREFIX and "e."
(DLL_EXPORT_PREFIX): New define. Use throughout instead of
DLL_IMPORT_EXPORT_PREFIX and "i."
(i386_pe_dllexport_name_p): Here.
(i386_pe_dllimport_name_p): Here.
        (i386_pe_mark_dllexport): Here. Remove DLL_IMPORT_PREFIX,
not 9 chars when getting identifier name.
(i386_pe_mark_dllimport): Here.
(i386_pe_encode_section_info): Here. Remove DLL_IMPORT_PREFIX,
not 9 chars when getting identifier name. Correct comment.
(i386_pe_strip_name_encoding): Here. Add comments for different
cases.
(gen_fastcall_suffix): Break down xmalloc() argument to
components.
(gen_stdcall_suffix): Likewise.
Update copyright year.

From-SVN: r64227

gcc/ChangeLog
gcc/config/i386/winnt.c

index a494fa76bb0718fafe53ee541707e6ce10f241cc..5d8f291dc9d9f0f4e2b64454cab00477a0d32fc8 100644 (file)
@@ -1,3 +1,23 @@
+2003-03-12  Danny Smith  <dannysmith@users.sourceforge.net>
+       * config/i386/winnt.c (DLL_IMPORT_PREFIX): New define.
+       Use throughout instead of DLL_IMPORT_EXPORT_PREFIX and "e."
+       (DLL_EXPORT_PREFIX): New define. Use throughout instead of
+       DLL_IMPORT_EXPORT_PREFIX and "i."
+       (i386_pe_dllexport_name_p): Here.
+       (i386_pe_dllimport_name_p): Here.
+        (i386_pe_mark_dllexport): Here. Remove DLL_IMPORT_PREFIX,
+       not 9 chars when getting identifier name.
+       (i386_pe_mark_dllimport): Here.
+       (i386_pe_encode_section_info): Here. Remove DLL_IMPORT_PREFIX,
+       not 9 chars when getting identifier name. Correct comment.
+       (i386_pe_strip_name_encoding): Here. Add comments for different
+       cases.
+       (gen_fastcall_suffix): Break down xmalloc() argument to
+       components.
+       (gen_stdcall_suffix): Likewise.
+       Update copyright year.
+
 2003-03-12  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        PR optimization/9888
index 846776139476ad1e5a9adada66ffff04481e76f8..566e75fbda68ddf656174303d56151173bfc0d1a 100644 (file)
@@ -1,6 +1,6 @@
 /* Subroutines for insn-output.c for Windows NT.
    Contributed by Douglas Rupp (drupp@cs.washington.edu)
-   Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002
+   Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
 
 This file is part of GNU CC.
@@ -54,6 +54,15 @@ int i386_pe_dllimport_p PARAMS ((tree));
 void i386_pe_mark_dllexport PARAMS ((tree));
 void i386_pe_mark_dllimport PARAMS ((tree));
 
+/* This is we how mark internal identifiers with dllimport or dllexport
+   attributes.  */
+#ifndef DLL_IMPORT_PREFIX
+#define DLL_IMPORT_PREFIX "#i."
+#endif
+#ifndef DLL_EXPORT_PREFIX
+#define DLL_EXPORT_PREFIX "#e."
+#endif
+
 /* Handle a "dllimport" or "dllexport" attribute;
    arguments as in struct attribute_spec.handler.  */
 tree
@@ -202,8 +211,8 @@ int
 i386_pe_dllexport_name_p (symbol)
      const char *symbol;
 {
-  return symbol[0] == DLL_IMPORT_EXPORT_PREFIX
-         && symbol[1] == 'e' && symbol[2] == '.';
+  return (strncmp (DLL_EXPORT_PREFIX, symbol,
+                  strlen (DLL_EXPORT_PREFIX)) == 0);
 }
 
 /* Return nonzero if SYMBOL is marked as being dllimport'd.  */
@@ -212,8 +221,8 @@ int
 i386_pe_dllimport_name_p (symbol)
      const char *symbol;
 {
-  return symbol[0] == DLL_IMPORT_EXPORT_PREFIX
-         && symbol[1] == 'i' && symbol[2] == '.';
+  return (strncmp (DLL_IMPORT_PREFIX, symbol,
+                  strlen (DLL_IMPORT_PREFIX)) == 0);
 }
 
 /* Mark a DECL as being dllexport'd.
@@ -237,12 +246,13 @@ i386_pe_mark_dllexport (decl)
   else
     abort ();
   if (i386_pe_dllimport_name_p (oldname))
-    oldname += 9;
+    /* Remove DLL_IMPORT_PREFIX.  */
+    oldname += strlen (DLL_IMPORT_PREFIX);
   else if (i386_pe_dllexport_name_p (oldname))
     return; /* already done */
 
-  newname = alloca (strlen (oldname) + 4);
-  sprintf (newname, "%ce.%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
+  newname = alloca (strlen (DLL_EXPORT_PREFIX) + strlen (oldname) + 1);
+  sprintf (newname, "%s%s", DLL_EXPORT_PREFIX, oldname);
 
   /* We pass newname through get_identifier to ensure it has a unique
      address.  RTL processing can sometimes peek inside the symbol ref
@@ -316,8 +326,8 @@ i386_pe_mark_dllimport (decl)
       return;
     }
 
-  newname = alloca (strlen (oldname) + 4);
-  sprintf (newname, "%ci.%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
+  newname = alloca (strlen (DLL_IMPORT_PREFIX) + strlen (oldname) + 1);
+  sprintf (newname, "%s%s", DLL_IMPORT_PREFIX, oldname);
 
   /* We pass newname through get_identifier to ensure it has a unique
      address.  RTL processing can sometimes peek inside the symbol ref
@@ -366,7 +376,8 @@ gen_fastcall_suffix (decl)
          }
       }
 
-  newsym = xmalloc (strlen (asmname) + 11);
+  /* Assume max of 8 base 10 digits in the suffix.  */ 
+  newsym = xmalloc (1 + strlen (asmname) + 1 + 8 + 1);
   sprintf (newsym, "%c%s@%d", FASTCALL_PREFIX, asmname, total/BITS_PER_UNIT);
   return IDENTIFIER_POINTER (get_identifier (newsym));
 }
@@ -404,7 +415,8 @@ gen_stdcall_suffix (decl)
          }
       }
 
-  newsym = xmalloc (strlen (asmname) + 10);
+  /* Assume max of 8 base 10 digits in the suffix.  */ 
+  newsym = xmalloc (strlen (asmname) + 1 + 8 + 1);
   sprintf (newsym, "%s@%d", asmname, total/BITS_PER_UNIT);
   return IDENTIFIER_POINTER (get_identifier (newsym));
 }
@@ -447,8 +459,8 @@ i386_pe_encode_section_info (decl, first)
     i386_pe_mark_dllimport (decl);
   /* It might be that DECL has already been marked as dllimport, but a
      subsequent definition nullified that.  The attribute is gone but
-     DECL_RTL still has (DLL_IMPORT_EXPORT_PREFIX)i._imp__foo.  We need
-     to remove that. Ditto for the DECL_NON_ADDR_CONST_P flag.  */
+     DECL_RTL still has (DLL_IMPORT_PREFIX) prefixed. We need to remove
+     that. Ditto for the DECL_NON_ADDR_CONST_P flag.  */
   else if ((TREE_CODE (decl) == FUNCTION_DECL
            || TREE_CODE (decl) == VAR_DECL)
           && DECL_RTL (decl) != NULL_RTX
@@ -458,7 +470,8 @@ i386_pe_encode_section_info (decl, first)
           && i386_pe_dllimport_name_p (XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0)))
     {
       const char *oldname = XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0);
-      tree idp = get_identifier (oldname + 9);
+      /* Remove DLL_IMPORT_PREFIX.  */
+      tree idp = get_identifier (oldname + strlen (DLL_IMPORT_PREFIX));
       rtx newrtl = gen_rtx (SYMBOL_REF, Pmode, IDENTIFIER_POINTER (idp));
 
       XEXP (DECL_RTL (decl), 0) = newrtl;
@@ -477,8 +490,12 @@ const char *
 i386_pe_strip_name_encoding (str)
      const char *str;
 {
-  if (*str == DLL_IMPORT_EXPORT_PREFIX)
-    str += 3;
+  if (strncmp (str, DLL_IMPORT_PREFIX, strlen (DLL_IMPORT_PREFIX))
+      == 0)
+    str += strlen (DLL_IMPORT_PREFIX);
+  else if (strncmp (str, DLL_EXPORT_PREFIX, strlen (DLL_EXPORT_PREFIX))
+          == 0)
+    str += strlen (DLL_EXPORT_PREFIX);
   if (*str == '*')
     str += 1;
   return str;
@@ -508,30 +525,34 @@ void i386_pe_output_labelref (stream, name)
      FILE *stream;
      const char *name;
 {
-  char prefix[4];
-
-  sprintf (prefix, "%ci.", DLL_IMPORT_EXPORT_PREFIX);
-  if (strncmp (name, prefix, strlen (prefix)) == 0)
-    {
-      if (name[3] == FASTCALL_PREFIX)
+  if (strncmp (name, DLL_IMPORT_PREFIX, strlen (DLL_IMPORT_PREFIX))
+      == 0)
+   /* A dll import */ 
+   {
+      if (name[strlen (DLL_IMPORT_PREFIX)] == FASTCALL_PREFIX)
+      /* A dllimport fastcall symbol.  */   
         {
           fprintf (stream, "__imp_%s",
                    i386_pe_strip_name_encoding (name));
         }
       else
+      /* A dllimport non-fastcall symbol.  */ 
         {
           fprintf (stream, "__imp__%s",
                    i386_pe_strip_name_encoding (name));
         }
     }
   else if ((name[0] == FASTCALL_PREFIX)
-           || ((name[0] == DLL_IMPORT_EXPORT_PREFIX)
-               && (name[3] == FASTCALL_PREFIX)))
+           || (strncmp (name, DLL_EXPORT_PREFIX, strlen (DLL_EXPORT_PREFIX)
+              == 0 
+              && name[strlen (DLL_EXPORT_PREFIX)] == FASTCALL_PREFIX)))
+    /* A fastcall symbol.  */
     {
       fprintf (stream, "%s",
                i386_pe_strip_name_encoding (name));
     }
   else
+    /* Everything else.  */
     {
       fprintf (stream, "%s%s", USER_LABEL_PREFIX,
                i386_pe_strip_name_encoding (name));