386PE ld/strip - Import Library stripping, issues during auto import & specific imports
Ivan Warren
ivan@vmfacility.fr
Wed Sep 17 10:19:00 GMT 2003
Hello,
First of all, my apologies if this isssue has already been addressed. I
searched the archive but couldn't find anything relevant.
Note : This is an issue with the 386 PE linker/stripper. My tests are done
using "cygwin". This message has also been posted to the cygwin list as it
may be a cygwin issue rather than a binutils core issue.
I am running into the following problem :
If I issue a 'strip --strip-unneeded' to a DLL import library (created with
--out-implib), Most .data and/or .bss external references generate linking
errors.
Furthermore, if I specify a __declspec(dllimport) to the reference *AND* the
symbol is referenced by a DLL itself, the application raises SIGSEGV upon
attempting to access the symbol.
I am not sure binary attachments are allowed on this list, so here is a copy
& paste of the files necessary to reproduce the problem :
(note : the Makefile should have the spaces changed to a tab character)
<sample>
<File fn="Makefile">
maincode: maincode.o libmydll.dll.a
$(CC) $(CFLAGS) -o maincode maincode.o -L. -lmydll
libmydll.dll.a: dllcode.o libmydll2.dll.a
$(CC) dllcode.o -o cygmydll.dll -shared -L. -lmydll2
-Wl,--out-implib -Wl,libmydll.dll.a
strip --strip-unneeded libmydll.dll.a
libmydll2.dll.a: dllcode2.o
$(CC) dllcode2.o -o cygmydll2.dll -shared -Wl,--out-implib
-Wl,libmydll2.dll.a
strip --strip-unneeded libmydll2.dll.a
clean:
rm -f *.o
rm -f *.a
rm -f *.dll
rm -f *.exe
rm -f *.stackdump
</File>
<File fn="dllcode.c">
extern __declspec(dllimport) level2;
int somebss;
int somedata=2;
int sometext()
{
return(level2);
}
</File>
<File fn="dllcode2.c">
__declspec(dllexport) int level2=1;
</File>
<File fn="maincode.c">
extern __declspec(dllimport) int somebss;
extern __declspec(dllimport) int somedata;
extern __declspec(dllimport) int sometext();
int main()
{
printf("%d\n",somebss);
printf("%d\n",somedata);
printf("%d\n",sometext());
}
</File>
</sample>
If you run './maincode' after make, the programs crashes.
If you remove '__declspec(dllimport) from file 'dllcode.c' the link fails.
If you comment out the 'strip' from the Makefile, the program links AND runs
to completion.
My questions is :
Is this a 'cygwin' issue or a core binutils issue ?
Is there a workaround (besides NOT stripping the import library) ?
<version-info>
$ ld -V
GNU ld version 2.14.90 20030901
Supported emulations:
i386pe
$ strip --version
GNU strip 2.14.90 20030901
</version-info>
Note : this issues is a main concern when using 'libtool' because this
behaviour is shown when using a libtool in confunction with
automake/autoconf and a 'make install-strip' is issued.
Thanks,
--Ivan
More information about the Binutils
mailing list