public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Excude whole libs when building w32  dlls with -export-all
@ 2002-04-27  0:48 Danny Smith
  0 siblings, 0 replies; 6+ messages in thread
From: Danny Smith @ 2002-04-27  0:48 UTC (permalink / raw)
  To: binutils; +Cc: cygwin-apps

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

The auto-export feature of ld for pe-dll targets would be more flexible
with an option to exclude whole archive libs from export.

Here is an example:

test.c==================================================
/* test.c */
#include <libiberty.h> /* for lbasename */

__attribute__((dllexport))  void
dll_test (void)
{
  printf("%s\n", lbasename ("./test.c"));
};
test.c==================================================


This command:

gcc -shared -o test.dll test.c  -Wl,--export-all -liberty

currently produces a dll that exports these symbols:

dll_test
lbasename    ; from libiberty.a
_sch_istable ; from libiberty.a
_sch_tolower ; from libiberty.a
_sch_toupper ; from libiberty.a
 

The following patch allows exclusion of specified libs or all libs.
So that:
gcc -shared -o test.dll test.c  -Wl,--export-all,
  -Wl,--exclude-libs,libiberty.a \
  -liberty

exports only dll_test.

-Wl,--exclude-libs,ALL
would do the same.

Explicitly listing exports in .def file will override the --exclude-lib switch,
eg

test.def==============================================

;test.def
EXPORTS
lbasename

test.def=============================================

gcc -shared -o test.dll test.c test.def  -Wl,--export-all,
  -Wl,--exclude-libs,libiberty.a \
  -liberty

exports:
dll_test
lbasename

The patch also adds a few more default system lib excludes. I haven't tried
-shared with Ada runtime libs.  libgnat.a maybe another one that should be
excluded by default.

2002-04-27  Danny Smith  <dannysmith@users.sourceforge.net>

	* emultempl/pe.em (OPTION_EXCLUDE_LIBS): Add new define.
	(longopts): Add new option --exclude-libs.
	(gld_${EMULATION_NAME}_list_options): Give quick help about it.
	(gld_${EMULATION_NAME}_parse_args): Use it.
	* pe-dll.h (pe_dll_add_excludes): Add second param to prototype.
	* pe-dll.c (exclude_list_struct): Add field type to distinguish
	symbols from whole archives.
	(pe_dll_add_excludes): Set excludes->type.
	(auto_export): Add new variable libname and set to
 	archive basename if abfd. Use it when filtering default and
	user-specified libarary excludes. Let string "ALL" mean all libs
	when filtering user-specified libs.
	* ld.texinfo: Document --exclude-libs.

	* pe-dll.c (autofilter_liblist): Add more libs excluded by
	 default.
	
Diff file is attached.  There are some long lines in pe.em
(gld_${EMULATION_NAME}_list_options) that may get wrapped. 

Danny




http://messenger.yahoo.com.au - Yahoo! Messenger
- A great way to communicate long-distance for FREE!

