This is the mail archive of the cygwin-apps@cygwin.com mailing list for the Cygwin 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]

ld ---export--all --exclude-libs,?


Hello, I'm after some criticism, before submitting this to binutils.

IMO, the auto-export feature of ld needs (at least) an option to exclude
whole libs from export. The following patch does that. It also adds a few
more default lib excludes and scans for backward compat implib symbols
(__imp_) 

I think this patch doesn't do enough.

My preference would be to exclude *all* libs by default, with a command
line option to explicity *include* named libs.  Why? It is too easy for
licensed library code to sneak into dll's using --export-all. This affects
distributability (sic) of the dll and apps dependent on the dll.
The user may be unaware of this infection because its automatic.
At least make the user think about what she/he is exporting.

I will gladly throw away the following to work on a patch to exclude all
libs by default if given encouragement.

Any comments.


2001-11-21  Danny Smith  <dannysmith@users.sourceforge.net>

	* ld/emultempl/pe.em (OPTION_EXCLUDE_LIBS): Add new define.
	(longopts): Add new option --exclude-libs.
	(gld_${EMULATION_NAME}_list_options): Document it.
	(gld_${EMULATION_NAME}_parse_args): Use it.
	* ld/pe-dll.h (pe_dll_add_excludes): Add second param to prototype.
	* ld/pe-dll.c (autofilter_liblist): Add more default libs.
	(exclude_list_struct): Add field type to distinguish
	symbols from whole archives.
	(pe_dll_add_excludes): Set excludes->type.
	(auto_export): Scan for old __imp_ prefix as well as _imp__
	when filtering symbols. Add new variable libname and set to
 	archive basename if abfd. Use it when filtering default and
	user-specified libarary excludes. Use excludes->type when
	scanning user-specified excludes. 

Index: src/ld/pe-dll.c
===================================================================
RCS file: /cvs/src/src/ld/pe-dll.c,v
retrieving revision 1.37
diff -u -p -r1.37 pe-dll.c
--- pe-dll.c	2001/10/19 14:25:51	1.37
+++ pe-dll.c	2001/11/21 08:20:19
@@ -231,6 +231,9 @@ static autofilter_entry_type autofilter_
   { "libgcc.", 7 },
   { "libstdc++.", 10 },
   { "libmingw32.", 11 },
+  { "libg2c.", 7 },
+  { "libsupc++.", 10 },  /* g++ 3.x  */
+  { "libobjc.", 8 }, 
   { NULL, 0 }
 };
 
@@ -368,14 +371,16 @@ typedef struct exclude_list_struct
   {
     char *string;
     struct exclude_list_struct *next;
+    int type;	
   }
 exclude_list_struct;
 
 static struct exclude_list_struct *excludes = 0;
 
 void
-pe_dll_add_excludes (new_excludes)
+pe_dll_add_excludes (new_excludes, type)
      const char *new_excludes;
+     const int type;	
 {
   char *local_copy;
   char *exclude_string;
@@ -391,6 +396,7 @@ pe_dll_add_excludes (new_excludes)
 		     xmalloc (sizeof (struct exclude_list_struct)));
       new_exclude->string = (char *) xmalloc (strlen (exclude_string) +
1);
       strcpy (new_exclude->string, exclude_string);
+      new_exclude->type = type;
       new_exclude->next = excludes;
       excludes = new_exclude;
     }
@@ -398,6 +404,7 @@ pe_dll_add_excludes (new_excludes)
   free (local_copy);
 }
 
+
 /* abfd is a bfd containing n (or NULL)
    It can be used for contextual checks.  */
 
@@ -410,9 +417,13 @@ auto_export (abfd, d, n)
   int i;
   struct exclude_list_struct *ex;
   autofilter_entry_type *afptr;
+  const char * libname = 0;
+  if (abfd && abfd->my_archive)
+    libname = lbasename (abfd->my_archive->filename);
 
   /* We should not re-export imported stuff.  */
-  if (strncmp (n, "_imp__", 6) == 0)
+  if ((strncmp (n, "_imp__", 6) == 0)
+      || (strncmp (n, "__imp_", 6) == 0)) 	
     return 0;
 
   for (i = 0; i < d->num_exports; i++)
