public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH pecoff mingw32 dlltool: Add option to create external aliases of DLL imports.
@ 2004-07-11  7:49 Aaron W. LaFramboise
  2004-07-12 17:07 ` Nick Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: Aaron W. LaFramboise @ 2004-07-11  7:49 UTC (permalink / raw)
  To: binutils

This patch adds an option --ext-prefix-alias that creates aliases of DLL
imports in an import library, with a specified prefix.

The ability to create aliases in this fashion is useful where one wants
to override the functionality in a DLL while still allowing access to
the original function.

I initially considered adding this as an extension to the DEF format,
but decided that that would cause more portability problems compared to
just adding an option.  In addition, its much easier to just specify an
option on the command line than to have to add an alias for each export.

Build and tested on i686-pc-mingw32.

Aaron W. LaFramboise


2004-07-09  Aaron W. LaFramboise <aaron98wiridge9@aaronwl.com>

	* binutils/doc/binutils.texi
	(--ext-prefix-alias): Document.
	* binutils/dlltool.c (ext_prefix_alias): New global variable.
	(make_one_lib_file): Add aliases with prefixes for external
	and import definitions.
	(usage): Document -p option.
	(long_options): Add --ext-prefix-alias option.
	(main): Handle -p.

Index: src/binutils/doc/binutils.texi
===================================================================
RCS file: /cvs/src/src/binutils/doc/binutils.texi,v
retrieving revision 1.53
diff -c -3 -p -r1.53 binutils.texi
*** src/binutils/doc/binutils.texi	3 Jul 2004 16:07:48 -0000	1.53
--- src/binutils/doc/binutils.texi	11 Jul 2004 07:35:44 -0000
*************** dlltool [@option{-d}|@option{--input-def
*** 2866,2871 ****
--- 2866,2872 ----
          [@option{-D}|@option{--dllname} @var{name}]
[@option{-m}|@option{--machine} @var{machine}]
          [@option{-a}|@option{--add-indirect}]
[@option{-U}|@option{--add-underscore}] [@option{-k}|@option{--kill-at}]
          [@option{-A}|@option{--add-stdcall-alias}]
+         [@option{-p}|@option{--ext-prefix-alias} @var{prefix}]
          [@option{-x}|@option{--no-idata4}]
[@option{-c}|@option{--no-idata5}] [@option{-i}|@option{--interwork}]
          [@option{-n}|@option{--nodelete}]
[@option{-t}|@option{--temp-prefix} @var{prefix}]
          [@option{-v}|@option{--verbose}]
*************** Specifies that when @command{dlltool} is
*** 3055,3060 ****
--- 3056,3067 ----
  should add aliases for stdcall symbols without @samp{@@ <number>}
  in addition to the symbols with @samp{@@ <number>}.

+ @item -p
+ @itemx --ext-prefix-alias @var{prefix}
+ Causes @command{dlltool} to to create external aliases for all DLL
+ imports with the specified prefix.  The aliases are created for both
+ external and import symbols with no leading underscore.
+
  @item -x
  @itemx --no-idata4
  Specifies that when @command{dlltool} is creating the exports and library
Index: src/binutils/dlltool.c
===================================================================
RCS file: /cvs/src/src/binutils/dlltool.c,v
retrieving revision 1.50
diff -c -3 -p -r1.50 dlltool.c
*** src/binutils/dlltool.c	9 Jul 2004 16:20:05 -0000	1.50
--- src/binutils/dlltool.c	11 Jul 2004 02:53:01 -0000
*************** extern char * program_name;
*** 382,387 ****
--- 382,388 ----
  static int machine;
  static int killat;
  static int add_stdcall_alias;
+ static const char *ext_prefix_alias;
  static int verbose;
  static FILE *output_def;
  static FILE *base_file;
*************** make_one_lib_file (export_type *exp, int
*** 2245,2252 ****
--- 2246,2255 ----
      {
        bfd *      abfd;
        asymbol *  exp_label;
+       asymbol *  exp_label_pre;
        asymbol *  iname = 0;
        asymbol *  iname2;
+       asymbol *  iname2_pre = 0;
        asymbol *  iname_lab;
        asymbol ** iname_lab_pp;
        asymbol ** iname_pp;
*************** make_one_lib_file (export_type *exp, int
*** 2336,2341 ****
--- 2339,2360 ----
  	    bfd_coff_set_symbol_class (abfd, exp_label, C_THUMBEXTFUNC);
  #endif
  	  ptrs[oidx++] = exp_label;
+
+ 	  if (ext_prefix_alias)
+ 	    {
+ 	      exp_label_pre = bfd_make_empty_symbol (abfd);
+ 	      exp_label_pre->name
+ 		= make_imp_label (ext_prefix_alias, exp->name);
+ 	      exp_label_pre->section = exp_label->section;
+ 	      exp_label_pre->flags = exp_label->flags;
+ 	      exp_label_pre->value = exp_label->value;
+ #ifdef DLLTOOL_ARM
+ 	      if (machine == MTHUMB)
+ 		bfd_coff_set_symbol_class (abfd, exp_label, C_THUMBEXTFUNC);
+ #endif
+ 	      ptrs[oidx++] = exp_label_pre;
+ 	    }
+
  	}

        /* Generate imp symbols with one underscore for Microsoft
*************** make_one_lib_file (export_type *exp, int
*** 2356,2361 ****
--- 2375,2392 ----
        iname2->flags = BSF_GLOBAL;
        iname2->value = 0;

+       if (ext_prefix_alias)
+ 	{
+ 	  char *pre_name;
+ 	  iname2_pre = bfd_make_empty_symbol (abfd);
+ 	  pre_name = xmalloc(strlen(ext_prefix_alias) + 7);
+ 	  sprintf(pre_name, "__imp_%s", ext_prefix_alias);
+ 	  iname2_pre->name = make_imp_label (pre_name, exp->name);
+ 	  iname2_pre->section = iname2->section;
+ 	  iname2_pre->flags = iname2->flags;
+ 	  iname2_pre->value = iname2->value;
+ 	}
+
        iname_lab = bfd_make_empty_symbol(abfd);

        iname_lab->name = head_label;
*************** make_one_lib_file (export_type *exp, int
*** 2367,2372 ****
--- 2398,2405 ----
        if (create_compat_implib)
  	ptrs[oidx++] = iname;
        ptrs[oidx++] = iname2;
+       if (ext_prefix_alias)
+ 	ptrs[oidx++] = iname2_pre;

        iname_lab_pp = ptrs + oidx;
        ptrs[oidx++] = iname_lab;
*************** usage (FILE *file, int status)
*** 3129,3134 ****
--- 3162,3168 ----
    fprintf (file, _("   -U --add-underscore       Add underscores to
symbols in interface library.\n"));
    fprintf (file, _("   -k --kill-at              Kill @<n> from
exported names.\n"));
    fprintf (file, _("   -A --add-stdcall-alias    Add aliases without
@<n>.\n"));
+   fprintf (file, _("   -p --ext-prefix-alias <prefix> Add aliases with
prefix.\n"));
    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"));
*************** static const struct option long_options[
*** 3168,3173 ****
--- 3202,3208 ----
    {"add-underscore", no_argument, NULL, 'U'},
    {"kill-at", no_argument, NULL, 'k'},
    {"add-stdcall-alias", no_argument, NULL, 'A'},
+   {"ext-prefix-alias", required_argument, NULL, 'p'},
    {"verbose", no_argument, NULL, 'v'},
    {"version", no_argument, NULL, 'V'},
    {"help", no_argument, NULL, 'h'},
*************** main (int ac, char **av)
*** 3281,3286 ****
--- 3316,3324 ----
  	case 'A':
  	  add_stdcall_alias = 1;
  	  break;
+ 	case 'p':
+ 	  ext_prefix_alias = optarg;
+ 	  break;
  	case 'd':
  	  def_file = optarg;
  	  break;

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

* Re: PATCH pecoff mingw32 dlltool: Add option to create external aliases of DLL imports.
  2004-07-11  7:49 PATCH pecoff mingw32 dlltool: Add option to create external aliases of DLL imports Aaron W. LaFramboise
@ 2004-07-12 17:07 ` Nick Clifton
  2004-07-12 20:48   ` Aaron W. LaFramboise
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2004-07-12 17:07 UTC (permalink / raw)
  To: Aaron W. LaFramboise; +Cc: binutils

Hi Aaron,

> 2004-07-09  Aaron W. LaFramboise <aaron98wiridge9@aaronwl.com>
> 
> 	* binutils/doc/binutils.texi
> 	(--ext-prefix-alias): Document.
> 	* binutils/dlltool.c (ext_prefix_alias): New global variable.
> 	(make_one_lib_file): Add aliases with prefixes for external
> 	and import definitions.
> 	(usage): Document -p option.
> 	(long_options): Add --ext-prefix-alias option.
> 	(main): Handle -p.

Approved and applied.  Note - there is a ChangeLog in the binutils/ 
directory so I have moved the above entry there.

I fixed one bug and made two additions.  The bug was that you had not 
added "p:" to the string passed to getopt_long() in dlltools.c:main() 
which meant that the -p switch was not recognised.  (The 
--ext-prefix-alias version was recognised).

The first addition was to add a few more lines to 
binutils/testsuite/binutils-all/dlltool.exp which check that the new 
switch is not rejected.  Note - this is not a proper test of the 
switch's functionality.  I hope that you might consider submitting a 
patch to do that yourself.

The other addition was a line to binutils/NEWS mentioning the new 
feature of dlltool.

Cheers
   Nick

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

* Re: PATCH pecoff mingw32 dlltool: Add option to create external aliases of DLL imports.
  2004-07-12 17:07 ` Nick Clifton
