This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH Revise Windows dlltool --ext-prefix-alias


In the initial implementation
<http://sources.redhat.com/ml/binutils/2004-07/msg00130.html>, the alias
symbols are put into the same object as the normal export symbols.  This
prevents one from defining a symbol with either of these names if the
the other name is used.  As the intent of the original patch was to
support this very practice, this is something of a bug.

With this patch, the aliases are put into their object.  (This has the
downside of doubling the import library size, but only if
--ext-prefix-alias is used).  This is accomplished by adding a new
struct export member, import_name, and moving the alias code from
make_one_lib_file() to gen_lib_file().  A hard coded maximum number of
imports is introduced (PREFIX_ALIAS_BASE = 20000), but again only when
this flag is used.

I've also added two tests that verify that this option is doing the
right thing.  To invoke dlltool to create an import library, I needed to
supply dlltool with as's path.  The code to set up tmpdir/gas was broken
for Windows, so I changed the code in config/default.exp to use cp
instead of ln -s and added a procedure exe_ext.

Tested on i686-pc-mingw32.  I have a copyright assignment but no CVS access.

Aaron W. LaFramboise
2004-10-16  Aaron W. LaFramboise <aaron98wiridge9@aaronwl.com>

	* dlltool.c (<assert.h>): Include.
	(PREFIX_ALIAS_BASE): Define.
	(struct export): Add member import_name;
	(def_exports): Set import_name.
	(make_one_lib_file): Remove prefix alias code, use import_name
	in .idata$6.
	(gen_lib_file): Create and delete aliases.

	* binutils-all/alias.def: New file.
	* binutils-all/dlltool.exp: Two new -p tests.
	* config/default.exp (dlltool_gas_flag): New variable.
	* lib/utils-lib.exp (exe_ext): New procedure.

Index: src/binutils/dlltool.c
===================================================================
RCS file: /cvs/src/src/binutils/dlltool.c,v
retrieving revision 1.54
diff -c -3 -p -r1.54 dlltool.c
*** src/binutils/dlltool.c	8 Oct 2004 09:49:14 -0000	1.54
--- src/binutils/dlltool.c	17 Oct 2004 00:44:10 -0000
***************
*** 261,266 ****
--- 261,268 ----
  #include <varargs.h>
  #endif
  
+ #include <assert.h>
+ 
  #ifdef DLLTOOL_ARM
  #include "coff/arm.h"
  #include "coff/internal.h"
*************** static char * mcore_elf_linker_flags = N
*** 430,435 ****
--- 432,440 ----
  
  #define PATHMAX 250		/* What's the right name for this ?  */
  
+ /* External name alias numbering starts here */
+ #define PREFIX_ALIAS_BASE 20000
+ 
  char *tmp_asm_buf;
  char *tmp_head_s_buf;
  char *tmp_head_o_buf;
