This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 1.5.10: problems relocating structures with function pointers


As was explained in the previous post, the structure must be defined as 'extern' when referenced from test.c - a stupid mistake from my side. Why I thought it was a bug was that the code worked perfectly on the same compiler version under Linux and Solaris, but failed under Cygwin.

The fact that it works on Linux, means that the 'bug' (the compiler linking against an extern symbol, even when declared localy) exists on almost all current versions of gcc / binutils...

Could be an interesting bug to fix, but should not _really_ be a problem, as it is unlikely to be triggered in good code.

Thanks,
-justin

H. Henning Schmidt 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.


You are constructing two instances of type <struct js>. One as global
static member of the module <inc>, and another instance in module
<test>. The one in module <inc> gets initalized (i.e. func pointer is
set to address of local func <junk>), the other one remains
uninitialized. Both of these instances of type <struct js> are named
<jsi> ... which is certainly a little confusing.
AFAIK, the code in main() should always and only reference the local
instance (the uninitialized one from module <test>), which would result
in an output of either 0x0 (or any other random number, really ... this
is just reading unitialized memory).

To my understanding, the fact that your second linker invocation (direct
linking, no static archive involved) does use the static (and thus
presumably invisible) instance of <struct js> from the <inc> module does
indicate a (completely different) bug in the linker ...

--
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/


-- 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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]