Apply Bruno de Bus's patch to record the ARM mapping symbol state on a per-
[deliverable/binutils-gdb.git] / binutils / dlltool.c
index 84f369243d35b42b33d29d30436d25f7406476cb..5f921ae0954b4fcd7f1689cd1745308766c494a1 100644 (file)
@@ -1,5 +1,5 @@
 /* dlltool.c -- tool to generate stuff for PE style DLLs
 /* dlltool.c -- tool to generate stuff for PE style DLLs
-   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
    Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
@@ -49,7 +49,7 @@
 
    EXPORTS  ( (  ( <name1> [ = <name2> ] )
                | ( <name1> = <module-name> . <external-name>))
 
    EXPORTS  ( (  ( <name1> [ = <name2> ] )
                | ( <name1> = <module-name> . <external-name>))
-            [ @ <integer> ] [ NONAME ] [CONSTANT] [DATA] ) *
+            [ @ <integer> ] [ NONAME ] [CONSTANT] [DATA] [PRIVATE] ) *
    Declares name1 as an exported symbol from the
    DLL, with optional ordinal number <integer>.
    Or declares name1 as an alias (forward) of the function <external-name>
    Declares name1 as an exported symbol from the
    DLL, with optional ordinal number <integer>.
    Or declares name1 as an alias (forward) of the function <external-name>
@@ -60,7 +60,7 @@
    Declares that <external-name> or the exported function whoes ordinal number
    is <integer> is to be imported from the file <module-name>.  If
    <internal-name> is specified then this is the name that the imported
    Declares that <external-name> or the exported function whoes ordinal number
    is <integer> is to be imported from the file <module-name>.  If
    <internal-name> is specified then this is the name that the imported
-   function will be refered to in the body of the DLL.
+   function will be refereed to in the body of the DLL.
 
    DESCRIPTION <string>
    Puts <string> into output .exp file in the .rdata section
 
    DESCRIPTION <string>
    Puts <string> into output .exp file in the .rdata section
@@ -443,7 +443,7 @@ char *tmp_stub_buf;
 #define TMP_TAIL_O     dlltmp (&tmp_tail_o_buf, "%st.o")
 #define TMP_STUB       dlltmp (&tmp_stub_buf, "%ss")
 
 #define TMP_TAIL_O     dlltmp (&tmp_tail_o_buf, "%st.o")
 #define TMP_STUB       dlltmp (&tmp_stub_buf, "%ss")
 
-/* This bit of assemly does jmp * ....  */
+/* This bit of assembly does jmp * ....  */
 static const unsigned char i386_jtab[] =
 {
   0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90
 static const unsigned char i386_jtab[] =
 {
   0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90
@@ -643,7 +643,8 @@ typedef struct export
     const char *internal_name;
     int ordinal;
     int constant;
     const char *internal_name;
     int ordinal;
     int constant;
-    int noname;
+    int noname;                /* Don't put name in image file.  */
+    int private;       /* Don't put reference in import lib.  */
     int data;
     int hint;
     int forward;       /* Number of forward label, 0 means no forward.  */
     int data;
     int hint;
     int forward;       /* Number of forward label, 0 means no forward.  */
@@ -706,12 +707,12 @@ static void usage (FILE *, int);
 static void inform (const char *, ...);
 
 static char *
 static void inform (const char *, ...);
 
 static char *
-prefix_encode (char *start, unsigned code))
+prefix_encode (char *start, unsigned code)
 {
   static char alpha[26] = "abcdefghijklmnopqrstuvwxyz";
   static char buf[32];
   char *p;
 {
   static char alpha[26] = "abcdefghijklmnopqrstuvwxyz";
   static char buf[32];
   char *p;
-  strcpy (buf, start;
+  strcpy (buf, start);
   p = strchr (buf, '\0');
   do
     *p++ = alpha[code % sizeof (alpha)];
   p = strchr (buf, '\0');
   do
     *p++ = alpha[code % sizeof (alpha)];
@@ -721,11 +722,11 @@ prefix_encode (char *start, unsigned code))
 }
 
 static char *
 }
 
 static char *
-dlltmp (char **buf, const char *fmt))
+dlltmp (char **buf, const char *fmt)
 {
   if (!*buf)
     {
 {
   if (!*buf)
     {
-      *buf = malloc (strlen (tmp_prefix) + 64;
+      *buf = malloc (strlen (tmp_prefix) + 64);
       sprintf (*buf, fmt, tmp_prefix);
     }
   return *buf;
       sprintf (*buf, fmt, tmp_prefix);
     }
   return *buf;
@@ -889,7 +890,7 @@ yyerror (const char * err ATTRIBUTE_UNUSED)
 
 void
 def_exports (const char *name, const char *internal_name, int ordinal,
 
 void
 def_exports (const char *name, const char *internal_name, int ordinal,
-            int noname, int constant, int data)
+            int noname, int constant, int data, int private)
 {
   struct export *p = (struct export *) xmalloc (sizeof (*p));
 
 {
   struct export *p = (struct export *) xmalloc (sizeof (*p));
 
@@ -898,6 +899,7 @@ def_exports (const char *name, const char *internal_name, int ordinal,
   p->ordinal = ordinal;
   p->constant = constant;
   p->noname = noname;
   p->ordinal = ordinal;
   p->constant = constant;
   p->noname = noname;
+  p->private = private;
   p->data = data;
   p->next = d_exports;
   d_exports = p;
   p->data = data;
   p->next = d_exports;
   d_exports = p;
@@ -1246,7 +1248,7 @@ scan_drectve_symbols (bfd *abfd)
          /* FIXME: The 5th arg is for the `constant' field.
             What should it be?  Not that it matters since it's not
             currently useful.  */
          /* FIXME: The 5th arg is for the `constant' field.
             What should it be?  Not that it matters since it's not
             currently useful.  */
-         def_exports (c, 0, -1, 0, 0, ! (flags & BSF_FUNCTION));
+         def_exports (c, 0, -1, 0, 0, ! (flags & BSF_FUNCTION), 0);
 
          if (add_stdcall_alias && strchr (c, '@'))
            {
 
          if (add_stdcall_alias && strchr (c, '@'))
            {
@@ -1255,7 +1257,7 @@ scan_drectve_symbols (bfd *abfd)
              char *atsym = strchr (exported_name, '@');
              *atsym = '\0';
              /* Note: stdcall alias symbols can never be data.  */
              char *atsym = strchr (exported_name, '@');
              *atsym = '\0';
              /* Note: stdcall alias symbols can never be data.  */
-             def_exports (exported_name, xstrdup (c), -1, 0, 0, 0);
+             def_exports (exported_name, xstrdup (c), -1, 0, 0, 0, 0);
            }
        }
       else
            }
        }
       else
@@ -1294,7 +1296,7 @@ scan_filtered_symbols (bfd *abfd, void *minisyms, long symcount,
        ++symbol_name;
 
       def_exports (xstrdup (symbol_name) , 0, -1, 0, 0,
        ++symbol_name;
 
       def_exports (xstrdup (symbol_name) , 0, -1, 0, 0,
-                  ! (sym->flags & BSF_FUNCTION));
+                  ! (sym->flags & BSF_FUNCTION), 0);
 
       if (add_stdcall_alias && strchr (symbol_name, '@'))
         {
 
       if (add_stdcall_alias && strchr (symbol_name, '@'))
         {
@@ -1303,7 +1305,7 @@ scan_filtered_symbols (bfd *abfd, void *minisyms, long symcount,
          char *atsym = strchr (exported_name, '@');
          *atsym = '\0';
          /* Note: stdcall alias symbols can never be data.  */
          char *atsym = strchr (exported_name, '@');
          *atsym = '\0';
          /* Note: stdcall alias symbols can never be data.  */
-         def_exports (exported_name, xstrdup (symbol_name), -1, 0, 0, 0);
+         def_exports (exported_name, xstrdup (symbol_name), -1, 0, 0, 0, 0);
        }
     }
 }
        }
     }
 }
@@ -1518,13 +1520,14 @@ dump_def_info (FILE *f)
   fprintf (f, "\n");
   for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
     {
   fprintf (f, "\n");
   for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
     {
-      fprintf (f, "%s  %d = %s %s @ %d %s%s%s\n",
+      fprintf (f, "%s  %d = %s %s @ %d %s%s%s%s\n",
               ASM_C,
               i,
               exp->name,
               exp->internal_name,
               exp->ordinal,
               exp->noname ? "NONAME " : "",
               ASM_C,
               i,
               exp->name,
               exp->internal_name,
               exp->ordinal,
               exp->noname ? "NONAME " : "",
+              exp->private ? "PRIVATE " : "",
               exp->constant ? "CONSTANT" : "",
               exp->data ? "DATA" : "");
     }
               exp->constant ? "CONSTANT" : "",
               exp->data ? "DATA" : "");
     }
@@ -1595,20 +1598,20 @@ gen_def_file (void)
 
       if (strcmp (exp->name, exp->internal_name) == 0)
        {
 
       if (strcmp (exp->name, exp->internal_name) == 0)
        {
-
-         fprintf (output_def, "\t%s%s%s @ %d%s%s\n",
+         fprintf (output_def, "\t%s%s%s @ %d%s%s%s\n",
                   quote,
                   exp->name,
                   quote,
                   exp->ordinal,
                   exp->noname ? " NONAME" : "",
                   quote,
                   exp->name,
                   quote,
                   exp->ordinal,
                   exp->noname ? " NONAME" : "",
+                  exp->private ? "PRIVATE " : "",
                   exp->data ? " DATA" : "");
        }
       else
        {
                   exp->data ? " DATA" : "");
        }
       else
        {
-         char *quote1 = strchr (exp->internal_name, '.') ? "\"" : "";
+         char * quote1 = strchr (exp->internal_name, '.') ? "\"" : "";
          /* char *alias =  */
          /* char *alias =  */
-         fprintf (output_def, "\t%s%s%s = %s%s%s @ %d%s%s\n",
+         fprintf (output_def, "\t%s%s%s = %s%s%s @ %d%s%s%s\n",
                   quote,
                   exp->name,
                   quote,
                   quote,
                   exp->name,
                   quote,
@@ -1617,6 +1620,7 @@ gen_def_file (void)
                   quote1,
                   exp->ordinal,
                   exp->noname ? " NONAME" : "",
                   quote1,
                   exp->ordinal,
                   exp->noname ? " NONAME" : "",
+                  exp->private ? "PRIVATE " : "",
                   exp->data ? " DATA" : "");
        }
     }
                   exp->data ? " DATA" : "");
        }
     }
