This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: nested functions on Arm


> The nested function handling on Arm is completely broken in the
> moment.  This prevents glibc from being used on Arm in the moment.
> 
> The problem is this piece from config/arm/arm.h:
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /* Output assembler code for a block containing the constant parts
>    of a trampoline, leaving space for the variable parts.
> 
>    On the ARM, (if r8 is the static chain regnum, and remembering that
>    referencing pc adds an offset of 8) the trampoline looks like:
> 	   ldr 		r8, [pc, #0]
> 	   ldr		pc, [pc]
> 	   .word	static chain value
> 	   .word	function's address
>    ??? FIXME: When the trampoline returns, r8 will be clobbered.  */
> #define ARM_TRAMPOLINE_TEMPLATE(FILE)			\
> {							\
>   asm_fprintf (FILE, "\tldr\t%r, [%r, #0]\n",		\
> 	       STATIC_CHAIN_REGNUM, PC_REGNUM);		\
>   asm_fprintf (FILE, "\tldr\t%r, [%r, #0]\n",		\
> 	       PC_REGNUM, PC_REGNUM);			\
>   ASM_OUTPUT_INT (FILE, const0_rtx);			\
>   ASM_OUTPUT_INT (FILE, const0_rtx);			\
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> r8 must be saved by the called function but the trampoline code
> clobbers the register even before control reaches the actual function.

This is a known problem.  Unfortunately, I've no idea how to solve it.  
The fundamental problem is that we need a call clobbered register to pass 
the static chain, but there are none spare in the ARM ABI (r0-r3 are used 
for arguments, lr has the return address and ip is either used by the 
prologue code or, sometimes, for passing the PIC table base); all the 
other registers are call-saved.

Another gcc extension that turns out to be very difficult to support 
properly.

Richard



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]