@ 2004-07-12 20:48   ` Aaron W. LaFramboise
  0 siblings, 0 replies; 3+ messages in thread
From: Aaron W. LaFramboise @ 2004-07-12 20:48 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Aaron W. LaFramboise, binutils

Nick Clifton wrote:
> I fixed one bug and made two additions.  The bug was that you had not 
> added "p:" to the string passed to getopt_long() in dlltools.c:main() 
> which meant that the -p switch was not recognised.  (The 
> --ext-prefix-alias version was recognised).

Sorry.  I think I must have accidentally trimmed that part from the patch.

> The first addition was to add a few more lines to 
> binutils/testsuite/binutils-all/dlltool.exp which check that the new 
> switch is not rejected.  Note - this is not a proper test of the 
> switch's functionality.  I hope that you might consider submitting a 
> patch to do that yourself.

OK.  I will soon.

> The other addition was a line to binutils/NEWS mentioning the new 
> feature of dlltool.

Thanks a ton.

Aaron W. LaFramboise

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

end of thread, other threads:[~2004-07-12 20:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-11  7:49 PATCH pecoff mingw32 dlltool: Add option to create external aliases of DLL imports Aaron W. LaFramboise
2004-07-12 17:07 ` Nick Clifton
2004-07-12 20:48   ` Aaron W. LaFramboise

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).