This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: thumb-2 and crt0.S init_hooks
- From: "Alexandre Pereira Nunes" <alexandre dot nunes at gmail dot com>
- To: newlib at sourceware dot org
- Date: Thu, 18 Dec 2008 16:06:41 -0200
- Subject: Re: thumb-2 and crt0.S init_hooks
Hi,
It seems that there's a problem with the patch suggested on
http://sourceware.org/ml/newlib/2008/msg00500.html.
This sort of constructs:
+#if defined(__thumb__) || defined(__thumb2__)
+ blx r3
+#else
mov lr, pc
mov pc, r3
+#endif
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
+#else
mov lr, pc
bx r3
+#endif
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.