[PATCH] weak symbols need to be "defined" weak but "declared" strong

Vineet Gupta Vineet.Gupta1 at synopsys.com
Wed Apr 16 12:15:28 UTC 2014

On Wednesday 16 April 2014 05:33 PM, Bernhard Reutner-Fischer wrote:
> Joern, Vineet,
> On 16 April 2014 12:36, Vineet Gupta <Vineet.Gupta1 at synopsys.com> wrote:
>> > Patch "LT.old: Make __errno_location/__h_errno_location thread safe"
>> > uncovered yet another bug with static linking and errno (hopefully this
>> > is last of them all).
>> >
>> > Currently, __errno_location is declared weak but is defined strong.
>> > While this provides with the desired weak semantics in dso, it
>> > is subtly broken in static links.
>> >
>> > Quoting Joern Rennecke (ARC gcc expert):
>> >
>> > | I think the issue is that you declare the function as weak in the
>> > | header file.  That is a rare instance where you want the reference
>> > | use declaration that differs a bit from the definition.
>> > | If the reference uses a weakly declared function, that creates a
>> > | weakref, i.e. the linker won't bother to look for this symbol at
>> > |  all - if it gets linked in for some other reason, fine,
>> > | otherwise, it stays zero.
> Sounds like this is, once again, http://gcc.gnu.org/PR36282 ;
> see patch referenced in that PR and the reason for our not_null_ptr()
> workaround, no?
> thanks,

Did you mean http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32219 instead.

Anyhow, using not_null_pointer() is just band aid - what it will do is not
generate reference to __errno_location (using gcc constant expression elimination)
and preventing a runtime segv. However this is a semantical change to program
since we no longer have the needed __errno_location call itself. User programs
might fail if they rely on errno being set (on say mmap failure)

Joern's proposal above fixes the root cause so NULL ref is not generated in first


More information about the uClibc mailing list