[-- Attachment #2: pe-dll-auto-export.diff --]
[-- Type: text/plain, Size: 6871 bytes --]

Index: ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.67
diff -u -p -r1.67 ld.texinfo
--- ld.texinfo	8 Apr 2002 00:24:02 -0000	1.67
+++ ld.texinfo	27 Apr 2002 07:32:23 -0000
@@ -1656,6 +1656,14 @@ These cygwin-excludes are: @code{_cygwin
 Specifies a list of symbols which should not be automatically
 exported.  The symbol names may be delimited by commas or colons.
 
+@kindex --exclude-libs
+@item --exclude-libs @var{lib},@var{lib},...
+Specifies a list of archive libraries from which symbols should not be automatically
+exported. The library names may be delimited by commas or colons.  Specifying
+@code{--exclude-libs ALL} excludes symbols in all archive libraries from
+automatic export. Symbols explicitly listed in a .def file are still exported,
+regardless of this option. 
+
 @kindex --file-alignment
 @item --file-alignment
 Specify the file alignment.  Sections in the file will always begin at
Index: pe-dll.c
===================================================================
RCS file: /cvs/src/src/ld/pe-dll.c,v
retrieving revision 1.38
diff -u -p -r1.38 pe-dll.c
--- pe-dll.c	15 Feb 2002 02:11:05 -0000	1.38
+++ pe-dll.c	27 Apr 2002 07:32:29 -0000
@@ -231,6 +231,9 @@ static autofilter_entry_type autofilter_
   { "libgcc.", 7 },
   { "libstdc++.", 10 },
   { "libmingw32.", 11 },
+  { "libg2c.", 7 },
+  { "libsupc++.", 10 },
+  { "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,12 @@ 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) 	
     return 0;
 
   for (i = 0; i < d->num_exports; i++)
@@ -429,14 +439,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 +505,17 @@ auto_export (abfd, d, n)
     }
 
   for (ex = excludes; ex; ex = ex->next)
-    if (strcmp (n, ex->string) == 0)
-      return 0;
+    {
+      if (ex->type == 1) /* exclude-libs */
+	{
+	  if (libname
+	      && ((strcmp (libname, ex->string) == 0)
+		   || (stricmp ("ALL", ex->string) == 0)))
+	    return 0;
+	}
+      else if (strcmp (n, ex->string) == 0)
+        return 0;	      		
+    }
 
   return 1;
 }
Index: 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	12 Sep 2001 15:58:10 -0000	1.5
+++ pe-dll.h	27 Apr 2002 07:32:29 -0000
@@ -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: emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.59
diff -u -p -r1.59 pe.em
--- emultempl/pe.em	15 Feb 2002 02:11:05 -0000	1.59
+++ emultempl/pe.em	27 Apr 2002 07:32:35 -0000
@@ -221,6 +221,7 @@ 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 */
@@ -247,6 +248,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 +335,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 +589,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;

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

* RE: Excude whole libs when building w32  dlls with -export-all
@ 2002-04-27 17:36 Robert Collins
  0 siblings, 0 replies; 6+ messages in thread
From: Robert Collins @ 2002-04-27 17:36 UTC (permalink / raw)
  To: Robert Collins, Charles Wilson; +Cc: Danny Smith, binutils, cygwin-apps



> -----Original Message-----
> From: Robert Collins 
> Sent: Sunday, April 28, 2002 3:36 AM

> Yeah well :}. Actually most import libs can be considered to 
> contain code - that's what the standard stub is. The 


Oops. The standar=d stub *used* to be. *blush*.

Rob

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

* RE: Excude whole libs when building w32  dlls with -export-all
  2002-04-27 10:35 Robert Collins
@ 2002-04-27 11:31 ` Ralf Habacker
  0 siblings, 0 replies; 6+ messages in thread
From: Ralf Habacker @ 2002-04-27 11:31 UTC (permalink / raw)
  To: Robert Collins, Charles Wilson; +Cc: Danny Smith, binutils, cygwin-apps

> I too like the patch Danny has put forward, (not that I didn't speak
> against it :]). I'm hoping to review Ralf's patch tomorrow & will try
> and get to Danny's as well. I'm going to test on a non-HEAD ld, and if
> that works correctly, then IMO it can go into HEAD... as long as that
> part hasn't altered significantly between my testpoint and HEAD.

I have applied this already to the CVS head. I works. :-)
Ralf 

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

* RE: Excude whole libs when building w32  dlls with -export-all
@ 2002-04-27 10:35 Robert Collins
  2002-04-27 11:31 ` Ralf Habacker
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Collins @ 2002-04-27 10:35 UTC (permalink / raw)
  To: Charles Wilson; +Cc: Danny Smith, binutils, cygwin-apps



> -----Original Message-----
> From: Charles Wilson [mailto:cwilson@ece.gatech.edu] 
> Sent: Sunday, April 28, 2002 2:26 AM
> To: Robert Collins
> Cc: Danny Smith; binutils; cygwin-apps
> Subject: Re: Excude whole libs when building w32 dlls with -export-all
> 
> 
> Robert Collins wrote:
> 
> 
> > Can we detect libs and automatically exclude symbols from shared 
> > libraries?
> > 
> > i.e. when linking against libcygwin.a, ALL symbols therein 
> are from a 
> > dll, so -by default- should not be exported.
> 
> 
> Picky point: that's not true in this case.  libcygwin.a, unlike most 
> import libs, contains actual code as well as import thunks 
> for cygwin1.dll.

Yeah well :}. Actually most import libs can be considered to contain
code - that's what the standard stub is. The important point is not to
*ignore* the library, but to not *re-export* it's symbols.
 
