Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Re: AArch64 calling convention in assembly code
       [not found] <CAN8C2CqGq4OUNXq5=ur87nqwVjYF-D6aAcVKGGB1pQT1S0b6Jg@mail.gmail.com>
@ 2018-08-01 13:28 ` Alexander Fedotov
  2018-08-01 15:49   ` Richard Earnshaw (lists)
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Fedotov @ 2018-08-01 13:28 UTC (permalink / raw)
  To: newlib; +Cc: gdb

>>Pushing LR on the stack resolves a problem
FP of course, not LR.
So the correct code must be like this:

_cpu_init_hook:
    stp        x29, x30, [sp, #-16]!
    mov        x29, sp
    bl        _init_vectors
    bl        _flat_map
    ldp        x29, x30, [sp], #16
    ret

But still my point is that GDB should catch such an error and do not hang.

Alex

On Tue, Jul 31, 2018 at 9:34 PM, Alexander Fedotov <alfedotov@gmail.com> wrote:
> Hello dear AArch64 maintainers
> Please look into code snippet below from newlib/libgloss/aarch64/rdimon-aem-el3.
>
> Seems to me this code violates AArch64 calling convention and actually
> breaks debugging in GDB. GDB tries to unwind call stack and got
> endless reentrancy...
>
> FUNCTION (_cpu_init_hook):
>     sub    sp, sp, #16
>     str    x30, [sp, xzr]
>     bl    _init_vectors
>     bl    _flat_map
>     ldr    x30, [sp, xzr]
>     add    sp, sp, #16
>     ret
>
>
> We have couple of calls there (_init_vectors, _flat_map). If you'll
> try to step into any subroutine you will found that GDB hangs and
> can't step anymore.
>
> Pushing LR on the stack resolves a problem.
>
> So my message is that:
> 1. Current code in _cpu_init_hook is incorrect
> 2. GDB should handle this and do not hang
>
> Alex



-- 
Best regards,
AF


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: AArch64 calling convention in assembly code
  2018-08-01 13:28 ` AArch64 calling convention in assembly code Alexander Fedotov
@ 2018-08-01 15:49   ` Richard Earnshaw (lists)
  2018-08-01 15:56     ` Alexander Fedotov
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Earnshaw (lists) @ 2018-08-01 15:49 UTC (permalink / raw)
  To: Alexander Fedotov, newlib; +Cc: gdb

On 01/08/18 14:28, Alexander Fedotov wrote:
>>> Pushing LR on the stack resolves a problem
> FP of course, not LR.
> So the correct code must be like this:
> 
> _cpu_init_hook:
>     stp        x29, x30, [sp, #-16]!
>     mov        x29, sp
>     bl        _init_vectors
>     bl        _flat_map
>     ldp        x29, x30, [sp], #16
>     ret
> 
> But still my point is that GDB should catch such an error and do not hang.
> 
> Alex
> 
> On Tue, Jul 31, 2018 at 9:34 PM, Alexander Fedotov <alfedotov@gmail.com> wrote:
>> Hello dear AArch64 maintainers
>> Please look into code snippet below from newlib/libgloss/aarch64/rdimon-aem-el3.
>>
>> Seems to me this code violates AArch64 calling convention and actually
>> breaks debugging in GDB. GDB tries to unwind call stack and got
>> endless reentrancy...
>>
>> FUNCTION (_cpu_init_hook):
>>     sub    sp, sp, #16
>>     str    x30, [sp, xzr]
>>     bl    _init_vectors
>>     bl    _flat_map
>>     ldr    x30, [sp, xzr]
>>     add    sp, sp, #16
>>     ret
>>
>>
>> We have couple of calls there (_init_vectors, _flat_map). If you'll
>> try to step into any subroutine you will found that GDB hangs and
>> can't step anymore.
>>
>> Pushing LR on the stack resolves a problem.

X30 is LR.

All we really need is a CFI unwind record that GDB can understand.

R.

>>
>> So my message is that:
>> 1. Current code in _cpu_init_hook is incorrect
>> 2. GDB should handle this and do not hang
>>
>> Alex
> 
> 
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: AArch64 calling convention in assembly code
  2018-08-01 15:49   ` Richard Earnshaw (lists)
@ 2018-08-01 15:56     ` Alexander Fedotov
  2018-08-01 16:19       ` Richard Earnshaw (lists)
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Fedotov @ 2018-08-01 15:56 UTC (permalink / raw)
  To: Richard Earnshaw (lists); +Cc: newlib, gdb

Yes, but X29 is not saved in original version. I can understand this
with 'frame-less functions" approach. So this code has a right for a
life.

I suspect that such a problem could happen if user will pass
"-fomit-frame-pointer" option to GCC as well.

>>All we really need is a CFI unwind record that GDB can understand.
For plain assembly code ?

Alex

On Wed, Aug 1, 2018 at 6:48 PM, Richard Earnshaw (lists)
<Richard.Earnshaw@arm.com> wrote:
> On 01/08/18 14:28, Alexander Fedotov wrote:
>>>> Pushing LR on the stack resolves a problem
>> FP of course, not LR.
>> So the correct code must be like this:
>>
>> _cpu_init_hook:
>>     stp        x29, x30, [sp, #-16]!
>>     mov        x29, sp
>>     bl        _init_vectors
>>     bl        _flat_map
>>     ldp        x29, x30, [sp], #16
>>     ret
>>
>> But still my point is that GDB should catch such an error and do not hang.
>>
>> Alex
>>
>> On Tue, Jul 31, 2018 at 9:34 PM, Alexander Fedotov <alfedotov@gmail.com> wrote:
>>> Hello dear AArch64 maintainers
>>> Please look into code snippet below from newlib/libgloss/aarch64/rdimon-aem-el3.
>>>
>>> Seems to me this code violates AArch64 calling convention and actually
>>> breaks debugging in GDB. GDB tries to unwind call stack and got
>>> endless reentrancy...
>>>
>>> FUNCTION (_cpu_init_hook):
>>>     sub    sp, sp, #16
>>>     str    x30, [sp, xzr]
>>>     bl    _init_vectors
>>>     bl    _flat_map
>>>     ldr    x30, [sp, xzr]
>>>     add    sp, sp, #16
>>>     ret
>>>
>>>
>>> We have couple of calls there (_init_vectors, _flat_map). If you'll
>>> try to step into any subroutine you will found that GDB hangs and
>>> can't step anymore.
>>>
>>> Pushing LR on the stack resolves a problem.
>
> X30 is LR.
>
> All we really need is a CFI unwind record that GDB can understand.
>
> R.
>
>>>
>>> So my message is that:
>>> 1. Current code in _cpu_init_hook is incorrect
>>> 2. GDB should handle this and do not hang
>>>
>>> Alex
>>
>>
>>
>



-- 
Best regards,
AF


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: AArch64 calling convention in assembly code
  2018-08-01 15:56     ` Alexander Fedotov
@ 2018-08-01 16:19       ` Richard Earnshaw (lists)
  2018-08-01 18:03         ` Jeff Johnston
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Earnshaw (lists) @ 2018-08-01 16:19 UTC (permalink / raw)
  To: Alexander Fedotov; +Cc: newlib, gdb

[-- Attachment #1: Type: text/plain, Size: 2291 bytes --]

On 01/08/18 16:56, Alexander Fedotov wrote:
> Yes, but X29 is not saved in original version. I can understand this
> with 'frame-less functions" approach. So this code has a right for a
> life.
> 
> I suspect that such a problem could happen if user will pass
> "-fomit-frame-pointer" option to GCC as well.
> 
>>> All we really need is a CFI unwind record that GDB can understand.
> For plain assembly code ?
> 

Yep, see attached.  This also simplifies the entry/exit sequences slightly.


	* aarch64/cpu-init/rdimon-aem-el3.S (cpu_init_hook): Simplify
	entry/exit sequences.  Add CFI unwind rules.

R.

> Alex
> 
> On Wed, Aug 1, 2018 at 6:48 PM, Richard Earnshaw (lists)
> <Richard.Earnshaw@arm.com> wrote:
>> On 01/08/18 14:28, Alexander Fedotov wrote:
>>>>> Pushing LR on the stack resolves a problem
>>> FP of course, not LR.
>>> So the correct code must be like this:
>>>
>>> _cpu_init_hook:
>>>     stp        x29, x30, [sp, #-16]!
>>>     mov        x29, sp
>>>     bl        _init_vectors
>>>     bl        _flat_map
>>>     ldp        x29, x30, [sp], #16
>>>     ret
>>>
>>> But still my point is that GDB should catch such an error and do not hang.
>>>
>>> Alex
>>>
>>> On Tue, Jul 31, 2018 at 9:34 PM, Alexander Fedotov <alfedotov@gmail.com> wrote:
>>>> Hello dear AArch64 maintainers
>>>> Please look into code snippet below from newlib/libgloss/aarch64/rdimon-aem-el3.
>>>>
>>>> Seems to me this code violates AArch64 calling convention and actually
>>>> breaks debugging in GDB. GDB tries to unwind call stack and got
>>>> endless reentrancy...
>>>>
>>>> FUNCTION (_cpu_init_hook):
>>>>     sub    sp, sp, #16
>>>>     str    x30, [sp, xzr]
>>>>     bl    _init_vectors
>>>>     bl    _flat_map
>>>>     ldr    x30, [sp, xzr]
>>>>     add    sp, sp, #16
>>>>     ret
>>>>
>>>>
>>>> We have couple of calls there (_init_vectors, _flat_map). If you'll
>>>> try to step into any subroutine you will found that GDB hangs and
>>>> can't step anymore.
>>>>
>>>> Pushing LR on the stack resolves a problem.
>>
>> X30 is LR.
>>
>> All we really need is a CFI unwind record that GDB can understand.
>>
>> R.
>>
>>>>
>>>> So my message is that:
>>>> 1. Current code in _cpu_init_hook is incorrect
>>>> 2. GDB should handle this and do not hang
>>>>
>>>> Alex
>>>
>>>
>>>
>>
> 
> 
> 


[-- Attachment #2: rdimon-cfi.patch --]
[-- Type: text/x-diff, Size: 725 bytes --]

diff --git a/libgloss/aarch64/cpu-init/rdimon-aem-el3.S b/libgloss/aarch64/cpu-init/rdimon-aem-el3.S
index 41db8f9..9edbccd 100644
--- a/libgloss/aarch64/cpu-init/rdimon-aem-el3.S
+++ b/libgloss/aarch64/cpu-init/rdimon-aem-el3.S
@@ -157,12 +157,16 @@ ttb:
 	.align 2
 	.global	FUNCTION (_cpu_init_hook)
 	.type	FUNCTION (_cpu_init_hook), %function
+	.cfi_sections	.debug_frame
 FUNCTION (_cpu_init_hook):
-	sub	sp, sp, #16
-	str	x30, [sp, xzr]
+	.cfi_startproc
+	str	x30, [sp, -16]!
+	.cfi_def_cfa_offset 16
+	.cfi_offset 30, -16
 	bl	_init_vectors
 	bl	_flat_map
-	ldr	x30, [sp, xzr]
-	add	sp, sp, #16
+	ldr	x30, [sp], 16
+	.cfi_restore 30
 	ret
+	.cfi_endproc
 	.size	FUNCTION (_cpu_init_hook), .-FUNCTION (_cpu_init_hook)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: AArch64 calling convention in assembly code
  2018-08-01 16:19       ` Richard Earnshaw (lists)
@ 2018-08-01 18:03         ` Jeff Johnston
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Johnston @ 2018-08-01 18:03 UTC (permalink / raw)
  To: Richard Earnshaw (lists); +Cc: Alexander Fedotov, Newlib, gdb

I have pushed Richard's patch to master.

-- Jeff J.

On Wed, Aug 1, 2018 at 12:19 PM, Richard Earnshaw (lists) <
Richard.Earnshaw@arm.com> wrote:

> On 01/08/18 16:56, Alexander Fedotov wrote:
> > Yes, but X29 is not saved in original version. I can understand this
> > with 'frame-less functions" approach. So this code has a right for a
> > life.
> >
> > I suspect that such a problem could happen if user will pass
> > "-fomit-frame-pointer" option to GCC as well.
> >
> >>> All we really need is a CFI unwind record that GDB can understand.
> > For plain assembly code ?
> >
>
> Yep, see attached.  This also simplifies the entry/exit sequences slightly.
>
>
>         * aarch64/cpu-init/rdimon-aem-el3.S (cpu_init_hook): Simplify
>         entry/exit sequences.  Add CFI unwind rules.
>
> R.
>
> > Alex
> >
> > On Wed, Aug 1, 2018 at 6:48 PM, Richard Earnshaw (lists)
> > <Richard.Earnshaw@arm.com> wrote:
> >> On 01/08/18 14:28, Alexander Fedotov wrote:
> >>>>> Pushing LR on the stack resolves a problem
> >>> FP of course, not LR.
> >>> So the correct code must be like this:
> >>>
> >>> _cpu_init_hook:
> >>>     stp        x29, x30, [sp, #-16]!
> >>>     mov        x29, sp
> >>>     bl        _init_vectors
> >>>     bl        _flat_map
> >>>     ldp        x29, x30, [sp], #16
> >>>     ret
> >>>
> >>> But still my point is that GDB should catch such an error and do not
> hang.
> >>>
> >>> Alex
> >>>
> >>> On Tue, Jul 31, 2018 at 9:34 PM, Alexander Fedotov <
> alfedotov@gmail.com> wrote:
> >>>> Hello dear AArch64 maintainers
> >>>> Please look into code snippet below from newlib/libgloss/aarch64/
> rdimon-aem-el3.
> >>>>
> >>>> Seems to me this code violates AArch64 calling convention and actually
> >>>> breaks debugging in GDB. GDB tries to unwind call stack and got
> >>>> endless reentrancy...
> >>>>
> >>>> FUNCTION (_cpu_init_hook):
> >>>>     sub    sp, sp, #16
> >>>>     str    x30, [sp, xzr]
> >>>>     bl    _init_vectors
> >>>>     bl    _flat_map
> >>>>     ldr    x30, [sp, xzr]
> >>>>     add    sp, sp, #16
> >>>>     ret
> >>>>
> >>>>
> >>>> We have couple of calls there (_init_vectors, _flat_map). If you'll
> >>>> try to step into any subroutine you will found that GDB hangs and
> >>>> can't step anymore.
> >>>>
> >>>> Pushing LR on the stack resolves a problem.
> >>
> >> X30 is LR.
> >>
> >> All we really need is a CFI unwind record that GDB can understand.
> >>
> >> R.
> >>
> >>>>
> >>>> So my message is that:
> >>>> 1. Current code in _cpu_init_hook is incorrect
> >>>> 2. GDB should handle this and do not hang
> >>>>
> >>>> Alex
> >>>
> >>>
> >>>
> >>
> >
> >
> >
>
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-01 18:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAN8C2CqGq4OUNXq5=ur87nqwVjYF-D6aAcVKGGB1pQT1S0b6Jg@mail.gmail.com>
2018-08-01 13:28 ` AArch64 calling convention in assembly code Alexander Fedotov
2018-08-01 15:49   ` Richard Earnshaw (lists)
2018-08-01 15:56     ` Alexander Fedotov
2018-08-01 16:19       ` Richard Earnshaw (lists)
2018-08-01 18:03         ` Jeff Johnston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox