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: weak symbols on Cygwin


On 07/04/2010 10:06, Bruno Haible wrote:

> Thanks for these explanations. So, "#pragma weak" is very different on PE 
> systems than on ELF systems.

  Well, to be pedantically precise, "#pragma weak" is basically the same: it
shuts the linker up from complaining about a symbol if no definition is
provided at link time.  But it has downstream (from the linker) consequences
owing to the linker on PE being obliged to resolve everything and the linker
on ELF not having to.

> I was implicitly hoping that - gcc would collect all weak-declared symbols
> in some table, and generate code so that the reference to these symbols
> makes an indirection through this table, - the Cygwin runtime would call
> dlsym or GetProcAddress at startup and fill in addresses into said table.

  This is basically what the static linker (ld) and runtime loader (ld.so)
co-operate to achieve on ELF.  It is very likely possible to support something
like that on Cygwin, but it'd take some work to implement.

> I've got some code, written for ELF platforms, that detects whether the
> pthread library (often a separate library from libc) is linked, by doing
> 
> #pragma weak pthread_cancel bool pthread_in_use = (pthread_cancel != NULL);

  And you really need to determine this dynamically at runtime rather than
statically at configure time?  Fair enough; in that case I think Chuck's
suggestion that you use configure to choose between the runtime check on ELF
platforms and a statically-configured runtime-constant value on PE platforms
is probably the best solution.

    cheers,
      DaveK



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


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