www.delorie.com/archives/browse.cgi | search |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
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 <Endlisnis AT mailc DOT net> |
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: | <cdm6m9$rae$1@sea.gmane.org> |
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 |
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 <stdio.h> > > static void junk(void) > { > fprintf(stderr, "JUNK!\n"); > } > > struct js { > void (*junk)(void); > }; > > const struct js jsi = { junk }; > > > ------------------------------------------------------------------------ > > #include <stdio.h> > > 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/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |