[klibc] signal handling broken on i386 (Re: fix i386 build)

Sergey Vlasov vsu at altlinux.ru
Mon May 10 13:28:23 PDT 2010


On Mon, Mar 15, 2010 at 02:44:47AM +0100, maximilian attems wrote:
> still inverstigating sparc, belows fixed i386 build
> and tested utils on it.
> 
> fixes fallout:
>  gcc -Wp,-MD,usr/klibc/.vsnprintf.o.d  -nostdinc -iwithprefix include -I/build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/include/arch/i386 -Iusr/include/arch/i386 -I/build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/include/bits32 -Iusr/include/bits32 -I/build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include -Iusr/klibc/../include -I/build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/include -Iusr/include -I/build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/linux/include -Ilinux/include -I/build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/linux/arch/i386/include -Ilinux/arch/i386/include -D__KLIBC__=1 -D__KLIBC_MINOR__=5 -D_BITSIZE=32 -fno-stack-protector -mregparm=3 -D_REGPARM=3 -m32 -march=i386 -Os -g -fomit-frame-pointer -falign-functions=0 -falign-jumps=0 -falign-loops=0 -W -Wall -Wno-sign-compare -Wno-unused-parameter -c -o usr/klibc/vsnprintf.o usr/klibc/vsnprintf.c
> In file included from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/include/arch/i386/klibc/archsignal.h:99,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/signal.h:14,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/sys/select.h:11,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/unistd.h:12,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/stdio.h:11,
>                  from usr/klibc/vsnprintf.c:13:
> /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/linux/include/asm-generic/signal.h:7:1: warning: "_NSIG_BPW" redefined
> In file included from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/signal.h:14,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/sys/select.h:11,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/unistd.h:12,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/stdio.h:11,
>                  from usr/klibc/vsnprintf.c:13:
> /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/include/arch/i386/klibc/archsignal.h:17:1: warning: this is the location of the previous definition
> In file included from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/include/arch/i386/klibc/archsignal.h:99,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/signal.h:14,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/sys/select.h:11,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/unistd.h:12,
>                  from /build/buildd-klibc_1.5.16-1-i386-e8cAsi/klibc-1.5.16/usr/klibc/../include/stdio.h:11,
>                  from usr/klibc/vsnprintf.c:13:
> 
> 
> commit 3cd286a4bff43ea339d2a815047703d134c0ecfc
> Author: maximilian attems <max at stro.at>
> Date:   Mon Mar 15 02:35:43 2010 +0100
> 
>     [klibc] Use x86_32 cleaned up signal.h
>     
>     x86 merges cleaned the header up, do the inverse then arm:
>     nuke duplication.
>     
>     Signed-off-by: maximilian attems <max at stro.at>
> 
> diff --git a/usr/include/arch/i386/klibc/archsignal.h b/usr/include/arch/i386/klibc/archsignal.h
> index 6c942db..c83fc8f 100644
> --- a/usr/include/arch/i386/klibc/archsignal.h
> +++ b/usr/include/arch/i386/klibc/archsignal.h
> @@ -1,5 +1,4 @@
>  /*
> - * arch/i386/include/klibc/archsignal.h
>   *
>   * Architecture-specific signal definitions
>   *
> @@ -8,107 +7,8 @@
>  #ifndef _KLIBC_ARCHSIGNAL_H
>  #define _KLIBC_ARCHSIGNAL_H
>  
> -/* The in-kernel headers for i386 still have libc5
> -   crap in them.  Reconsider using <asm/signal.h>
> -   when/if it gets cleaned up; for now, duplicate
> -   the definitions here. */
> +/* The in-kernel headers for i386 got clean up, use them. */
>  
> -#define _NSIG           64
> -#define _NSIG_BPW       32
> -#define _NSIG_WORDS     (_NSIG / _NSIG_BPW)
> -
> -typedef struct {
> -	unsigned long sig[_NSIG_WORDS];
> -} sigset_t;
> -
> -#define SIGHUP           1
> -#define SIGINT           2
> -#define SIGQUIT          3
> -#define SIGILL           4
> -#define SIGTRAP          5
> -#define SIGABRT          6
> -#define SIGIOT           6
> -#define SIGBUS           7
> -#define SIGFPE           8
> -#define SIGKILL          9
> -#define SIGUSR1         10
> -#define SIGSEGV         11
> -#define SIGUSR2         12
> -#define SIGPIPE         13
> -#define SIGALRM         14
> -#define SIGTERM         15
> -#define SIGSTKFLT       16
> -#define SIGCHLD         17
> -#define SIGCONT         18
> -#define SIGSTOP         19
> -#define SIGTSTP         20
> -#define SIGTTIN         21
> -#define SIGTTOU         22
> -#define SIGURG          23
> -#define SIGXCPU         24
> -#define SIGXFSZ         25
> -#define SIGVTALRM       26
> -#define SIGPROF         27
> -#define SIGWINCH        28
> -#define SIGIO           29
> -#define SIGPOLL         SIGIO
> -#define SIGPWR          30
> -#define SIGSYS          31
> -#define SIGUNUSED       31
> -
> -#define SIGRTMIN        32
> -#define SIGRTMAX        (_NSIG-1)
> -
> -/*
> - * SA_FLAGS values:
> - *
> - * SA_ONSTACK indicates that a registered stack_t will be used.
> - * SA_INTERRUPT is a no-op, but left due to historical reasons. Use the
> - * SA_RESTART flag to get restarting signals (which were the default long ago)
> - * SA_NOCLDSTOP flag to turn off SIGCHLD when children stop.
> - * SA_RESETHAND clears the handler when the signal is delivered.
> - * SA_NOCLDWAIT flag on SIGCHLD to inhibit zombies.
> - * SA_NODEFER prevents the current signal from being masked in the handler.
> - *
> - * SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single
> - * Unix names RESETHAND and NODEFER respectively.
> - */
> -#define SA_NOCLDSTOP	0x00000001u
> -#define SA_NOCLDWAIT	0x00000002u
> -#define SA_SIGINFO	0x00000004u
> -#define SA_ONSTACK	0x08000000u
> -#define SA_RESTART	0x10000000u
> -#define SA_NODEFER	0x40000000u
> -#define SA_RESETHAND	0x80000000u
> -
> -#define SA_NOMASK	SA_NODEFER
> -#define SA_ONESHOT	SA_RESETHAND
> -#define SA_INTERRUPT	0x20000000	/* dummy -- ignored */
> -
> -#define SA_RESTORER	0x04000000
> -
> -/*
> - * sigaltstack controls
> - */
> -#define SS_ONSTACK	1
> -#define SS_DISABLE	2
> -
> -#define MINSIGSTKSZ	2048
> -#define SIGSTKSZ	8192
> -
> -#include <asm-generic/signal.h>
> -
> -/* This uses gcc anonymous union support... */
> -struct siginfo;
> -
> -struct sigaction {
> -	union {
> -		__sighandler_t sa_handler;
> -		void (*sa_sigaction)(int, struct siginfo *, void *);
> -	};
> -	unsigned long	sa_flags;
> -	__sigrestore_t 	sa_restorer;
> -	sigset_t	sa_mask;
> -};
> +#include <linux/signal.h>
>  
>  #endif

