<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6249.1">
<TITLE>!RE: [PATCH] gcc3/ld patch for direct-linking-to-dll and auto-importsupport</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi,<BR>
<BR>
<BR>
> > From: Nick Clifton <nickc at redhat dot com><BR>
> ><BR>
> > Hi Ralf,<BR>
> ><BR>
> > > while compiling trolltechs qt/xfree library with gcc3 (3.2x) on<BR>
> > > cygwin I recognized, that the auto-import stuff in combination of<BR>
> > > recent ld does not work in case of const variables in a dll when<BR>
> > > using direct linking to a dll, because gcc put those variables into<BR>
> > > a readonly, that means the .text section.<BR>
> > ><BR>
> > > The patch and a testcase is appended. A documentation could be found<BR>
> > > in the patch file.<BR>
> ><BR>
> > Are you sure that the current linker does not work ?<BR>
> ><BR>
> > When I tried it, using the test case you supplied, but without the<BR>
> > patch applied, I got this:<BR>
> ><BR>
> > % make<BR>
> > ../gcc/g++ -B ../gcc/ -g -save-temps -c -o dll.o dll.cc<BR>
> > ../gcc/g++ -B ../gcc/ -g --shared -L ./i686-pc-cygwin/newlib -L<BR>
> ../i686-pc-cygwin/libstdc++-v3/src/.libs dll.o -o dll.dll<BR>
> > ../gcc/g++ -B ../gcc/ -g -save-temps -c -o client.o client.cc<BR>
> > ../gcc/g++ -B ../gcc/ -g -o client client.o -L<BR>
> ../i686-pc-cygwin/newlib -L<BR>
> ../i686-pc-cygwin/libstdc++-v3/src/.libs -L. -ldll<BR>
> > Info: resolving _var by linking to __imp__var (auto-import)<BR>
> > Info: resolving test::var by linking to __imp___ZN4test3varE<BR>
> (auto-import)<BR>
> ><BR>
There must be four auto imported vars.<BR>
<BR>
><BR>
> Yes, but try running ./client.exe. Since the const data variables are<BR>
> in .text section they are treated as functions, not data. They are<BR>
> imported without warning, but not as data.<BR>
><BR>
> Ralf, what about a less intrusive approach? Compile dll<BR>
> code with -fdata-sections. This will put const data in<BR>
> .rdata$foo sections. Then, make pe_implied_import_dll()<BR>
> scan .rdata as well as .data and .bss. for data symbols<BR>
><BR>
> I've tried that with your testcase and it seems to work.<BR>
><BR>
What gcc release you are using ? It seems that gcc3.2 (which is the recent<BR>
cygwin release) does not support this. (See the ! below)<BR>
Are there any other gcc options to archive this ?<BR>
<BR>
$ gcc --version<BR>
gcc (GCC) 3.2 20020927 (prerelease)<BR>
<BR>
$ make<BR>
g++ -save-temps -fdata-sections -c -o dll.o dll.cc<BR>
<BR>
$ less dll.s<BR>
.file "dll.cc"<BR>
globl _var<BR>
section data$var,"w"<BR>
.align 4<BR>
_var:<BR>
.long 1<BR>
globl _constvar<BR>
! section text$constvar,""<BR>
.align 4<BR>
_constvar:<BR>
.long 2<BR>
! section text$_ZZ4funcvE14staticconstvar,""<BR>
.align 4<BR>
_ZZ4funcvE14staticconstvar:<BR>
.long 2<BR>
.text<BR>
.align 2<BR>
globl __Z4funcv<BR>
.def __Z4funcv; .scl 2; .type 32; .endef<BR>
__Z4funcv:<BR>
LFB1:<BR>
pushl %ebp<BR>
LCFI0:<BR>
movl %esp, %ebp<BR>
LCFI1:<BR>
subl $4, %esp<BR>
LCFI2:<BR>
movl $3, -4(%ebp)<BR>
movl $1, %eax<BR>
leave<BR>
ret<BR>
LFE1:<BR>
globl __ZN4test3varE<BR>
section data$_ZN4test3varE,"w"<BR>
.align 4<BR>
__ZN4test3varE:<BR>
.long 4<BR>
globl __ZN4test14staticconstvarE<BR>
! section text$_ZN4test14staticconstvarE,""<BR>
.align 4<BR>
__ZN4test14staticconstvarE:<BR>
.long 5<BR>
<BR>
<BR>
<BR>
--<BR>
Unsubscribe info: <A HREF="http://cygwin.com/ml/#unsubscribe-simple">http://cygwin.com/ml/#unsubscribe-simple</A><BR>
Problem reports: <A HREF="http://cygwin.com/problems.html">http://cygwin.com/problems.html</A><BR>
Documentation: <A HREF="http://cygwin.com/docs.html">http://cygwin.com/docs.html</A><BR>
FAQ: <A HREF="http://cygwin.com/faq/">http://cygwin.com/faq/</A><BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>