This is the mail archive of the
mailing list for the Cygwin project.
Re: weak symbols on Cygwin
- From: Bruno Haible <bruno at clisp dot org>
- To: Eric Blake <eblake at redhat dot com>, Dave Korn <dave dot korn dot cygwin at googlemail dot com>, cygwin at cygwin dot com
- Date: Wed, 7 Apr 2010 01:41:35 +0200
- Subject: Re: weak symbols on Cygwin
- References: <4BBB31C6.firstname.lastname@example.org>
Dave Korn wrote:
> >> These were all due to the fact that gcc 4.3.x on Cygwin 1.7.2
> >> accepts "#pragma weak foo", but the symbol foo then evaluates
> >> to the NULL address, even if foo is defined in libc.
> > Dave, are weak symbols something that should work on cygwin with new
> > enough binutils/gcc? Or is this an indicator of a gcc bug, for silently
> > accepting #pragma weak foo that it can't support?
> Weak symbols work on Cygwin, but the semantics of undefined weak symbols
> aren't identical to ELF platforms: a weak reference won't pull in an archive
> member that wouldn't otherwise be linked; the implications in relation to
> import libraries should be fairly obvious.
I don't know what semantics is implemented by "#pragma weak" on Cygwin.
On ELF platforms, I use "#pragma weak" in order to detect whether a symbol
is defined in the libraries which are linked in with the executable
(including libc). This does not work on Cygwin: this program
extern void gurky (void);
#pragma weak fputs
#pragma weak gurky
int main ()
printf ("fputs %s, gurky %s\n",
fputs != NULL ? "present" : "missing",
gurky != NULL ? "present" : "missing");
compiled and run with
$ gcc -o foo foo.c -Wall
prints on glibc systems:
fputs present, gurky missing
but on Cygwin 1.7.2:
fputs missing, gurky missing
With this inability to distinguish present from missing libc symbols,
"#pragma weak" is useless to me on Cygwin.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple