[PATCH] Static linking binaries with uClibc

Will Newton will.newton at gmail.com
Thu Feb 4 11:16:14 UTC 2010


On Thu, Feb 4, 2010 at 10:46 AM, Bernhard Reutner-Fischer
<rep.dot.nop at gmail.com> wrote:
> On Thu, Feb 04, 2010 at 10:31:31AM +0000, Will Newton wrote:
>>On Thu, Feb 4, 2010 at 10:22 AM, Bernhard Reutner-Fischer
>><rep.dot.nop at gmail.com> wrote:
>>
>>Hi Bernhard,
>>
>>> On Wed, Feb 03, 2010 at 09:07:03PM +0100, Bernhard Reutner-Fischer wrote:
>>>>On Wed, Feb 03, 2010 at 04:21:29PM +0000, Will Newton wrote:
>>>>>Hello,
>>>>>
>>>>>I have a problem with linking applications statically with uClibc but
>>>>>without including the stdio functions. This issue has been brought up
>>>>
>>>>See http://bugs.uClibc.org/1033
>>>>My theory (which is essentially size-neutral) goes like this, and yes,
>>>>it's not pretty but seems to work for me:
>>>
>>> I've attached a possible fix to the PR.
>>
>>Thanks for working on this.
>>
>>I think the patch goes a bit too far however. The problem is only with
>>symbols that are weak *and* hidden:
>>
>>libc/misc/internals/__uClibc_main.c:extern void weak_function
>>_stdio_init(void) attribute_hidden;
>>libc/misc/internals/__uClibc_main.c:extern void weak_function
>>_locale_init(void) attribute_hidden;
>>libc/misc/internals/shared_flat_add_library.c:extern void _init(void)
>>attribute_hidden weak_function;
>>libc/misc/internals/shared_flat_add_library.c:extern void _fini(void)
>>attribute_hidden weak_function;
>>libc/stdlib/_atexit.c:extern void weak_function _stdio_term(void)
>>attribute_hidden;
>>libc/stdlib/abort.c:extern void weak_function _stdio_term(void)
>>attribute_hidden;
>>
>>__pthread_initialize_minimal and __errno_location are not hidden so do
>>not need to be changed.
>
> I didn't try locale or pthread, but i suggest you backout the errno
> stuff and run:
> #include <unistd.h>
> int main(void){return write("toast\n", 6) != 6;}
>
> If you can confirm that either of the locale hunk or the pthread hunk is
> not needed, then we'll certainly drop it. Please let me know.

The locale change is needed as it stands, i.e. with locale_init being
weak, but I would argue that the simpler and easier fix is to make
locale_init not weak. I don't see why someone would build a uClibc
with locale enabled and static link against it and then complain when
they get locale support. There is no use case for that, it seems
irrelevant to me.

The pthread change is not needed, as the disassembly of __uClibc_init
will reveal.


More information about the uClibc mailing list