public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Patch of dlltool for enhanced dll-stub creation@rsl-sie.de
@ 2004-05-17 16:10 Mark Junker
  2004-05-17 16:39 ` Dave Korn
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Junker @ 2004-05-17 16:10 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 439 bytes --]

Hi,

I created a patch for dlltool.c that allows all Win32-DLL users to use a 
DEF file with EXPORTS of the form

    external_name = internal_name

and the created archive contains an export with "external_name" but 
it'll call the DLL function "internal_name".

We needed this because we had to use a 3rd party DLL that contains 
__stdcall functions *without* the @n at the end of the names ...

Best regards,

Mark Junker
RSL SIE GmbH


[-- Attachment #2: dlltool.patch --]
[-- Type: text/plain, Size: 2461 bytes --]

--- binutils-2.15.90-20040222-1/binutils/dlltool.c	Sun Feb 22 03:25:50 2004
+++ binutils-patched/binutils/dlltool.c	Mon May 17 15:08:16 2004
@@ -359,6 +359,7 @@
 static int add_indirect = 0;
 static int add_underscore = 0;
 static int dontdeltemps = 0;
+static int map_to_internal_name = 0;
 
 /* TRUE if we should export all symbols.  Otherwise, we only export
    symbols listed in .drectve sections or in the def file.  */
@@ -2475,11 +2476,11 @@
                      why it did that, and it does not match what I see
                      in programs compiled with the MS tools.  */
 		  int idx = exp->hint;
-		  si->size = strlen (xlate (exp->name)) + 3;
+                  si->size = strlen (xlate (map_to_internal_name ? exp->internal_name : exp->name)) + 3;
 		  si->data = xmalloc (si->size);
 		  si->data[0] = idx & 0xff;
 		  si->data[1] = idx >> 8;
-		  strcpy (si->data + 2, xlate (exp->name));
+		  strcpy (si->data + 2, xlate (map_to_internal_name ? exp->internal_name : exp->name));
 		}
 	      break;
 	    case IDATA7:
@@ -3130,6 +3131,7 @@
   fprintf (file, _("   -S --as <name>            Use <name> for assembler.\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, _("   -i --internal-name        Maps external to internal name\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"));
@@ -3176,6 +3178,7 @@
   {"as-flags", required_argument, NULL, 'f'},
   {"mcore-elf", required_argument, NULL, 'M'},
   {"compat-implib", no_argument, NULL, 'C'},
+  {"internal-name", no_argument, NULL, 'i'},
   {"temp-prefix", required_argument, NULL, 't'},
   {NULL,0,NULL,0}
 };
@@ -3202,9 +3205,9 @@
 
   while ((c = getopt_long (ac, av,
 #ifdef DLLTOOL_MCORE_ELF
-			   "m:e:l:aD:d:z:b:xcCuUkAS:f:nvVHhM:L:F:",
+			   "m:e:l:aD:d:z:b:xcCiuUkAS:f:nvVHhM:L:F:",
 #else
-			   "m:e:l:aD:d:z:b:xcCuUkAS:f:nvVHh",
+			   "m:e:l:aD:d:z:b:xcCiuUkAS:f:nvVHh",
 #endif
 			   long_options, 0))
 	 != EOF)
@@ -3306,6 +3309,9 @@
 #endif
 	case 'C':
 	  create_compat_implib = 1;
+	  break;
+	case 'i':
+	  map_to_internal_name = 1;
 	  break;
 	default:
 	  usage (stderr, 1);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: Patch of dlltool for enhanced dll-stub creation@rsl-sie.de
  2004-05-17 16:10 Patch of dlltool for enhanced dll-stub creation@rsl-sie.de Mark Junker
@ 2004-05-17 16:39 ` Dave Korn
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Korn @ 2004-05-17 16:39 UTC (permalink / raw)
  To: binutils

> -----Original Message-----
> From: binutils-owner On Behalf Of Mark Junker
> Sent: 17 May 2004 17:11

> Hi,
> 
> I created a patch for dlltool.c that allows all Win32-DLL 
> users to use a 
> DEF file with EXPORTS of the form
> 
>     external_name = internal_name
> 
> and the created archive contains an export with "external_name" but 
> it'll call the DLL function "internal_name".
> 
> We needed this because we had to use a 3rd party DLL that contains 
> __stdcall functions *without* the @n at the end of the names ...

  You have heard about the '--enable-stdcall-fixup' option to ld, right?  I
believe it does what you want:

-------------------snip-------------------
"`--enable-stdcall-fixup'
`--disable-stdcall-fixup'
     If the link finds a symbol that it cannot resolve, it will attempt
     to do "fuzzy linking" by looking for another defined symbol that
     differs only in the format of the symbol name (cdecl vs stdcall)
     and will resolve that symbol by linking to the match.  For
     example, the undefined symbol `_foo' might be linked to the
     function `_foo@12', or the undefined symbol `_bar@16' might be
     linked to the function `_bar'.  When the linker does this, it
     prints a warning, since it normally should have failed to link,
     but sometimes import libraries generated from third-party dlls may
     need this feature to be usable.  If you specify
     `--enable-stdcall-fixup', this feature is fully enabled and
     warnings are not printed.  If you specify
     `--disable-stdcall-fixup', this feature is disabled and such
     mismatches are considered to be errors."
-------------------snip-------------------


  However, your patch is more widely generalized than that, and might well
be of use in other circumstances.



   cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-05-17 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-17 16:10 Patch of dlltool for enhanced dll-stub creation@rsl-sie.de Mark Junker
2004-05-17 16:39 ` Dave Korn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).