static linking failed with sigaction testing program

Jian Peng jipeng at broadcom.com
Sat Mar 26 00:41:42 UTC 2011


This is a follow-up of my previous bug report on static linking failed with sigaction testing program.

With 0.9.32-rc3, following testing program failed with static linking on MIPS. The result is same with gcc-4.4.5 and gcc-4.5.2. While my old 0.9.29 uClibc plus gcc-4.4.5 works well.


Here is static-test.c

#include <signal.h>

int main(void)
{
    struct sigaction old, new;

    sigaction(11, &new, &old);
    return 3;
}

$ mipsel-linux-gcc static-test.c -o static-test -static -lpthread

/big/toolchains/stbgcc-4.5.2-0.2/bin/../mipsel-linux-uclibc/sys-root/usr/lib/libc.a(sigaction.os):
In function `__libc_sigaction':
sigaction.c:(.text+0x0): multiple definition of `__libc_sigaction'
/big/toolchains/stbgcc-4.5.2-0.2/bin/../mipsel-linux-uclibc/sys-root/usr/lib/libpthread.a(pt-sigaction.os):pt-sigaction.c:(.text+0x0):

first defined here
/big/toolchains/stbgcc-4.5.2-0.2/bin/../mipsel-linux-uclibc/sys-root/usr/lib/libc.a(sigaction.os):
In function `sigaction':
sigaction.c:(.text+0x18): multiple definition of `__sigaction'

/big/toolchains/stbgcc-4.5.2-0.2/bin/../mipsel-linux-uclibc/sys-root/usr/lib/libpthread.a(pt-sigaction.os):pt-sigaction.c:(.text+0x18):
first defined here
collect2: ld returned 1 exit status

$ mipsel-linux-gcc static-test.c -o static-test -static -lc -lpthread


has no problem.

The reason is that after sigaction was pulled in from libpthread.a:pt-sigaction.os, another runtime supporting function abort() in libc calls sigaction that will be pulled from libc.a:sigaction.os, and cause multiple definitions.

In case that "-static -lc -lpthread", sigaction was pulled from libc.a:sigaction.os to resolve undefined sigaction for both the one called in abort and main already.

To fix it, __libc_sigaction and __sigaction should not be GLOBAL in both libc.a and libpthread.a.


Here is my patch to fix it.

>From a322d80e01137f8d8287ffda716dbff05960cdab Mon Sep 17 00:00:00 2001
From: Jian Peng <jpeng2005 at gmail.com>
Date: Fri, 25 Mar 2011 16:12:58 -0700

Subject: [PATCH 1/1] MIPS: sigaction static linking failed

With simple sigaction testing program, "mipsel-linux-gcc prog.c -o prog -static -lpthread" failed to compile due to multiple definition error of __libc_sigaction and __sigaction.


The problem is that __libc_sigaction and __sigaction should not be GLOBAL in both libc.a and libpthread.a.

Signed-off-by: Jian Peng <jipeng2005 at gmail.com>
---

 libc/sysdeps/linux/mips/sigaction.c         |   19 +++++++++++++++----
 libpthread/nptl/sysdeps/pthread/sigaction.c |    3 +--
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/libc/sysdeps/linux/mips/sigaction.c b/libc/sysdeps/linux/mips/sigaction.c

index f2d2747..26b816c 100644
--- a/libc/sysdeps/linux/mips/sigaction.c
+++ b/libc/sysdeps/linux/mips/sigaction.c
@@ -27,8 +27,9 @@
 
 #define SA_RESTORER	0x04000000
 
-extern __typeof(sigaction) __libc_sigaction;

-
+#ifdef	NOT_IN_libc
+extern __typeof(sigaction) __libc_sigaction; 
+#endif
 
 #ifdef __NR_rt_sigaction
 
@@ -43,7 +44,12 @@ static void restore(void) __asm__ ("__restore");
 
 /* If ACT is not NULL, change the action for SIG to *ACT.

    If OACT is not NULL, put the old action for SIG in *OACT.  */
-int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
+#ifdef	NOT_IN_libc
+int
+#else
+static int
+#endif 

+__libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
 {
 # if _MIPS_SIM != _ABIO32
 	struct sigaction kact;
@@ -65,7 +71,12 @@ extern void restore(void) __asm__ ("__restore") attribute_hidden;

 
 /* If ACT is not NULL, change the action for SIG to *ACT.
    If OACT is not NULL, put the old action for SIG in *OACT.  */
-int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)

+#ifdef	NOT_IN_libc
+int
+#else
+static int
+#endif
+__libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
 {
 	int result;
 	struct old_kernel_sigaction kact, koact;
diff --git a/libpthread/nptl/sysdeps/pthread/sigaction.c b/libpthread/nptl/sysdeps/pthread/sigaction.c

index e004a39..190a3ab 100644
--- a/libpthread/nptl/sysdeps/pthread/sigaction.c
+++ b/libpthread/nptl/sysdeps/pthread/sigaction.c
@@ -26,8 +26,7 @@
 #define LIBC_SIGACTION	1
 #include <sigaction.c>

 
-extern __typeof(sigaction) __sigaction;
-int
+static int
 __sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
 {
   if (__builtin_expect (sig == SIGCANCEL || sig == SIGSETXID, 0))

-- 
1.7.4.1



More information about the uClibc mailing list