On Mon, 10 Jun 2013 09:02:24 -0700
Cesar Philippidis <[email protected]> wrote:
> On 6/10/13 8:32 AM, Richard Earnshaw wrote:
> > On 07/06/13 17:50, Cesar Philippidis wrote:
> >> On 6/6/13 9:00 AM, Richard Earnshaw wrote:
> >>> The pipeline offset is 4 for Thumb2 as well. So at the very
> >>> least you need to explain why your change doesn't apply then as
> >>> well.
> >>
> >> Yes some context is lost in that comment. Thunks are usually
> >> emitted in ARM mode, except for Thumb-only targets. Is the new
> >> comment OK? If so, please check it in since I do not have SVN
> >> write access.
> >>
> >
> > So what about ARMv7-M, which is thumb2 but no ARM state?
>
> Thumb2 is handled differently. This patch is inside an if
> (TARGET_THUMB1) block.
To expand, with examples (from g++.old-deja/g++.jason/thunk2.C):
-O2 -S -march=armv4t -fPIC -mthumb:
.code 32
.type _ZThn4_N8CExample9MixinFuncEi1A, %function
_ZThn4_N8CExample9MixinFuncEi1A:
.fnstart
.LFB19:
ldr r12, .LTHUMBFUNC0
.LTHUNKPC0:
add r12, pc, r12
sub r1, r1, #4
bx r12
.align 2
.LTHUMBFUNC0:
.word .LTHUNK0-(.LTHUNKPC0+7)
(Thumb-1 mode, but thunk is in ARM mode, PC offset is 8.)
-O2 -S -march=armv6-m -fPIC -mthumb:
.code 16
.thumb_func
.type _ZThn4_N8CExample9MixinFuncEi1A, %function
_ZThn4_N8CExample9MixinFuncEi1A:
.fnstart
.LFB19:
push {r3}
ldr r3, .LTHUMBFUNC0
.LTHUNKPC0:
add r3, pc, r3
mov r12, r3
sub r1, r1, #4
pop {r3}
bx r12
.align 2
.LTHUMBFUNC0:
.word .LTHUNK0-(.LTHUNKPC0+7)
(Current *wrong* behaviour: Thumb mode thunk, but the pipeline offset is
still 8.)
-O2 -S -march=armv7-m -fPIC -mthumb:
.thumb
.thumb_func
.type _ZThn4_N8CExample9MixinFuncEi1A, %function
_ZThn4_N8CExample9MixinFuncEi1A:
.fnstart
.LFB19:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
sub r1, r1, #4
b .LTHUNK0(PLT)
(IIUC, wide branches are available, so there's no need for a synthesised
long PC-relative branch[-exchange]. Similar code is generated for ARM
mode on other architecture versions.)
Ahh -- so actually, maybe the right thing to do is use this last style
of thunk for v6-m, the same as v7-m -- is there any reason that
wouldn't work? (I wrote this patch to start with, but I don't remember
if I considered that possibility at the time...)
HTH,
Julian