*************** typedef struct export
*** 642,647 ****
--- 647,653 ----
    {
      const char *name;
      const char *internal_name;
+     const char *import_name;
      int ordinal;
      int constant;
      int noname;		/* Don't put name in image file.  */
*************** def_exports (const char *name, const cha
*** 901,906 ****
--- 907,913 ----
  
    p->name = name;
    p->internal_name = internal_name ? internal_name : name;
+   p->import_name = name;
    p->ordinal = ordinal;
    p->constant = constant;
    p->noname = noname;
*************** make_one_lib_file (export_type *exp, int
*** 2248,2254 ****
        asymbol *  exp_label;
        asymbol *  iname = 0;
        asymbol *  iname2;
-       asymbol *  iname2_pre = 0;
        asymbol *  iname_lab;
        asymbol ** iname_lab_pp;
        asymbol ** iname_pp;
--- 2255,2260 ----
*************** make_one_lib_file (export_type *exp, int
*** 2338,2360 ****
  	    bfd_coff_set_symbol_class (abfd, exp_label, C_THUMBEXTFUNC);
  #endif
  	  ptrs[oidx++] = exp_label;
- 
- 	  if (ext_prefix_alias)
- 	    {
- 	      asymbol *  exp_label_pre;
- 
- 	      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
--- 2344,2349 ----
*************** make_one_lib_file (export_type *exp, int
*** 2375,2393 ****
        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;
--- 2364,2369 ----
*************** make_one_lib_file (export_type *exp, int
*** 2399,2406 ****
        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;
--- 2375,2380 ----
*************** make_one_lib_file (export_type *exp, int
*** 2517,2527 ****
                       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->data = xmalloc (si->size);
  		  si->data[0] = idx & 0xff;
  		  si->data[1] = idx >> 8;
! 		  strcpy (si->data + 2, xlate (exp->name));
  		}
  	      break;
  	    case IDATA7:
--- 2491,2501 ----
                       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->import_name)) + 3;
  		  si->data = xmalloc (si->size);
  		  si->data[0] = idx & 0xff;
  		  si->data[1] = idx >> 8;
! 		  strcpy (si->data + 2, xlate (exp->import_name));
  		}
  	      break;
  	    case IDATA7:
*************** gen_lib_file (void)
*** 2843,2848 ****
--- 2817,2841 ----
        n = make_one_lib_file (exp, i);
        n->next = head;
        head = n;
+       if (ext_prefix_alias)
+ 	{
+ 	  export_type alias_exp;
+ 	  assert (i < PREFIX_ALIAS_BASE);
+ 	  alias_exp.name = make_imp_label (ext_prefix_alias, exp->name);
+ 	  alias_exp.internal_name = exp->internal_name;
+ 	  alias_exp.import_name = exp->name;
+ 	  alias_exp.ordinal = exp->ordinal;
+ 	  alias_exp.constant = exp->constant;
+ 	  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);
+ 	  n->next = head;
+ 	  head = n;
+ 	}
      }
  
    /* Now stick them all into the archive.  */
*************** gen_lib_file (void)
*** 2886,2891 ****
--- 2879,2891 ----
  	  if (unlink (name) < 0)
  	    /* xgettext:c-format */
  	    non_fatal (_("cannot delete %s: %s"), name, strerror (errno));
+ 	  if (ext_prefix_alias)
+ 	    {
+ 	      sprintf (name, "%s%05d.o", TMP_STUB, i + PREFIX_ALIAS_BASE);
+ 	      if (unlink (name) < 0)
+ 		/* xgettext:c-format */
+ 		non_fatal (_("cannot delete %s: %s"), name, strerror (errno));
+ 	    }
  	}
      }
  
*** /dev/null   Sat Oct 16 21:43:53 2004
--- src/binutils/testsuite/binutils-all/alias.def       Sat Oct 16 20:53:38 2004
***************
*** 0 ****
--- 1,2 ----
+ EXPORTS
+ symbol=nothing
Index: src/binutils/testsuite/binutils-all/dlltool.exp
===================================================================
RCS file: /cvs/src/src/binutils/testsuite/binutils-all/dlltool.exp,v
retrieving revision 1.3
diff -c -3 -p -r1.3 dlltool.exp
*** src/binutils/testsuite/binutils-all/dlltool.exp	12 Jul 2004 17:07:55 -0000	1.3
--- src/binutils/testsuite/binutils-all/dlltool.exp	17 Oct 2004 02:39:31 -0000
*************** if ![string match "" $err] then {
*** 41,59 ****
      send_log "$err\n"
      verbose "$err" 1
      fail "dlltool (fastcall export)"
!     continue
  }
  
! pass "dlltool (fastcall export)"
! 
! verbose "$DLLTOOL -p foo -d $srcdir/$subdir/fastcall.def" 1
! catch "exec $DLLTOOL -p foo -d $srcdir/$subdir/fastcall.def" err
  
  if ![string match "" $err] then {
      send_log "$err\n"
      verbose "$err" 1
!     fail "dlltool (aliased export)"
      continue
  }
  
! pass "dlltool (aliased export)"
--- 41,76 ----
      send_log "$err\n"
      verbose "$err" 1
      fail "dlltool (fastcall export)"
! } else {
!     pass "dlltool (fastcall export)"
  }
  
! verbose "$DLLTOOL -p prefix -l tmpdir/libalias.a -d $srcdir/$subdir/alias.def $dlltool_gas_flag" 1
! catch "exec $DLLTOOL -p prefix -l tmpdir/libalias.a -d $srcdir/$subdir/alias.def $dlltool_gas_flag" err
  
  if ![string match "" $err] then {
      send_log "$err\n"
      verbose "$err" 1
!     fail "dlltool -p (execution)"
      continue
  }
  