> I dunno if we need something *less* granular (e.g. never never never 
> export ANY symbol of ANY kind that comes from *.dll) ... 
> maybe so.  But, 
> this is a separate argument from Danny's proposed patch.

True. However the current code in ld is a kludge. Always has-been, and
if not fixed... always will-be.
 
I too like the patch Danny has put forward, (not that I didn't speak
against it :]). I'm hoping to review Ralf's patch tomorrow & will try
and get to Danny's as well. I'm going to test on a non-HEAD ld, and if
that works correctly, then IMO it can go into HEAD... as long as that
part hasn't altered significantly between my testpoint and HEAD.

Rob

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

* Re: Excude whole libs when building w32  dlls with -export-all
  2002-04-27  2:09 Robert Collins
@ 2002-04-27  9:23 ` Charles Wilson
  0 siblings, 0 replies; 6+ messages in thread
From: Charles Wilson @ 2002-04-27  9:23 UTC (permalink / raw)
  To: Robert Collins; +Cc: Danny Smith, binutils, cygwin-apps

Robert Collins wrote:


> Can we detect libs and automatically exclude symbols from shared
> libraries? 
> 
> i.e. when linking against libcygwin.a, ALL symbols therein are from a
> dll, so -by default- should not be exported.


Picky point: that's not true in this case.  libcygwin.a, unlike most 
import libs, contains actual code as well as import thunks for cygwin1.dll.

 
> That would remove the need for many default exclusions, and be closer to
> unix behaviour (as I understand it).


We already exclude symbols beginning with _imp_, and Ralf's patch (well, 
part of it, IIRC) adds an additional exclusion for symbols beginning 
with _nm_.  And, of course, the data thunks _fu0_ are never re-exported.

I dunno if we need something *less* granular (e.g. never never never 
export ANY symbol of ANY kind that comes from *.dll) ... maybe so.  But, 
this is a separate argument from Danny's proposed patch.

Danny is addressing Ralf's long-desired ability to exclude symbols from 
static convenience libraries that are used by multiple KDE dlls. 
Without this ability, multiple KDE DLLs have export the same symbols, 
leading to linking errors when building apps.  This has forced Ralf to 
se a specially hacked binutils for all KDE builds.

I like Danny's patch, as it is more flexible than the one Ralf has been 
using (Ralf's was basically: " --exclude-libs -lfoo -bar 
--no-exclude-libs -baz" IIRC, so that symbols from libfoo and libbar 
would not be exported, but symbols from libbaz would be).

Ordinarily, at this point, I'd say: "I'll build a binutils and give your 
patch a try" -- except for the reports that say binutils has been broken 
on x86 since mid-December.  I *really* don't have the time right now to 
track THAT down, just to test Danny's patch -- I'm in hardcore 
dissertation mode, right now...

--Chuck

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

* RE: Excude whole libs when building w32  dlls with -export-all
@ 2002-04-27  2:09 Robert Collins
  2002-04-27  9:23 ` Charles Wilson
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Collins @ 2002-04-27  2:09 UTC (permalink / raw)
  To: Danny Smith, binutils; +Cc: cygwin-apps



> -----Original Message-----
> From: Danny Smith [mailto:danny_r_smith_2001@yahoo.co.nz] 
> Sent: Saturday, April 27, 2002 5:48 PM
> To: binutils
> Cc: cygwin-apps
> Subject: Excude whole libs when building w32 dlls with -export-all
> 
> 
> The auto-export feature of ld for pe-dll targets would be 
> more flexible with an option to exclude whole archive libs 
> from export.

Can we detect libs and automatically exclude symbols from shared
libraries? 

i.e. when linking against libcygwin.a, ALL symbols therein are from a
dll, so -by default- should not be exported.

That would remove the need for many default exclusions, and be closer to
unix behaviour (as I understand it).

Rob

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

end of thread, other threads:[~2002-04-28  0:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-27  0:48 Excude whole libs when building w32 dlls with -export-all Danny Smith
2002-04-27  2:09 Robert Collins
2002-04-27  9:23 ` Charles Wilson
2002-04-27 10:35 Robert Collins
2002-04-27 11:31 ` Ralf Habacker
2002-04-27 17:36 Robert Collins

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