C++ Exception handling

Nick Burrett nick at dsvr.net
Thu Feb 26 01:48:24 PST 2004

I've never heard or seen any reports of exception handling issues.


Peter Naulls wrote:
> Graham Shaw has found a fix for exception handling issues in GCC 2.95.4.
> I don't know if they also apply to 3.3.3, but I've quoted the relevant
> parts and the patch:
>>The problem is that not enough memory is being allocated for the setjmp
>>buffer, and as a result the last word is being overwritten by other code. 
>>(The last word contains the program counter, so the consequences of
>>overwriting it are invariably rather serious :-)
>>AFAIKT the problem is (surprisingly) not the definition of JMP_BUF_SIZE,
>>but rather the number of words allocated above and beyond this value (to
>>accommodate some other data stored by the exception handling code).  A
>>possible fix is attached.
>>What I don't understand is why this bug has suddenly appeared now, because
>>the code in question can be traced right back to the upstream GCC sources.
>>It would only happen on architectures that use setjmp buffers for
>>exception handling, and then only if JMP_BUF_SIZE is defined in the
>>makefile (rather than using the built-in heuristic), but even then I would
>>have expected it to have surfaced by now - if not for other platforms,
>>then at least for the 26-bit RISC OS compiler.
>>(The code certainly looks wrong.  It says that the jump buffer starts two
>>words into the area allocated, but the requested size is
>>Really this needs to be checked by someone who knows a bit more about the
>>internals of GCC than I do.  On the upside, I can't see my patch doing
>>much harm (except for slightly increasing run-time memory usage) and it
>>does seem to work.
> diff -ur gccsdk/gcc/gcc/except.c gccsdk-295/gcc/gcc/except.c
> --- gccsdk/gcc/gcc/except.c	Thu Feb 26 08:16:48 2004
> +++ gccsdk-295/gcc/gcc/except.c	Thu Feb 26 08:14:25 2004
> @@ -1363,7 +1363,7 @@
>       but there is no allocation routine that allocates at the level of
>       the last binding contour.  */
>    arg = assign_stack_local (BLKmode,
> -			    GET_MODE_SIZE (Pmode)*(size+2),
> +			    GET_MODE_SIZE (Pmode)*(size+1),
>  			    0);
>    arg = change_address (arg, Pmode, NULL_RTX);

Nick Burrett, Senior Systems and Network Engineer
Designer Servers Ltd.   http://www.dsvr.co.uk

More information about the gcc mailing list