<!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>
&gt; &gt; From: Nick Clifton &lt;nickc at redhat dot com&gt;<BR>
&gt; &gt;<BR>
&gt; &gt; Hi Ralf,<BR>
&gt; &gt;<BR>
&gt; &gt; &gt; while compiling trolltechs qt/xfree library with gcc3 (3.2x) on<BR>
&gt; &gt; &gt; cygwin I recognized, that the auto-import stuff in combination of<BR>
&gt; &gt; &gt; recent ld does not work in case of const variables in a dll when<BR>
&gt; &gt; &gt; using direct linking to a dll, because gcc put those variables into<BR>
&gt; &gt; &gt; a readonly, that means the .text section.<BR>
&gt; &gt; &gt;<BR>
&gt; &gt; &gt; The patch and a testcase is appended. A documentation could be found<BR>
&gt; &gt; &gt; in the patch file.<BR>
&gt; &gt;<BR>
&gt; &gt; Are you sure that the current linker does not work ?<BR>
&gt; &gt;<BR>
&gt; &gt; When I tried it, using the test case you supplied, but without the<BR>
&gt; &gt; patch applied, I got this:<BR>
&gt; &gt;<BR>
&gt; &gt;&nbsp;&nbsp; % make<BR>
&gt; &gt;&nbsp;&nbsp; ../gcc/g++ -B ../gcc/ -g&nbsp; -save-temps -c -o dll.o dll.cc<BR>
&gt; &gt;&nbsp;&nbsp; ../gcc/g++ -B ../gcc/ -g&nbsp; --shared -L ./i686-pc-cygwin/newlib -L<BR>
&gt; ../i686-pc-cygwin/libstdc++-v3/src/.libs dll.o -o dll.dll<BR>
&gt; &gt;&nbsp;&nbsp; ../gcc/g++ -B ../gcc/ -g&nbsp; -save-temps -c -o client.o client.cc<BR>
&gt; &gt;&nbsp;&nbsp; ../gcc/g++ -B ../gcc/ -g&nbsp; -o client client.o -L<BR>
&gt; ../i686-pc-cygwin/newlib -L<BR>
&gt; ../i686-pc-cygwin/libstdc++-v3/src/.libs -L. -ldll<BR>
&gt; &gt;&nbsp;&nbsp; Info: resolving _var by linking to __imp__var (auto-import)<BR>
&gt; &gt;&nbsp;&nbsp; Info: resolving test::var&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; by linking to __imp___ZN4test3varE<BR>
&gt; (auto-import)<BR>
&gt; &gt;<BR>
There must be four auto imported vars.<BR>
<BR>
&gt;<BR>
&gt; Yes, but try running ./client.exe.&nbsp; Since the const data variables are<BR>
&gt; in .text section they are treated as functions, not data.&nbsp; They are<BR>
&gt; imported without warning, but not as data.<BR>
&gt;<BR>
&gt; Ralf, what about a&nbsp; less intrusive approach? Compile dll<BR>
&gt; code with -fdata-sections. This will put const data in<BR>
&gt; .rdata$foo sections.&nbsp; Then, make pe_implied_import_dll()<BR>
&gt; scan .rdata as well as .data and .bss. for data symbols<BR>
&gt;<BR>
&gt; I've tried that with your testcase and it seems to work.<BR>
&gt;<BR>
What gcc release you are using ?&nbsp; 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++&nbsp; -save-temps -fdata-sections&nbsp;&nbsp;&nbsp; -c -o dll.o dll.cc<BR>
<BR>
$ less dll.s<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .file&nbsp;&nbsp; &quot;dll.cc&quot;<BR>
globl _var<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; section&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data$var,&quot;w&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .align 4<BR>
_var:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .long&nbsp;&nbsp; 1<BR>
globl _constvar<BR>
!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; section&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text$constvar,&quot;&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .align 4<BR>
_constvar:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .long&nbsp;&nbsp; 2<BR>
!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; section&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text$_ZZ4funcvE14staticconstvar,&quot;&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .align 4<BR>
_ZZ4funcvE14staticconstvar:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .long&nbsp;&nbsp; 2<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .text<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .align 2<BR>
globl __Z4funcv<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .def&nbsp;&nbsp;&nbsp; __Z4funcv;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .scl&nbsp;&nbsp;&nbsp; 2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .type&nbsp;&nbsp; 32;&nbsp;&nbsp;&nbsp;&nbsp; .endef<BR>
__Z4funcv:<BR>
LFB1:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pushl&nbsp;&nbsp; %ebp<BR>
LCFI0:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; movl&nbsp;&nbsp;&nbsp; %esp, %ebp<BR>
LCFI1:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; subl&nbsp;&nbsp;&nbsp; $4, %esp<BR>
LCFI2:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; movl&nbsp;&nbsp;&nbsp; $3, -4(%ebp)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; movl&nbsp;&nbsp;&nbsp; $1, %eax<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leave<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret<BR>
LFE1:<BR>
globl __ZN4test3varE<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; section&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data$_ZN4test3varE,&quot;w&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .align 4<BR>
__ZN4test3varE:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .long&nbsp;&nbsp; 4<BR>
globl __ZN4test14staticconstvarE<BR>
!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; section&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text$_ZN4test14staticconstvarE,&quot;&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .align 4<BR>
__ZN4test14staticconstvarE:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .long&nbsp;&nbsp; 5<BR>
<BR>
<BR>
<BR>
--<BR>
Unsubscribe info:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://cygwin.com/ml/#unsubscribe-simple">http://cygwin.com/ml/#unsubscribe-simple</A><BR>
Problem reports:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://cygwin.com/problems.html">http://cygwin.com/problems.html</A><BR>
Documentation:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://cygwin.com/docs.html">http://cygwin.com/docs.html</A><BR>
FAQ:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://cygwin.com/faq/">http://cygwin.com/faq/</A><BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>