[PATCH] Static linking binaries with uClibc

Will Newton will.newton at gmail.com
Fri Feb 5 11:51:54 UTC 2010


On Thu, Feb 4, 2010 at 10:45 PM, Bernhard Reutner-Fischer
<rep.dot.nop at gmail.com> wrote:

>> Pulling in stuff people don't need is going the way of the glibc, and
>>the uClibc FAQ explicitly claims that uClibc does things differently.
>> Please make sure it keeps living up to that claim. Please do not be
>>careless.
>
> Be assured that we will not instroduce bloat, in contrast, we continue
> to cut down on it.

I'll have one more attempt at a simple fix for the problem. This
change makes _stdio_init weak only in non-PIC builds. This allows
building of a minimal static library as before, and it also allows
linking the PIC library statically without a crash. The one case where
one gets stdio unnecessarily is where uClibc is built PIC (i.e. built
with .so support), the app is not using stdio and the user does a
static link.

>From 629195d44f1ef2082f46e2f323f2217af46d51d4 Mon Sep 17 00:00:00 2001
From: Will Newton <will.newton at gmail.com>
Date: Fri, 5 Feb 2010 11:43:57 +0000
Subject: [PATCH] uClibc: Make _stdio_init weak only when building non-PIC.

This allows users to build a minimal non-PIC static uClibc, but also avoids a
crash when linking statically with the PIC library.
---
 include/libc-symbols.h              |    6 ++++++
 libc/misc/internals/__uClibc_main.c |    2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index 2729d30..3908b57 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -195,6 +195,12 @@
 # define weak_function __attribute__ ((weak))
 # define weak_const_function __attribute__ ((weak, __const__))

+# ifdef __PIC__
+#  define weak_nonpic_function
+# else
+#  define weak_nonpic_function __attribute__ ((weak))
+# endif
+
 # ifdef HAVE_WEAK_SYMBOLS

 /* Define ALIASNAME as a weak alias for NAME.
diff --git a/libc/misc/internals/__uClibc_main.c
b/libc/misc/internals/__uClibc_main.c
index 6e520fa..a835296 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -68,7 +68,7 @@ libc_hidden_proto(__errno_location)
 extern int *weak_const_function __h_errno_location(void);
 libc_hidden_proto(__h_errno_location)

-extern void weak_function _stdio_init(void) attribute_hidden;
+extern void weak_nonpic_function _stdio_init(void) attribute_hidden;
 #ifdef __UCLIBC_HAS_LOCALE__
 extern void weak_function _locale_init(void) attribute_hidden;
 #endif
-- 
1.5.5.2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-uClibc-Make-_stdio_init-weak-only-when-building-non.patch
Type: application/octet-stream
Size: 1593 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/uclibc/attachments/20100205/8d0feefd/attachment.obj>


More information about the uClibc mailing list