@@ -1841,14 +1845,14 @@ gen_exp_file (void)
 
       fprintf(f,"%s Export Name Table\n", ASM_C);
       for (i = 0; (exp = d_exports_lexically[i]); i++)
 
       fprintf(f,"%s Export Name Table\n", ASM_C);
       for (i = 0; (exp = d_exports_lexically[i]); i++)
-       if (!exp->noname || show_allnames)
-         {
+       {
+         if (!exp->noname || show_allnames)
            fprintf (f, "n%d:   %s      \"%s\"\n",
                     exp->ordinal, ASM_TEXT, xlate (exp->name));
            fprintf (f, "n%d:   %s      \"%s\"\n",
                     exp->ordinal, ASM_TEXT, xlate (exp->name));
-           if (exp->forward != 0)
-             fprintf (f, "f%d: %s      \"%s\"\n",
-                      exp->forward, ASM_TEXT, exp->internal_name);
-         }
+         if (exp->forward != 0)
+           fprintf (f, "f%d:   %s      \"%s\"\n",
+                    exp->forward, ASM_TEXT, exp->internal_name);
+       }
 
       if (a_list)
        {
 
       if (a_list)
        {
@@ -1943,7 +1947,7 @@ gen_exp_file (void)
          int dst = 0;
          int last = -1;
          qsort (copy, num_entries, sizeof (long), sfunc);
          int dst = 0;
          int last = -1;
          qsort (copy, num_entries, sizeof (long), sfunc);
-         /* Delete duplcates */
+         /* Delete duplicates */
          for (src = 0; src < num_entries; src++)
            {
              if (last != copy[src])
          for (src = 0; src < num_entries; src++)
            {
              if (last != copy[src])
@@ -2364,7 +2368,7 @@ make_one_lib_file (export_type *exp, int i)
       ptrs[oidx++] = iname_lab;
 
 #ifdef DLLTOOL_PPC
       ptrs[oidx++] = iname_lab;
 
 #ifdef DLLTOOL_PPC
-      /* The symbol refering to the code (.text).  */
+      /* The symbol referring to the code (.text).  */
       {
        asymbol *function_name;
 
       {
        asymbol *function_name;
 
@@ -2794,7 +2798,11 @@ gen_lib_file (void)
 
   for (i = 0; (exp = d_exports_lexically[i]); i++)
     {
 
   for (i = 0; (exp = d_exports_lexically[i]); i++)
     {
-      bfd *n = make_one_lib_file (exp, i);
+      bfd *n;
+      /* Don't add PRIVATE entries to import lib.  */
+      if (exp->private)
+       continue;
+      n = make_one_lib_file (exp, i);
       n->next = head;
       head = n;
     }
       n->next = head;
       head = n;
     }
@@ -2831,8 +2839,11 @@ gen_lib_file (void)
       char *name;
 
       name = (char *) alloca (strlen (TMP_STUB) + 10);
       char *name;
 
       name = (char *) alloca (strlen (TMP_STUB) + 10);
-      for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
+      for (i = 0; (exp = d_exports_lexically[i]); i++)
        {
        {
+         /* Don't delete non-existent stubs for PRIVATE entries.  */
+          if (exp->private)
+           continue;
          sprintf (name, "%s%05d.o", TMP_STUB, i);
          if (unlink (name) < 0)
            /* xgettext:c-format */
          sprintf (name, "%s%05d.o", TMP_STUB, i);
          if (unlink (name) < 0)
            /* xgettext:c-format */
@@ -2843,10 +2854,9 @@ gen_lib_file (void)
   inform (_("Created lib file"));
 }
 
   inform (_("Created lib file"));
 }
 
-/**********************************************************************/
-
 /* Run through the information gathered from the .o files and the
    .def file and work out the best stuff.  */
 /* Run through the information gathered from the .o files and the
    .def file and work out the best stuff.  */
+
 static int
 pfunc (const void *a, const void *b)
 {
 static int
 pfunc (const void *a, const void *b)
 {
@@ -2890,11 +2900,7 @@ remove_null_names (export_type **ptr)
 }
 
 static void
 }
 
 static void
-dtab (export **ptr
-#ifndef SACDEBUG
-ATTRIBUTE_UNUSED
-#endif
-      )
+dtab (export_type **ptr ATTRIBUTE_UNUSED)
 {
 #ifdef SACDEBUG
   int i;
 {
 #ifdef SACDEBUG
   int i;
@@ -2922,7 +2928,6 @@ process_duplicates (export_type **d_export_vec)
 
   while (more)
     {
 
   while (more)
     {
-
       more = 0;
       /* Remove duplicates.  */
       qsort (d_export_vec, d_nfuncs, sizeof (export_type *), nfunc);
       more = 0;
       /* Remove duplicates.  */
       qsort (d_export_vec, d_nfuncs, sizeof (export_type *), nfunc);
@@ -2933,7 +2938,6 @@ process_duplicates (export_type **d_export_vec)
          if (strcmp (d_export_vec[i]->name,
                      d_export_vec[i + 1]->name) == 0)
            {
          if (strcmp (d_export_vec[i]->name,
                      d_export_vec[i + 1]->name) == 0)
            {
-
              export_type *a = d_export_vec[i];
              export_type *b = d_export_vec[i + 1];
 
              export_type *a = d_export_vec[i];
              export_type *b = d_export_vec[i + 1];
 
@@ -2963,13 +2967,10 @@ process_duplicates (export_type **d_export_vec)
        }
     }
 
        }
     }
 
-
   /* Count the names.  */
   for (i = 0; i < d_nfuncs; i++)
   /* Count the names.  */
   for (i = 0; i < d_nfuncs; i++)
-    {
-      if (!d_export_vec[i]->noname)
-       d_named_nfuncs++;
-    }
+    if (!d_export_vec[i]->noname)
+      d_named_nfuncs++;
 }
 
 static void
 }
 
 static void
@@ -3008,7 +3009,7 @@ fill_ordinals (export_type **d_export_vec)
     {
       if (d_export_vec[i]->ordinal == -1)
        {
     {
       if (d_export_vec[i]->ordinal == -1)
        {
-         register int j;
+         int j;
 
          /* First try within or after any user supplied range.  */
          for (j = lowest; j < size; j++)
 
          /* First try within or after any user supplied range.  */
          for (j = lowest; j < size; j++)
@@ -3063,8 +3064,7 @@ mangle_defs (void)
 
   int i;
   int hint = 0;
 
   int i;
   int hint = 0;
-  export_type **d_export_vec
-  = (export_type **) xmalloc (sizeof (export_type *) * d_nfuncs);
+  export_type **d_export_vec = xmalloc (sizeof (export_type *) * d_nfuncs);
 
   inform (_("Processing definitions"));
 
 
   inform (_("Processing definitions"));
 
@@ -3101,8 +3101,6 @@ mangle_defs (void)
   inform (_("Processed definitions"));
 }
 
   inform (_("Processed definitions"));
 }
 
-/**********************************************************************/
-
 static void
 usage (FILE *file, int status)
 {
 static void
 usage (FILE *file, int status)
 {
@@ -3131,6 +3129,7 @@ usage (FILE *file, int status)
   fprintf (file, _("   -f --as-flags <flags>     Pass <flags> to the assembler.\n"));
   fprintf (file, _("   -C --compat-implib        Create backward compatible import library.\n"));
   fprintf (file, _("   -n --no-delete            Keep temp files (repeat for extra preservation).\n"));
   fprintf (file, _("   -f --as-flags <flags>     Pass <flags> to the assembler.\n"));
   fprintf (file, _("   -C --compat-implib        Create backward compatible import library.\n"));
   fprintf (file, _("   -n --no-delete            Keep temp files (repeat for extra preservation).\n"));
+  fprintf (file, _("   -t --temp-prefix <prefix> Use <prefix> to construct temp file names.\n"));
   fprintf (file, _("   -v --verbose              Be verbose.\n"));
   fprintf (file, _("   -V --version              Display the program version.\n"));
   fprintf (file, _("   -h --help                 Display this information.\n"));
   fprintf (file, _("   -v --verbose              Be verbose.\n"));
   fprintf (file, _("   -V --version              Display the program version.\n"));
   fprintf (file, _("   -h --help                 Display this information.\n"));
@@ -3160,7 +3159,7 @@ static const struct option long_options[] =
   {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMS},
   {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
   {"output-lib", required_argument, NULL, 'l'},
   {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMS},
   {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
   {"output-lib", required_argument, NULL, 'l'},
-  {"def", required_argument, NULL, 'd'}, /* for compatiblity with older versions */
+  {"def", required_argument, NULL, 'd'}, /* for compatibility with older versions */
   {"input-def", required_argument, NULL, 'd'},
   {"add-underscore", no_argument, NULL, 'U'},
   {"kill-at", no_argument, NULL, 'k'},
   {"input-def", required_argument, NULL, 'd'},
   {"add-underscore", no_argument, NULL, 'U'},
   {"kill-at", no_argument, NULL, 'k'},
@@ -3238,7 +3237,7 @@ main (int ac, char **av)
          as_flags = optarg;
          break;
 
          as_flags = optarg;
          break;
 
-         /* ignored for compatibility */
+         /* Ignored for compatibility.  */
        case 'u':
          break;
        case 'a':
        case 'u':
          break;
        case 'a':
This page took 0.02844 seconds and 4 git commands to generate.