This compiles, but fails at runtime on i386, because
arch/x86/include/asm/signal.h in the kernel does not provide the
correct definition of sigset_t needed for klibc:

| #ifdef __KERNEL__
| #include <linux/linkage.h>
| 
| /* Most things should be clean enough to redefine this at will, if care
|    is taken to make libc match.  */
| 
| #define _NSIG           64
| 
| #ifdef __i386__
| # define _NSIG_BPW      32
| #else
| # define _NSIG_BPW      64
| #endif
| 
| #define _NSIG_WORDS     (_NSIG / _NSIG_BPW)
| 
| typedef unsigned long old_sigset_t;             /* at least 32 bits */
| 
| typedef struct {
|         unsigned long sig[_NSIG_WORDS];
| } sigset_t;
| 
| #else
| /* Here we must cater to libcs that poke about in kernel headers.  */
| 
| #define NSIG            32
| typedef unsigned long sigset_t;
| 
| #endif /* __KERNEL__ */

This gives sizeof(sigset_t) == 4, which is then rejected with EINVAL
by rt_sigprocmask() and other syscalls.  The subsequent definition of
struct sigaction is also wrong for klibc.

Looks like the libc5 crap is not really dead yet...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://www.zytor.com/pipermail/klibc/attachments/20100511/aea33ad9/attachment.sig>


More information about the klibc mailing list