gcc version 4.1. 20060120 Configured with: ../configure --target=h8300-elf --prefix=/usr/local --enable-languages=c,c++ --with-newlib --with-headers=/usr/src/newlib-1.14.0/newlib/libc/include ///////////////////////////////////// #include <setjmp.h> jmp_buf jb_error; void jump(void){ longjmp(jb_error,1); } void func1(void){ return; } int main(void){ setjmp(jb_error); func1(); jump(); } ///////////////////////////// This program compiled by h8300-elf-gcc(4.1) doesn't work. The program compiled by h8300-elf-gcc(3.4.3) with same library works.
You need to provide a more sensible test or a description of what "works" and "does not work" for this testcase is supposed to be.
h8300-elf-gcc(3.4.3) makes this object. 0x1a0 <main>: 6d f6 mov.w r6,@-e7 - 0x1a2 <main+2>: 0d 76 mov.w r7,r6 0x1a4 <main+4>: 79 00 1d 4a mov.w #0x1d4a,r0 - 0x1a8 <main+8>: 5e 00 01 f0 jsr @0x1f0:0 ; setjmp(jb_error) - 0x1ac <main+12>: 5e 00 01 98 jsr @0x198:0 ; func1() - 0x1b0 <main+16>: 5e 00 01 88 jsr @0x188:0 ; jump() - 0x1b4 <main+20>: 0d 20 mov.w r2,r0 - 0x1b6 <main+22>: 6d 76 mov.w @r7+,r6 - 0x1b8 <main+24>: 54 70 rts It works fine. run-> setjmp()->func1()->jump()->setjmp() .. h8300-elf-gcc(4.1.0) makes this object 0x1a8 <main>: 6d f6 mov.w r6,@-e7 - 0x1aa <main+2>: 0d 76 mov.w r7,r6 - 0x1ac <main+4>: 79 02 1d 1a mov.w #0x1d1a,r2 - 0x1b0 <main+8>: 6d f2 mov.w r2,@-e7 - 0x1b2 <main+10>: 5e 00 01 f8 jsr @0x1f8:0 - 0x1b6 <main+14>: 0b 87 adds #0x2,er7 - 0x1b8 <main+16>: 5e 00 01 a0 jsr @0x1a0:0 - 0x1bc <main+20>: 5e 00 01 8c jsr @0x18c:0 - 0x1c0 <main+24>: 6d 76 mov.w @r7+,r6 - 0x1c2 <main+26>: 54 70 rts It doesn't run correctly. run-> setjmp()->func1()->jump()-> freeze(Infinite loop in jump()) In more complex program, freeze when run into longjmp().
Can you try: #include <setjmp.h> jmp_buf jb_error; void jump(void){ longjmp(jb_error,1); } void func1(void){ return; } int main(void){ if(setjmp(jb_error)) return 0; func1(); jump(); } I am wondering if you are invoking undefined behavior in calling longjmp twice on the same setjmp.
No feedback in almost 5 years so closing.