@@ -429,14 +440,14 @@ auto_export (abfd, d, n)
 		n, abfd, abfd->my_archive);
 
       /* First of all, make context checks:
-         Don't export anything from libgcc.  */
-      if (abfd && abfd->my_archive)
+         Don't export anything from standard libs.  */
+      if (libname)	
 	{
 	  afptr = autofilter_liblist;
 
 	  while (afptr->name)
 	    {
-	      if (strstr (abfd->my_archive->filename, afptr->name))
+	      if (strncmp (libname, afptr->name, afptr->len) == 0 )
 		return 0;
 	      afptr++;
 	    }
@@ -495,8 +506,15 @@ auto_export (abfd, d, n)
     }
 
   for (ex = excludes; ex; ex = ex->next)
-    if (strcmp (n, ex->string) == 0)
-      return 0;
+    {
+      if (ex->type == 1)
+	{
+	  if (libname && (strcmp (libname, ex->string) == 0))
+            return 0;
+	}
+      else if (strcmp (n, ex->string) == 0)
+        return 0;	      		
+    }
 
   return 1;
 }
Index: src/ld/pe-dll.h
===================================================================
RCS file: /cvs/src/src/ld/pe-dll.h,v
retrieving revision 1.5
diff -u -p -r1.5 pe-dll.h
--- pe-dll.h	2001/09/12 15:58:10	1.5
+++ pe-dll.h	2001/11/21 08:20:19
@@ -36,7 +36,7 @@ extern int pe_dll_compat_implib;
 extern int pe_dll_extra_pe_debug;
 
 extern void pe_dll_id_target PARAMS ((const char *));
-extern void pe_dll_add_excludes PARAMS ((const char *));
+extern void pe_dll_add_excludes PARAMS ((const char *, const int));
 extern void pe_dll_generate_def_file PARAMS ((const char *));
 extern void pe_dll_generate_implib PARAMS ((def_file *, const char *));
 extern void pe_process_import_defs PARAMS ((bfd *, struct bfd_link_info
*));
Index: src/ld/emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.54
diff -u -p -r1.54 pe.em
--- pe.em	2001/09/24 18:21:24	1.54
+++ pe.em	2001/11/21 08:20:30
@@ -221,7 +221,9 @@ gld_${EMULATION_NAME}_before_parse()
 #define OPTION_DLL_ENABLE_AUTO_IMPORT	(OPTION_NO_DEFAULT_EXCLUDES + 1)
 #define OPTION_DLL_DISABLE_AUTO_IMPORT	(OPTION_DLL_ENABLE_AUTO_IMPORT + 1)
 #define OPTION_ENABLE_EXTRA_PE_DEBUG	(OPTION_DLL_DISABLE_AUTO_IMPORT + 1)
+#define OPTION_EXCLUDE_LIBS		(OPTION_ENABLE_EXTRA_PE_DEBUG + 1)
 
+
 static struct option longopts[] = {
   /* PE options */
   {"base-file", required_argument, NULL, OPTION_BASE_FILE},
@@ -247,6 +249,7 @@ static struct option longopts[] = {
   {"output-def", required_argument, NULL, OPTION_OUT_DEF},
   {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
   {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
+  {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},	
   {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
   {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
   {"enable-stdcall-fixup", no_argument, NULL,
OPTION_ENABLE_STDCALL_FIXUP},
@@ -333,6 +336,7 @@ gld_${EMULATION_NAME}_list_options (file
   fprintf (file, _("  --disable-stdcall-fixup            Don't link _sym
to _sym@nn\n"));
   fprintf (file, _("  --enable-stdcall-fixup             Link _sym to
_sym@nn without warnings\n"));
   fprintf (file, _("  --exclude-symbols sym,sym,...      Exclude symbols
from automatic export\n"));
+  fprintf (file, _("  --exclude-libs lib,lib,...         Exclude libraries
from automatic export\n"));	
   fprintf (file, _("  --export-all-symbols               Automatically
export all globals to DLL\n"));
   fprintf (file, _("  --kill-at                          Remove @nn from
exported symbols\n"));
   fprintf (file, _("  --out-implib <file>                Generate import
library\n"));
@@ -586,7 +590,10 @@ gld_${EMULATION_NAME}_parse_args(argc, a
       pe_dll_export_everything = 1;
       break;
     case OPTION_EXCLUDE_SYMBOLS:
-      pe_dll_add_excludes (optarg);
+      pe_dll_add_excludes (optarg, 0);
+      break;
+    case OPTION_EXCLUDE_LIBS:
+      pe_dll_add_excludes (optarg, 1);
       break;
     case OPTION_KILL_ATS:
       pe_dll_kill_ats = 1;



http://shopping.yahoo.com.au - Yahoo! Shopping
- Get organised for Christmas early this year!


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