Bug 58660 - ARM/Thumb non-interworking code broken in libgcc
Summary: ARM/Thumb non-interworking code broken in libgcc
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcc (show other bugs)
Version: 4.7.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-07 22:49 UTC by Jonathan Larmour
Modified: 2015-05-21 09:16 UTC (History)
1 user (show)

See Also:
Host:
Target: arm
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-05-21 00:00:00


Attachments
libgcc patch to correct operation with non-interworking thumb builds (551 bytes, patch)
2013-10-07 22:49 UTC, Jonathan Larmour
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Larmour 2013-10-07 22:49:02 UTC
Created attachment 30966 [details]
libgcc patch to correct operation with non-interworking thumb builds

I have included a multilib in my GCC for ARM to generate thumb code with interworking disabled, intended for an ARMv4T CPU (e.g. ARM7T or ARM9). In other words, -mcpu=arm9 -mthumb -mno-thumb-interwork.

However this fails to work because of a problem in libgcc making it incorrect 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.

As well as the obvious aeabi_ldivmod, someone may 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).

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

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

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

Thanks,

Jifl
Comment 1 Richard Earnshaw 2013-10-08 08:49:59 UTC
Please post patches to gcc-patches@gcc.gnu.org and x-ref this PR.
Comment 2 Ramana Radhakrishnan 2015-05-21 09:16:21 UTC
Confirmed.