public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/28197] New: longjmp and alloca cause bus error
@ 2006-06-29 0:01 akr at m17n dot org
2006-06-29 2:32 ` [Bug target/28197] longjmp and alloca cause bus error at -O0 akr at m17n dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: akr at m17n dot org @ 2006-06-29 0:01 UTC (permalink / raw)
To: gcc-bugs
I got a bus error by following program which use longjmp and __builtin_alloca
with -O0.
% cat z.c
#include <setjmp.h>
jmp_buf env;
void f(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
{
longjmp(env, 1);
}
int main()
{
if (setjmp(env) == 0) {
void *p = __builtin_alloca(4);
f(1,2,3,4,5,6,7,8);
}
return 0;
}
% ~/src/gcc/bin/gcc -E z.c > z.i
% cat z.i
# 1 "z.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "z.c"
# 1 "/usr/include/setjmp.h" 1 3 4
# 26 "/usr/include/setjmp.h" 3 4
# 1 "/usr/include/machine/setjmp.h" 1 3 4
# 29 "/usr/include/machine/setjmp.h" 3 4
# 1 "/usr/include/ppc/setjmp.h" 1 3 4
# 31 "/usr/include/ppc/setjmp.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 32 "/usr/include/ppc/setjmp.h" 2 3 4
# 1 "/usr/include/machine/signal.h" 1 3 4
# 27 "/usr/include/machine/signal.h" 3 4
# 1 "/usr/include/ppc/signal.h" 1 3 4
# 29 "/usr/include/ppc/signal.h" 3 4
# 1 "/usr/include/sys/appleapiopts.h" 1 3 4
# 30 "/usr/include/ppc/signal.h" 2 3 4
typedef int sig_atomic_t;
# 50 "/usr/include/ppc/signal.h" 3 4
typedef enum {
REGS_SAVED_NONE,
REGS_SAVED_CALLER,
REGS_SAVED_ALL
} regs_saved_t;
# 66 "/usr/include/ppc/signal.h" 3 4
struct sigcontext32 {
int sc_onstack;
int sc_mask;
int sc_ir;
int sc_psw;
int sc_sp;
void *sc_regs;
};
struct sigcontext64 {
int sc_onstack;
int sc_mask;
long long sc_ir;
long long sc_psw;
long long sc_sp;
void *sc_regs;
};
struct sigcontext {
int sc_onstack;
int sc_mask;
int sc_ir;
int sc_psw;
int sc_sp;
void *sc_regs;
};
# 28 "/usr/include/machine/signal.h" 2 3 4
# 33 "/usr/include/ppc/setjmp.h" 2 3 4
struct _jmp_buf {
struct sigcontext sigcontext;
unsigned int vmask __attribute__((aligned(8)));
unsigned int vreg[32 * 4] __attribute__((aligned(16)));
};
# 82 "/usr/include/ppc/setjmp.h" 3 4
typedef int jmp_buf[(26 + 18*2 + 129 + 1)];
typedef int sigjmp_buf[(26 + 18*2 + 129 + 1) + 1];
extern int setjmp(jmp_buf env);
extern void longjmp(jmp_buf env, int val);
int _setjmp(jmp_buf env);
void _longjmp(jmp_buf, int val);
int sigsetjmp(sigjmp_buf env, int val);
void siglongjmp(sigjmp_buf env, int val);
void longjmperror(void);
# 30 "/usr/include/machine/setjmp.h" 2 3 4
# 27 "/usr/include/setjmp.h" 2 3 4
# 2 "z.c" 2
jmp_buf env;
void f(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
{
longjmp(env, 1);
}
int main()
{
if (setjmp(env) == 0) {
void *p = __builtin_alloca(4);
f(1,2,3,4,5,6,7,8);
}
return 0;
}
% ~/src/gcc/bin/gcc -O0 -g -v z.i
Using built-in specs.
Target: powerpc-apple-darwin8.6.0
Configured with: ../gcc-4.1.1/configure --prefix=/Users/akr/src/gcc
--enable-languages=c --with-as=/Users/akr/src/odcctools/bin/as
--with-ld=/Users/akr/src/odcctools/bin/ld
Thread model: posix
gcc version 4.1.1
/Users/akr/src/gcc/libexec/gcc/powerpc-apple-darwin8.6.0/4.1.1/cc1
-fpreprocessed z.i -feliminate-unused-debug-symbols -fPIC -quiet -dumpbase z.i
-auxbase z -g -O0 -version -o /var/tmp//ccD20CPP.s
GNU C version 4.1.1 (powerpc-apple-darwin8.6.0)
compiled by GNU C version 4.1.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 060081fe4c432c1f8e1af4cf790a4da4
/Users/akr/src/odcctools/bin/as -arch ppc -o /var/tmp//cck0sLjz.o
/var/tmp//ccD20CPP.s
/Users/akr/src/gcc/libexec/gcc/powerpc-apple-darwin8.6.0/4.1.1/collect2
-dynamic -arch ppc -weak_reference_mismatches non-weak -o a.out -lcrt1.o
/Users/akr/src/gcc/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1/crt2.o
-L/Users/akr/src/gcc/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1
-L/Users/akr/src/gcc/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1/../../..
/var/tmp//cck0sLjz.o -lgcc -lSystemStubs -lSystem
% ./a.out
zsh: bus error ./a.out
% uname -a
Darwin ppc64.tky.aist.go.jp 8.6.0 Darwin Kernel Version 8.6.0: Tue Mar 7
16:58:48 PST 2006; root:xnu-792.6.70.obj~1/RELEASE_PPC Power Macintosh powerpc
--
Summary: longjmp and alloca cause bus error
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: akr at m17n dot org
GCC build triplet: powerpc-apple-darwin8.6.0
GCC host triplet: powerpc-apple-darwin8.6.0
GCC target triplet: powerpc-apple-darwin8.6.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28197
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/28197] longjmp and alloca cause bus error at -O0
2006-06-29 0:01 [Bug c/28197] New: longjmp and alloca cause bus error akr at m17n dot org
@ 2006-06-29 2:32 ` akr at m17n dot org
2006-10-29 21:29 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: akr at m17n dot org @ 2006-06-29 2:32 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from akr at m17n dot org 2006-06-29 01:49 -------
I found a way to reproduce the bus error with -O2 as well as -O0.
% cat z.c
#include <setjmp.h>
jmp_buf env;
int i;
int main()
{
if (setjmp(env) == 0) {
char *p = __builtin_alloca(1024);
for (i = 0; i < 1024; i++) {
p[i] = 0;
}
longjmp(env, 1);
}
return 0;
}
Z:akr@ppc64.tky.aist.go.jp% ~/src/gcc/bin/gcc -O2 -v z.c
Using built-in specs.
Target: powerpc-apple-darwin8.6.0
Configured with: ../gcc-4.1.1/configure --prefix=/Users/akr/src/gcc
--enable-languages=c --with-as=/Users/akr/src/odcctools/bin/as
--with-ld=/Users/akr/src/odcctools/bin/ld
Thread model: posix
gcc version 4.1.1
/Users/akr/src/gcc/libexec/gcc/powerpc-apple-darwin8.6.0/4.1.1/cc1 -quiet -v
-D__DYNAMIC__ z.c -fPIC -quiet -dumpbase z.c -auxbase z -O2 -version -o
/var/tmp//ccCHTcUf.s
ignoring nonexistent directory
"/Users/akr/src/gcc/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1/../../../../powerpc-apple-darwin8.6.0/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Users/akr/src/gcc/include
/Users/akr/src/gcc/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1/include
/usr/include
/System/Library/Frameworks
/Library/Frameworks
End of search list.
GNU C version 4.1.1 (powerpc-apple-darwin8.6.0)
compiled by GNU C version 4.1.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 060081fe4c432c1f8e1af4cf790a4da4
/Users/akr/src/odcctools/bin/as -arch ppc -o /var/tmp//ccsOCM5w.o
/var/tmp//ccCHTcUf.s
/Users/akr/src/gcc/libexec/gcc/powerpc-apple-darwin8.6.0/4.1.1/collect2
-dynamic -arch ppc -weak_reference_mismatches non-weak -o a.out -lcrt1.o
/Users/akr/src/gcc/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1/crt2.o
-L/Users/akr/src/gcc/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1
-L/Users/akr/src/gcc/lib/gcc/powerpc-apple-darwin8.6.0/4.1.1/../../..
/var/tmp//ccsOCM5w.o -lgcc -lSystemStubs -lSystem
% ./a.out
zsh: bus error ./a.out
% ~/src/gcc/bin/gcc -O0 z.c
% ./a.out
zsh: bus error ./a.out
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28197
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/28197] longjmp and alloca cause bus error at -O0
2006-06-29 0:01 [Bug c/28197] New: longjmp and alloca cause bus error akr at m17n dot org
2006-06-29 2:32 ` [Bug target/28197] longjmp and alloca cause bus error at -O0 akr at m17n dot org
@ 2006-10-29 21:29 ` pinskia at gcc dot gnu dot org
2007-04-25 18:50 ` geoffk at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-10-29 21:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2006-10-29 21:29 -------
This is not a bug in GCC but rather longjump/setjmp on Darwin, report this bug
to Apple.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28197
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/28197] longjmp and alloca cause bus error at -O0
2006-06-29 0:01 [Bug c/28197] New: longjmp and alloca cause bus error akr at m17n dot org
2006-06-29 2:32 ` [Bug target/28197] longjmp and alloca cause bus error at -O0 akr at m17n dot org
2006-10-29 21:29 ` pinskia at gcc dot gnu dot org
@ 2007-04-25 18:50 ` geoffk at gcc dot gnu dot org
2007-04-25 18:50 ` geoffk at gcc dot gnu dot org
2007-05-07 5:57 ` akr at m17n dot org
4 siblings, 0 replies; 6+ messages in thread
From: geoffk at gcc dot gnu dot org @ 2007-04-25 18:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from geoffk at gcc dot gnu dot org 2007-04-25 19:49 -------
I'm fairly sure this is in fact a bug in GCC. The problem is that in a routine
which uses setjmp, alloca() must ensure that the previous stack backchain is
preserved, which means it needs to allocate enough space for its allocation,
the linkage area, *and* arguments for any called function. It's not allocating
enough space for called function arguments. In the routine given, it's only
allocating 32 bytes where it actually needs to allocate 64.
--
geoffk at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28197
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/28197] longjmp and alloca cause bus error at -O0
2006-06-29 0:01 [Bug c/28197] New: longjmp and alloca cause bus error akr at m17n dot org
` (2 preceding siblings ...)
2007-04-25 18:50 ` geoffk at gcc dot gnu dot org
@ 2007-04-25 18:50 ` geoffk at gcc dot gnu dot org
2007-05-07 5:57 ` akr at m17n dot org
4 siblings, 0 replies; 6+ messages in thread
From: geoffk at gcc dot gnu dot org @ 2007-04-25 18:50 UTC (permalink / raw)
To: gcc-bugs
--
geoffk at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-04-25 19:50:13
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28197
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/28197] longjmp and alloca cause bus error at -O0
2006-06-29 0:01 [Bug c/28197] New: longjmp and alloca cause bus error akr at m17n dot org
` (3 preceding siblings ...)
2007-04-25 18:50 ` geoffk at gcc dot gnu dot org
@ 2007-05-07 5:57 ` akr at m17n dot org
4 siblings, 0 replies; 6+ messages in thread
From: akr at m17n dot org @ 2007-05-07 5:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from akr at m17n dot org 2007-05-07 06:56 -------
I think the problem can be fixed by alloca or setjmp.
* alloca extends a stack as the old stack backchain will not crashed, or
* setjmp saves the stack backchain and longjmp restore it.
I'm not sure that which should be done.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28197
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-05-07 5:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-29 0:01 [Bug c/28197] New: longjmp and alloca cause bus error akr at m17n dot org
2006-06-29 2:32 ` [Bug target/28197] longjmp and alloca cause bus error at -O0 akr at m17n dot org
2006-10-29 21:29 ` pinskia at gcc dot gnu dot org
2007-04-25 18:50 ` geoffk at gcc dot gnu dot org
2007-04-25 18:50 ` geoffk at gcc dot gnu dot org
2007-05-07 5:57 ` akr at m17n dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).