This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[Patch/ld] Fix pe-dll.c exclusion of MS-formatted (ILF) import lib internals when exporting symbols
- From: "Danny Smith" <dansmister at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Sat, 5 Jul 2008 22:01:02 +1200
- Subject: [Patch/ld] Fix pe-dll.c exclusion of MS-formatted (ILF) import lib internals when exporting symbols
When using --the export-all switch (explicitly or by default) for
building a PE .dll, the inclusion of of a MS-style (ILF) import lib,
causes bogus identifiers to be added to the export table.
For example, from Mingw-Bug reported at:
https://sourceforge.net/tracker/index.php?func=detail&aid=1901008&group_id=2435&atid=102435
With function.o containing a dependency on the MS PSDK library
wlanapi.dll, and using the MS import lib wlanapi.lib (in current dir)
to resolve that
dependency
ld -L./ -shared -o library.dll --output-def bad_syntax.def function.o -lwlanapi
produces the error
Cannot export Wlanapi_NULL_THUNK_DATA: symbol not found
and creates the bad_syntax.def file
EXPORTS
.idata$4 @1 DATA
.idata$5 @2 DATA
.idata$6 @3 DATA
_IMPORT_DESCRIPTOR_Wlanapi @4 DATA
_NULL_IMPORT_DESCRIPTOR @5 DATA
function @6
Wlanapi_NULL_THUNK_DATA DATA
The following patch fixes by filtering out these strings
(_IMPORT_DESCRIPTOR_. _NULL_THUNK_DATA, _NULL_IMPORT_DESCRIPTOR) used
internally by ILF libs, and extends the exclusion of the ".text" label to
all symbols starting with ".".
OK to commit?
2008-07-05 Danny Smith <dannysmith@users.sourceforge.net>
*pe-dll.c (autofilter_symbolprefixlist): Excude all symbols
starting with ".".
Exclude "_IMPORT_DESCRIPTOR_".
(autofilter_symbolsuffixlist): Exclude "_NULL_THUNK_DATA".
(autofilter_symbollist_generic): Don't check for ".text".
Exclude STRING_COMMA_LEN ("_NULL_IMPORT_DESCRIPTOR".
(autofilter_symbollist_i386): Likewise.
Index: pe-dll.c
===================================================================
RCS file: /cvs/src/src/ld/pe-dll.c,v
retrieving revision 1.105
diff -c -3 -p -r1.105 pe-dll.c
*** pe-dll.c 27 May 2008 08:34:26 -0000 1.105
--- pe-dll.c 5 Jul 2008 09:41:33 -0000
*************** pe_details_type;
*** 187,193 ****
static const autofilter_entry_type autofilter_symbollist_generic[] =
{
! { STRING_COMMA_LEN (".text") },
/* Entry point symbols. */
{ STRING_COMMA_LEN ("DllMain") },
{ STRING_COMMA_LEN ("DllMainCRTStartup") },
--- 187,193 ----
static const autofilter_entry_type autofilter_symbollist_generic[] =
{
! { STRING_COMMA_LEN ("_NULL_IMPORT_DESCRIPTOR") },
/* Entry point symbols. */
{ STRING_COMMA_LEN ("DllMain") },
{ STRING_COMMA_LEN ("DllMainCRTStartup") },
*************** static const autofilter_entry_type autof
*** 200,206 ****
static const autofilter_entry_type autofilter_symbollist_i386[] =
{
! { STRING_COMMA_LEN (".text") },
/* Entry point symbols, and entry hooks. */
{ STRING_COMMA_LEN ("cygwin_crt0") },
#ifdef pe_use_x86_64
--- 200,206 ----
static const autofilter_entry_type autofilter_symbollist_i386[] =
{
! { STRING_COMMA_LEN ("_NULL_IMPORT_DESCRIPTOR") },
/* Entry point symbols, and entry hooks. */
{ STRING_COMMA_LEN ("cygwin_crt0") },
#ifdef pe_use_x86_64
*************** static const autofilter_entry_type autof
*** 350,361 ****
--- 350,366 ----
{ STRING_COMMA_LEN ("_nm_") },
/* Don't export symbols specifying internal DLL layout. */
{ STRING_COMMA_LEN ("_head_") },
+ { STRING_COMMA_LEN ("_IMPORT_DESCRIPTOR_") },
+ /* Don't export section labels or artificial symbols
+ (eg ".weak.foo". */
+ { STRING_COMMA_LEN (".") },
{ NULL, 0 }
};
static const autofilter_entry_type autofilter_symbolsuffixlist[] =
{
{ STRING_COMMA_LEN ("_iname") },
+ { STRING_COMMA_LEN ("_NULL_THUNK_DATA") },
{ NULL, 0 }
};