Fix ARM/Thumb non-interworking problem in libgcc

Jonathan Larmour jifl@eCosCentric.com
Tue Oct 8 13:53:00 GMT 2013


This is forwarded from PR58660
(<http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58660>). Please CC me on
replies as I am not on the list.

In doing some testing of GCC 4.7.3 on a target with an ARMv4T CPU (e.g.
ARM7T or ARM9) I encountered a problem if using Thumb mode with
interworking disabled. For that, obviously I had to created a libgcc
multilib for this combination; for example: -mcpu=arm9 -mthumb
-mno-thumb-interwork.

However this fails to work in GCC 4.7.3 because of a problem in libgcc
making it fail to handle modes correctly for non-interworking operation. A
specific example is aeabi_uldivmod in bpabi.S which is an ARM (not thumb)
function, which includes a bl to __gnu_uldivmod_helper.
__gnu_uldivmod_helper is from bpabi.c and is in Thumb mode.

The linker helpfully adds a little trampoline to switch to Thumb mode
with the bx instruction (____gnu_uldivmod_helper_from_arm). However GCC
returns from __gnu_uldivmod_helper with:

  pop     {r3, r4, r5, r6, r7, pc}

This means that no mode switch happens on the return from the Thumb mode
function to the ARM mode aeabi_uldivmod function.

I am attaching a potential fix for the problem with aeabi_ldivmod and
aeabi_uldivmod (against 4.7.3), so it would be good for that to be applied
at least, including on the 4.7 and 4.8 branches.

2013-10-07  Jonathan Larmour  <jifl@eCosCentric.com>

	* config/arm/bpabi.S (aeabi_ldivmod, aeabi_uldivmod): Allow for
	non-interworking Thumb builds.

Someone may also want to double-check whether this sort of problem may
apply to other functions (although I haven't found any others yet myself,
but I'm not sure about how functions like those in unaligned-funcs.c would
be called).

Thanks,

Jifl
-- 
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------       Opinions==mine
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: arm.libgcc.thumb.no.interwork.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20131008/bb6e41b7/attachment.ksh>


More information about the Gcc-patches mailing list