public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org>,
	gdb-patches@sourceware.org
Cc: Bruno Larsen <blarsen@redhat.com>
Subject: Re: [PATCH] gdb/testsuite: change hardcoded assembly in gdb.arch/disp-step-insn-reloc.exp
Date: Sat, 20 May 2023 07:31:45 +0100	[thread overview]
Message-ID: <87o7mf8qem.fsf@redhat.com> (raw)
In-Reply-To: <87r0rc7zvm.fsf@redhat.com>

Andrew Burgess <aburgess@redhat.com> writes:

> Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org> writes:
>
>> When testing gdb.arch.disp-step-insn-reloc.exp with clang in an x86_64
>> machine, the compiled test case would segfault when returning from
>> the function can_relocate_call, with a suggestion of a broken stack.
>> The example assembly in the commment was the following:
>>
>>    f:
>>      MOV $1, %[ok]
>>      JMP end
>>    set_point0:
>>      CALL f ; tracepoint here.
>>    end:
>
> Honestly, I found the following paragraph really hard to grok.  I had to
> go look at the failure myself to see what was going on.  Don't spend too
> long on it, but it might be possible to make it a little clearer...
>
>>
>> And the segmentation fault happening at the final "ret" instruction of
>> the original function.
>
> s/the original function/the function cal_relocate_call/.
>
>>                         This suggests that gcc's compilation process would
>> realize that no ret instruction ever happened after that call and doesn't
>
> s/after that call and/after the inner call and so/
>
>> save the return address, while clang's process wouldn't.  Looking at the
>
> Maybe:
>
> save the return address, while clang doesn't spot the missing 'ret' and
> so does push the return address onto the stack.  Looking at the
>
>> generated instructions, we can indeed see a difference:
>
>>
>> clang's version: e8 f1 ff ff ff          call   11a4 <can_relocate_call+0x14>
>> gcc's version:   e8 f4 ff ff ff          call   401125 <can_relocate_call+0x11>
>>
>> Notice the difference on the second byte.
>
> Yes, but please, don't expect me to go read the x86-64 ISA manual --
> what does this difference mean?
>
>>
>> Changing the assembly to use "ret" instead of "JMP end" does not change
>> the behavior of the program and guarantees a compiler independent
>> behavior.  This commit does just that.
>
> The change itself is great, and I agree that this shouldn't change the
> test.
>
> Feel free to tweak the commit message and push this.

Actually, I retract this.  Having thought about this a bit more I now
worry that the explanation doesn't really explain what's going on.  Is
there really a call variant that doesn't push the return address?

Even if that was the case, it is gas, not gcc that decides the encoding
of the instruction, and gas isn't analysing the destination to decide if
there's a ret or not.

I suspect you fix is actually the right one, but I think this
explanation is going in the wrong direction.  Maybe if you reword things
it might be clearer what's going on.

Thanks,
Andrew


>
> Approved-By: Andrew Burgess <aburgess@redhat.com>
>
> Thanks,
> Andrew
>
>> ---
>>  gdb/testsuite/gdb.arch/insn-reloc.c | 6 ++----
>>  1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/gdb/testsuite/gdb.arch/insn-reloc.c b/gdb/testsuite/gdb.arch/insn-reloc.c
>> index f687c2c5631..365e6180057 100644
>> --- a/gdb/testsuite/gdb.arch/insn-reloc.c
>> +++ b/gdb/testsuite/gdb.arch/insn-reloc.c
>> @@ -49,10 +49,9 @@ fail (void)
>>       JMP set_point0
>>     f:
>>       MOV $1, %[ok]
>> -     JMP end
>> +     RET
>>     set_point0:
>>       CALL f ; tracepoint here.
>> -   end:
>>  
>>     */
>>  
>> @@ -65,10 +64,9 @@ can_relocate_call (void)
>>         "  jmp " SYMBOL (set_point0) "\n"
>>         "0:\n"
>>         "  mov $1, %[ok]\n"
>> -       "  jmp 1f\n"
>> +       "  ret\n"
>>         SYMBOL (set_point0) ":\n"
>>         "  call 0b\n"
>> -       "1:\n"
>>         : [ok] "=r" (ok));
>>  
>>    if (ok == 1)
>> -- 
>> 2.39.2


  reply	other threads:[~2023-05-20  6:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26 13:29 Bruno Larsen
2023-05-11  9:04 ` [PING][PATCH] " Bruno Larsen
2023-05-18  9:01 ` [PINGv2][PATCH] " Bruno Larsen
2023-05-20  9:19   ` Andrew Burgess
2023-05-19 21:52 ` [PATCH] " Andrew Burgess
2023-05-20  6:31   ` Andrew Burgess [this message]
2023-05-22 10:46 ` [PATCH v2] " Bruno Larsen
2023-05-23  8:36   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o7mf8qem.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).