Add symbol called __nm_<name> to exported symbols created by dlltool.
[binutils-gdb.git] / binutils / dlltool.c
index e116e6bf9c2e3beaee9b0de3c1be72365112af55..88ee5a5f1b1640fa7dca2cae1a8eb7ea493f2e17 100644 (file)
@@ -1,5 +1,5 @@
 /* dlltool.c -- tool to generate stuff for PE style DLLs
-   Copyright (C) 1995-2016 Free Software Foundation, Inc.
+   Copyright (C) 1995-2017 Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -780,10 +780,9 @@ typedef struct export
   int ordinal;
   int constant;
   int noname;          /* Don't put name in image file.  */
-  int private; /* Don't put reference in import lib.  */
+  int private;         /* Don't put reference in import lib.  */
   int data;
-  int hint;
-  int forward; /* Number of forward label, 0 means no forward.  */
+  int forward;         /* Number of forward label, 0 means no forward.  */
   struct export *next;
 }
 export_type;
@@ -2339,7 +2338,7 @@ static sinfo secdata[NSECS] =
   INIT_SEC_DATA (IDATA7, ".idata$7", SEC_HAS_CONTENTS, 2),
   INIT_SEC_DATA (IDATA5, ".idata$5", SEC_HAS_CONTENTS, 2),
   INIT_SEC_DATA (IDATA4, ".idata$4", SEC_HAS_CONTENTS, 2),
-  INIT_SEC_DATA (IDATA6, ".idata$6", SEC_HAS_CONTENTS, 1)
+  INIT_SEC_DATA (IDATA6, ".idata$6", SEC_HAS_CONTENTS, 2)
 };
 
 #else
@@ -2544,6 +2543,18 @@ make_one_lib_file (export_type *exp, int i, int delay)
 #endif
       ptrs[oidx++] = exp_label;
     }
+#ifndef DLLTOOL_PPC
+  else
+    {
+      /* PR 20881: Add __nm_<symbol> for the exported library.
+        FIXME: Might be needed for PowerPC, but currently unable to test this.  */
+      exp_label = bfd_make_empty_symbol (abfd);
+      exp_label->name = make_imp_label ("__nm_", exp->name);
+      exp_label->section = secdata[IDATA6].sec;
+      exp_label->flags = BSF_GLOBAL;
+      exp_label->value = 0;
+    }
+#endif
 
   /* Generate imp symbols with one underscore for Microsoft
      compatibility, and with two underscores for backward
@@ -2574,6 +2585,12 @@ make_one_lib_file (export_type *exp, int i, int delay)
   if (create_compat_implib)
     ptrs[oidx++] = iname;
   ptrs[oidx++] = iname2;
+#ifndef DLLTOOL_PPC
+  /* PR 20881:
+     According to pe-dll.c __nm_<symbol> should be add after __imp_<symbol>.  */
+  if (exp->data)
+    ptrs[oidx++] = exp_label;
+#endif
 
   iname_lab_pp = ptrs + oidx;
   ptrs[oidx++] = iname_lab;
@@ -2708,7 +2725,8 @@ make_one_lib_file (export_type *exp, int i, int delay)
              sec->orelocation = rpp;
              break;
            }
-         /* else fall through */
+         /* Fall through.  */
+
        case IDATA4:
          /* An idata$4 or idata$5 is one word long, and has an
             rva to idata$6.  */
@@ -2775,10 +2793,8 @@ make_one_lib_file (export_type *exp, int i, int delay)
        case IDATA6:
          if (!exp->noname)
            {
-             /* This used to add 1 to exp->hint.  I don't know
-                why it did that, and it does not match what I see
-                in programs compiled with the MS tools.  */
-             int idx = exp->hint;
+             int idx = exp->ordinal;
+
              if (exp->its_name)
                si->size = strlen (exp->its_name) + 3;
              else
@@ -3262,7 +3278,6 @@ gen_lib_file (int delay)
          alias_exp.noname = exp->noname;
          alias_exp.private = exp->private;
          alias_exp.data = exp->data;
-         alias_exp.hint = exp->hint;
          alias_exp.forward = exp->forward;
          alias_exp.next = exp->next;
          n = make_one_lib_file (&alias_exp, i + PREFIX_ALIAS_BASE, delay);
@@ -3926,10 +3941,8 @@ mangle_defs (void)
 {
   /* First work out the minimum ordinal chosen.  */
   export_type *exp;
-
-  int i;
-  int hint = 0;
   export_type **d_export_vec = xmalloc (sizeof (export_type *) * d_nfuncs);
+  int i;
 
   inform (_("Processing definitions"));
 
@@ -3958,11 +3971,6 @@ mangle_defs (void)
 
   qsort (d_exports_lexically, i, sizeof (export_type *), nfunc);
 
-  /* Fill exp entries with their hint values.  */
-  for (i = 0; i < d_nfuncs; i++)
-    if (!d_exports_lexically[i]->noname || show_allnames)
-      d_exports_lexically[i]->hint = hint++;
-
   inform (_("Processed definitions"));
 }