Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 2 Sep 2019 22:10:10 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: About those weak aliases

* Markus Wichmann <nullplan@....net> [2019-09-02 21:04:48 +0200]:
> I'd like to know what those weak aliases are for in the many cases where
> they are used to define a public interface. Or, more to the point, by
> what criteria they are handed out, and by what logic the internal
> symbols are used.
> 
> For instance, pthread_mutex_lock() et al. are weakly defined, but

it's a weak alias for __pthread_mutex_lock which can be used
to implement iso c apis (where pthread* is not reserved and
thus may conflict with user defined symbols)

__pthread_mutex_lock is not used internally right now, but
e.g. __pthread_mutex_timedlock is.

(could be a strong alias, weakness of public api symbols
doesn't matter, you can only observe the difference by
getting a link error when static linking a conflicting
definition, but that is non-standard: when the symbol is
reserved for the implementation user code must not use it)

so following namespace rules for static linking is one
reason for aliases. and musl only uses weak aliases.

there are other usage of weak symbols, there was a patch
that tried to cathegorize them:

https://www.openwall.com/lists/musl/2013/02/15/1

> pthread_cond_wait() is not. Unlike pthread_cond_timedwait(), which is
> called from pthread_cond_wait() by the public symbol that might be
> interposed. Makes sense, since pthread_cond_wait() does not depend on
> mutex internals (pthread_cond_timedwait() does).
> 
> I found no C standard function with a weak definition. But I did find
> crypt() being strongly defined, but it calls the internal (strong)
> definition of crypt_r(), rather than the weak one.
> 
> So I thought maybe the C standard functions get strong definitions and
> all others get weak ones. But open(), close(), etc. are also defined
> strongly, while fdopen() gets a weak definition. And those are all in
> POSIX. Meanwhile, adjtime() gets a strong definition, as does
> getdents(), and those are Linux specialities.
> 
> So yeah,I have so far failed to identify any rhyme or reason to these
> definitions. Can anyone help me?
> 
> Ciao,
> Markus

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.