signal handerl and -fno-optimize-sibling-calls
Hiroshi SAKURAI
an.olive.tree@gmail.com
Thu Mar 2 03:40:00 GMT 2006
Hi,
I'm using NetBSD3.0 and gcc3.3.3.
Following program exits when it receives SIGWINCH signal
if built with -foptimize-sibling-calls.
$ gcc -Wall -foptimize-sibling-calls -g a.c
$ ./a.out &
[1] 15605
$ pkill -WINCH a.out
[1]+ Done ./a.out
If built without -foptimize-sibling-calls, it does not exit when
receiving SIGWINCH.
$ gcc -Wall -g a.c
$ ./a.out &
[1] 15605
$ pkill -WINCH a.out
$
With -foptimize-sibling-calls, a.out ended up calling setcontext(0) and exits.
Is this a bug of gcc or this optimization flag cannot be used to
compile signal handler?
Here's a output of uname and gcc -v.
$ uname -a
NetBSD tomato.odn.ne.jp 3.0 NetBSD 3.0 (GENERIC) #0: Fri Feb 24
00:50:03 JST 2006
sakurai@tomato.odn.ne.jp:/usr/home/sakurai/src/obj/sys/arch/i386/compile/GENERIC
i386
$ gcc -v
Using built-in specs.
Configured with:
/home/nick/work/netbsd/src/tools/gcc/../../gnu/dist/gcc/configure
--enable-long-long --disable-multilib --enable-threads
--disable-symvers --build=i386-unknown-netbsdelf2.0.
--host=i386--netbsdelf --target=i386--netbsdelf
Thread model: posix
gcc version 3.3.3 (NetBSD nb3 20040520)
I'm not a member of the list so please CC: me.
Thanks.
=========
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
int a;
void func( int sig, siginfo_t *info, void *context )
{
a = sig;
}
void handle_winch( int sig, siginfo_t *info, void *context )
{
func(sig, 0, 0);
}
int main(void)
{
struct sigaction act;
sigemptyset(&act.sa_mask);
act.sa_handler=SIG_IGN;
act.sa_flags = SA_SIGINFO;
act.sa_sigaction= &handle_winch;
if (sigaction(SIGWINCH, &act, 0) != 0) {
exit (1);
}
for (;;) {
sleep(1);
}
return 0;
}
=========
--
Hiroshi SAKURAI
http://vimrc.hp.infoseek.co.jp/
More information about the Gcc-help
mailing list