! pass "dlltool -p (execution)"
! 
! set got [binutils_run $NM "tmpdir/libalias.a"]
! set want "00000000 I __imp__prefix_symbol.*00000000 T _prefix_symbol.*00000000 I __imp__symbol.*00000000 T _symbol"
! 
! if [regexp $want $got] then {
!     pass "dlltool -p (symbol names)"
! } else {
!     fail "dlltool -p (symbol names)"
! }
! 
! set got [binutils_run $OBJDUMP "-s -j .idata\$6 tmpdir/libalias.a"]
! set want "(Contents of section .idata\\\$6:.*\\.\\.symbol\\.\\..*){2,2}"
! 
! if [regexp $want $got] then {
!     pass "dlltool -p (import name)"
! } else {
!     fail "dlltool -p (import name)"
! }
Index: src/binutils/testsuite/config/default.exp
===================================================================
RCS file: /cvs/src/src/binutils/testsuite/config/default.exp,v
retrieving revision 1.5
diff -c -3 -p -r1.5 default.exp
*** src/binutils/testsuite/config/default.exp	6 Nov 2002 19:36:18 -0000	1.5
--- src/binutils/testsuite/config/default.exp	17 Oct 2004 02:39:32 -0000
*************** if ![info exists DLLTOOL] then {
*** 71,89 ****
  
  if ![file isdirectory tmpdir] {catch "exec mkdir tmpdir" status}
  
! # Make a symlink from tmpdir/gas/as and tmpdir/gas/ld to the assembler
  # and linker in the build tree, so that we can use a -B option to gcc
  # to force it to use the newly built assembler/linker.
  if {![file isdirectory tmpdir/gas]} then {
      catch "exec mkdir tmpdir/gas" status
!     if {[file isfile ../gas/as-new]} then {
! 	catch "exec ln -s ../../../gas/as-new tmpdir/gas/as" status
      }
!     if {[file isfile ../ld/ld-new]} then {
! 	catch "exec ln -s ../../../ld/ld-new tmpdir/gas/ld" status
      }
  }
  set gcc_gas_flag "-B[pwd]/tmpdir/gas/"
  
  #
  # binutils_run
--- 71,91 ----
  
  if ![file isdirectory tmpdir] {catch "exec mkdir tmpdir" status}
  
! # Make a copy from tmpdir/gas/as and tmpdir/gas/ld to the assembler
  # and linker in the build tree, so that we can use a -B option to gcc
  # to force it to use the newly built assembler/linker.
  if {![file isdirectory tmpdir/gas]} then {
      catch "exec mkdir tmpdir/gas" status
!     send_user "file isfile ../gas/as-new[exe_ext] [file isfile ../gas/as-new[exe_ext]]"
!     if {[file isfile ../gas/as-new[exe_ext]]} then {
! 	catch "exec cp ../gas/as-new[exe_ext] tmpdir/gas/as[exe_ext]" status
      }
!     if {[file isfile ../ld/ld-new[exe_ext]]} then {
! 	catch "exec cp ../ld/ld-new[exe_ext] tmpdir/gas/ld[exe_ext]" status
      }
  }
  set gcc_gas_flag "-B[pwd]/tmpdir/gas/"
+ set dlltool_gas_flag "-S [pwd]/tmpdir/gas/as[exe_ext]"
  
  #
  # binutils_run
Index: src/binutils/testsuite/lib/utils-lib.exp
===================================================================
RCS file: /cvs/src/src/binutils/testsuite/lib/utils-lib.exp,v
retrieving revision 1.6
diff -c -3 -p -r1.6 utils-lib.exp
*** src/binutils/testsuite/lib/utils-lib.exp	12 May 2004 03:28:46 -0000	1.6
--- src/binutils/testsuite/lib/utils-lib.exp	17 Oct 2004 02:39:32 -0000
*************** proc is_elf_format {} {
*** 149,151 ****
--- 149,163 ----
      }
      return 1
  }
+ 
+ #
+ # exe_ext
+ #	Returns target executable extension, if any.
+ #
+ proc exe_ext {} {
+     if { [istarget *-*-mingw32] || [istarget *-*-cygwin*] } {
+         return ".exe"
+     } else {
+         return ""
+     }
+ }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]