ARM setjmp and r12

Nick Clifton nickc@redhat.com
Fri Apr 28 15:44:00 GMT 2006


Hi Konrad,

>>> On the ARM, why does setjmp preserve r12 (ip)?  I believe r12 is 
>>> caller-preserved, not callee-preserved.

>> I *think* that this is because GCC uses it as the static 
>> chain register for nested functions (when operating in ARM mode).

> Would that even be legal?

Yes...

> Shouldn't the contents/layout of jmpbuf be
> specified by the ABI?

The ARM EABI specifies the jmp_buf type as being an opaque type.  ie one 
whose contents are not specified by the EABI.  It does mandate that if 
the define _AEABI_PORTABILITY_LEVEL is 0 that the size of the jump 
buffer should be at least 8.  (See section 5.11 of the ARM C-library 
EABI for more information).

> Or how would different implementations interoperate?

By not sharing implementations of setjmp and longjmp.  ie if you link 
with the setjmp() implementation from one particular library you must 
also link with the longjmp() implementation from the same library.  This 
is usually not an issue, as you would have to try quite hard to link 
with different versions of these functions.

The only real issue is whether the code that invokes setjmp() and 
longjmp() have passed a sufficiently sized buffer in as one of the 
parameters.  Providing that the setjmp.h header files for the two 
different C libraries that you are using(1) define a jmp_buf type that 
is sufficiently large, then there should not be problems.

Cheers
   Nick

(1) Why on earth would you want to use two different C libraries anyway? 
  This is just asking for trouble.



More information about the Newlib mailing list