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 to binutils/dlltool: Support PRIVATE keyword in pe dll .def files [2]


Hello

This patch adds functionality to handle pe-dll .def file PRIVATE keyword
(exclude entry from import lib) to binutils/dlltool.

Tested on mingw32.

binutils/ChangeLog

2004-03-07  Danny Smith  <dannysmith@users.sourceforge.net>

	* deflex.l: Handle "PRIVATE" string.
	* defparse.y (%token): Add PRIVATE.
	(%type): Add opt_PRIVATE.
	(expline): Pass opt_PRIVATE to def_exports.
	(opt_PRIVATE): Handle PRIVATE token.
	* dlltool.h (def_exports): Add 7th param for private flag to
	declaration.
	* dlltool.c: Add PRIVATE to comment on EXPORTS syntax.
	(struct export): Add 'private' field.
	(def_exports): Set 'private' field of struct exports.
	(scan_drectve_symbols): Adjust calls to def_exports.
	(scan_filtered_symbols): Likewise.
	(dump_def_info): Print 'private' field.
	(gen_def_file): Likewise.
	(gen_lib_file): Skip generation of lib object if private.
	Delete tmp object files in same order as they were generated.
	Don't delete non-existent private object files.

Index: src/binutils/deflex.l
===================================================================
RCS file: /cvs/src/src/binutils/deflex.l,v
retrieving revision 1.6
diff -c -3 -p -r1.6 deflex.l
*** src/binutils/deflex.l	14 Sep 2003 12:20:16 -0000	1.6
--- src/binutils/deflex.l	7 Mar 2004 19:42:08 -0000
***************
*** 1,6 ****
  %{/* deflex.l - Lexer for .def files */
  
! /*   Copyright 1995, 1997, 1998, 1999, 2002, 2003 Free Software Foundation,
Inc.
  
  This file is part of GNU Binutils.
  
--- 1,7 ----
  %{/* deflex.l - Lexer for .def files */
  
! /*   Copyright 1995, 1997, 1998, 1999, 2002, 2003, 2004
!      Free Software Foundation, Inc.
  
  This file is part of GNU Binutils.
  
*************** int linenumber;
*** 46,51 ****
--- 47,53 ----
  "BASE"		{ return BASE;}
  "CONSTANT"	{ return CONSTANT; }
  "NONAME"	{ return NONAME; }
+ "PRIVATE"	{ return PRIVATE; }
  "READ"		{ return READ;}
  "WRITE"		{ return WRITE;}
  "EXECUTE"	{ return EXECUTE;}
Index: src/binutils/defparse.y
===================================================================
RCS file: /cvs/src/src/binutils/defparse.y,v
retrieving revision 1.4
diff -c -3 -p -r1.4 defparse.y
*** src/binutils/defparse.y	14 Mar 2001 02:56:45 -0000	1.4
--- src/binutils/defparse.y	7 Mar 2004 19:42:08 -0000
***************
*** 1,6 ****
  %{ /* defparse.y - parser for .def files */
  
! /*   Copyright 1995, 1997, 1998, 1999 Free Software Foundation, Inc.
  
  This file is part of GNU Binutils.
  
--- 1,7 ----
  %{ /* defparse.y - parser for .def files */
  
! /*   Copyright 1995, 1997, 1998, 1999, 2001, 2004
!      Free Software Foundation, Inc.
  
  This file is part of GNU Binutils.
  
*************** Foundation, Inc., 59 Temple Place - Suit
*** 30,40 ****
  
  %token NAME, LIBRARY, DESCRIPTION, STACKSIZE, HEAPSIZE, CODE, DATA
  %token SECTIONS, EXPORTS, IMPORTS, VERSIONK, BASE, CONSTANT
! %token READ WRITE EXECUTE SHARED NONSHARED NONAME
  %token SINGLE MULTIPLE INITINSTANCE INITGLOBAL TERMINSTANCE TERMGLOBAL
  %token <id> ID
  %token <number> NUMBER
! %type  <number> opt_base opt_ordinal opt_NONAME opt_CONSTANT opt_DATA
  %type  <number> attr attr_list opt_number
  %type  <id> opt_name opt_equal_name 
  
--- 31,41 ----
  
  %token NAME, LIBRARY, DESCRIPTION, STACKSIZE, HEAPSIZE, CODE, DATA
  %token SECTIONS, EXPORTS, IMPORTS, VERSIONK, BASE, CONSTANT
! %token READ WRITE EXECUTE SHARED NONSHARED NONAME PRIVATE
  %token SINGLE MULTIPLE INITINSTANCE INITGLOBAL TERMINSTANCE TERMGLOBAL
  %token <id> ID
  %token <number> NUMBER
! %type  <number> opt_base opt_ordinal opt_NONAME opt_CONSTANT opt_DATA
opt_PRIVATE
  %type  <number> attr attr_list opt_number
  %type  <id> opt_name opt_equal_name 
  
*************** explist:
*** 66,73 ****
  	;
  
  expline:
! 		ID opt_equal_name opt_ordinal opt_NONAME opt_CONSTANT opt_DATA
! 			{ def_exports ($1, $2, $3, $4, $5, $6);}
  	;
  implist:	
  		implist impline
--- 67,74 ----
  	;
  
  expline:
! 		ID opt_equal_name opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
! 			{ def_exports ($1, $2, $3, $4, $5, $6, $7);}
  	;
  implist:	
  		implist impline
*************** opt_NONAME:
*** 130,135 ****
--- 131,141 ----
  opt_DATA:
  		DATA { $$ = 1; }
  	|	     { $$ = 0; }
+ 	;
+ 
+ opt_PRIVATE:
+ 		PRIVATE { $$ = 1; }
+ 	|		{ $$ = 0; }
  	;
  
  opt_name: ID		{ $$ =$1; }
Index: src/binutils/dlltool.c
===================================================================
RCS file: /cvs/src/src/binutils/dlltool.c,v
retrieving revision 1.47
diff -c -3 -p -r1.47 dlltool.c
*** src/binutils/dlltool.c	21 Feb 2004 21:28:22 -0000	1.47
--- src/binutils/dlltool.c	7 Mar 2004 19:42:22 -0000
***************
*** 1,5 ****
  /* dlltool.c -- tool to generate stuff for PE style DLLs
!    Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
     Free Software Foundation, Inc.
  
     This file is part of GNU Binutils.
--- 1,5 ----
  /* dlltool.c -- tool to generate stuff for PE style DLLs
!    Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
     Free Software Foundation, Inc.
  
     This file is part of GNU Binutils.
***************
*** 49,55 ****
  
     EXPORTS  ( (  ( <name1> [ = <name2> ] )
                 | ( <name1> = <module-name> . <external-name>))
!             [ @ <integer> ] [ NONAME ] [CONSTANT] [DATA] ) *
     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>
--- 49,55 ----
  
     EXPORTS  ( (  ( <name1> [ = <name2> ] )
                 | ( <name1> = <module-name> . <external-name>))
!             [ @ <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>
*************** typedef struct export
*** 643,650 ****
      const char *internal_name;
      int ordinal;
      int constant;
-     int noname;
      int data;
      int hint;
      int forward;	/* Number of forward label, 0 means no forward.  */
      struct export *next;
--- 643,651 ----
      const char *internal_name;
      int ordinal;
      int constant;
      int data;
+     int noname;		/* Don't put name in image file.  */ 
+     int private;	/* Don't put reference in import lib.  */ 
      int hint;
      int forward;	/* Number of forward label, 0 means no forward.  */
      struct export *next;
*************** yyerror (const char * err ATTRIBUTE_UNUS
*** 889,895 ****
  
  void
  def_exports (const char *name, const char *internal_name, int ordinal,
! 	     int noname, int constant, int data)
  {
    struct export *p = (struct export *) xmalloc (sizeof (*p));
  
--- 890,896 ----
  
  void
  def_exports (const char *name, const char *internal_name, int ordinal,
! 	     int noname, int constant, int data, int private)
  {
    struct export *p = (struct export *) xmalloc (sizeof (*p));
  
*************** def_exports (const char *name, const cha
*** 899,904 ****
--- 900,906 ----
    p->constant = constant;
    p->noname = noname;
    p->data = data;
+   p->private = private;
    p->next = d_exports;
    d_exports = p;
    d_nfuncs++;
*************** scan_drectve_symbols (bfd *abfd)
*** 1246,1252 ****
  	  /* 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));
  
  	  if (add_stdcall_alias && strchr (c, '@'))
  	    {
--- 1248,1254 ----
  	  /* 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), 0);
  
  	  if (add_stdcall_alias && strchr (c, '@'))
  	    {
*************** scan_drectve_symbols (bfd *abfd)
*** 1255,1261 ****
  	      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);
  	    }
  	}
        else
--- 1257,1263 ----
  	      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, 0);
  	    }
  	}
        else
*************** scan_filtered_symbols (bfd *abfd, void *
*** 1294,1300 ****
  	++symbol_name;
  
        def_exports (xstrdup (symbol_name) , 0, -1, 0, 0,
! 		   ! (sym->flags & BSF_FUNCTION));
  
        if (add_stdcall_alias && strchr (symbol_name, '@'))
          {
--- 1296,1302 ----
  	++symbol_name;
  
        def_exports (xstrdup (symbol_name) , 0, -1, 0, 0,
! 		   ! (sym->flags & BSF_FUNCTION), 0);
  
        if (add_stdcall_alias && strchr (symbol_name, '@'))
          {
*************** scan_filtered_symbols (bfd *abfd, void *
*** 1303,1309 ****
  	  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);
  	}
      }
  }
--- 1305,1311 ----
  	  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, 0);
  	}
      }
  }
*************** dump_def_info (FILE *f)
*** 1518,1530 ****
    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",
  	       ASM_C,
  	       i,
  	       exp->name,
  	       exp->internal_name,
  	       exp->ordinal,
  	       exp->noname ? "NONAME " : "",
  	       exp->constant ? "CONSTANT" : "",
  	       exp->data ? "DATA" : "");
      }
--- 1520,1533 ----
    fprintf (f, "\n");
    for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
      {
!       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 " : "",
+ 	       exp->private ? "PRIVATE " : "",
  	       exp->constant ? "CONSTANT" : "",
  	       exp->data ? "DATA" : "");
      }
*************** gen_def_file (void)
*** 1596,1614 ****
        if (strcmp (exp->name, exp->internal_name) == 0)
  	{
  
! 	  fprintf (output_def, "\t%s%s%s @ %d%s%s\n",
  		   quote,
  		   exp->name,
  		   quote,
  		   exp->ordinal,
  		   exp->noname ? " NONAME" : "",
  		   exp->data ? " DATA" : "");
  	}
        else
  	{
  	  char *quote1 = strchr (exp->internal_name, '.') ? "\"" : "";
  	  /* char *alias =  */
! 	  fprintf (output_def, "\t%s%s%s = %s%s%s @ %d%s%s\n",
  		   quote,
  		   exp->name,
  		   quote,
--- 1599,1618 ----
        if (strcmp (exp->name, exp->internal_name) == 0)
  	{
  
! 	  fprintf (output_def, "\t%s%s%s @ %d%s%s%s\n",
  		   quote,
  		   exp->name,
  		   quote,
  		   exp->ordinal,
  		   exp->noname ? " NONAME" : "",
+ 		   exp->private ? "PRIVATE " : "",
  		   exp->data ? " DATA" : "");
  	}
        else
  	{
  	  char *quote1 = strchr (exp->internal_name, '.') ? "\"" : "";
  	  /* char *alias =  */
! 	  fprintf (output_def, "\t%s%s%s = %s%s%s @ %d%s%s%s\n",
  		   quote,
  		   exp->name,
  		   quote,
*************** gen_def_file (void)
*** 1617,1622 ****
--- 1621,1627 ----
  		   quote1,
  		   exp->ordinal,
  		   exp->noname ? " NONAME" : "",
+ 		   exp->private ? "PRIVATE " : "",
  		   exp->data ? " DATA" : "");
  	}
      }
*************** gen_lib_file (void)
*** 2794,2800 ****
  
    for (i = 0; (exp = d_exports_lexically[i]); i++)
      {
!       bfd *n = make_one_lib_file (exp, i);
        n->next = head;
        head = n;
      }
--- 2799,2809 ----
  
    for (i = 0; (exp = d_exports_lexically[i]); 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;
      }
*************** gen_lib_file (void)
*** 2831,2838 ****
        char *name;
  
        name = (char *) alloca (strlen (TMP_STUB) + 10);
!       for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
  	{
  	  sprintf (name, "%s%05d.o", TMP_STUB, i);
  	  if (unlink (name) < 0)
  	    /* xgettext:c-format */
--- 2840,2850 ----
        char *name;
  
        name = (char *) alloca (strlen (TMP_STUB) + 10);
!       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 */
Index: src/binutils/dlltool.h
===================================================================
RCS file: /cvs/src/src/binutils/dlltool.h,v
retrieving revision 1.3
diff -c -3 -p -r1.3 dlltool.h
*** src/binutils/dlltool.h	14 Sep 2003 12:20:16 -0000	1.3
--- src/binutils/dlltool.h	7 Mar 2004 19:42:22 -0000
***************
*** 1,5 ****
  /* dlltool.h -- header file for dlltool
!    Copyright 1997, 1998, 2003 Free Software Foundation, Inc.
  
     This file is part of GNU Binutils.
  
--- 1,5 ----
  /* dlltool.h -- header file for dlltool
!    Copyright 1997, 1998, 2003. 2004 Free Software Foundation, Inc.
  
     This file is part of GNU Binutils.
  
***************
*** 24,30 ****
  extern void def_code (int);
  extern void def_data (int);
  extern void def_description (const char *);
! extern void def_exports (const char *, const char *, int, int, int, int);
  extern void def_heapsize (int, int);
  extern void def_import
    (const char *, const char *, const char *, const char *, int);
--- 24,30 ----
  extern void def_code (int);
  extern void def_data (int);
  extern void def_description (const char *);
! extern void def_exports (const char *, const char *, int, int, int, int,
int);
  extern void def_heapsize (int, int);
  extern void def_import
    (const char *, const char *, const char *, const char *, int);

Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com


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