thumb-2 and crt0.S init_hooks

Alexandre Pereira Nunes
Fri Dec 19 20:48:00 GMT 2008


It seems that there's a problem with the patch suggested on

This sort of constructs:

+#if defined(__thumb__) || defined(__thumb2__)
+	blx   r3
 	mov	lr, pc
 	mov	pc, r3

Will probably fail on armv4t targets. The reason is that this
architecture lacks support for the blx instruction.
Also, on thumb1 targets, mov lr, pc will do right thing, because the
calling code is in arm mode, but the mov pc, r3 may fail to call a
thumb function.

The way I see it, this sequence will probably work fine:

+#if defined(__thumb2__)
+	blx   r3
 	mov	lr, pc
 	bx r3

But there's still a catch on armv4t targets, if the code is compiled
with -mno-thumb-interwork (default for arm-elf targets, but not for
arm-*-eabi ones): some gcc versions tends to emit mov pc, lr or
similar sequences in order to return from thumb functions, and on this
case, a thunk has to be implemented to manually switch from thumb to
arm mode since the processor is unable to do this by itself.

I'm too lazy to write a patch right now, but I may work on that later.

More information about the Newlib mailing list