Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com To: cygwin AT cygwin DOT com From: Rolf Campbell Subject: Basic C/C++ (Was: 1.5.10: problems relocating structures with function pointers) Date: Wed, 21 Jul 2004 12:47:04 -0400 Lines: 67 Message-ID: References: <40FE9B4B DOT 6090901 AT expertron DOT co DOT za> Reply-To: cygwin DOT 0 DOT endlisnis AT spamgourmet DOT org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet AT sea DOT gmane DOT org X-Gmane-NNTP-Posting-Host: ottgw.tropicnetworks.com User-Agent: Mozilla Thunderbird 0.7.2 (Windows/20040707) In-Reply-To: <40FE9B4B.6090901@expertron.co.za> X-IsSubscribed: yes Justin Schoeman wrote: > I have discovered what may be a bug in the linker/relocater in cygwin > (or, more likely, I am doing something stupid again). > > When I use a structure containing function pointers, and this structure > is placed in an archive, then the function pointer becomes NULL. As an > example, compile the attached files as follows: > > gcc -O2 -Wall -c inc.c > ar rsvc inc.a inc.c > gcc -O2 -Wall -o test test.c inc.a > > Executing test.exe prints 0x0 (the address of the function cointained in > the structure), and subsequently segfaults. > > Relinking with > > gcc -O2 -Wall -o test test.c inc.o > > produces a binary that works correctly. > > It seems that once the object file is archived, the dynamic loader > losses the capability of correctly assigning the function addresses? > > Any help would be greatly appreciated. > > TIA, > -justin > > > ------------------------------------------------------------------------ > > #include > > static void junk(void) > { > fprintf(stderr, "JUNK!\n"); > } > > struct js { > void (*junk)(void); > }; > > const struct js jsi = { junk }; > > > ------------------------------------------------------------------------ > > #include > > struct js { > void (*junk)(void); > }; > > struct js jsi; extern struct js jsi; ^^^^^^ > > int main(void) > { > fprintf(stderr, "%p\n", jsi.junk); > jsi.junk(); > return 0; > } > > -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/