public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: xmeng <xmeng@cs.wisc.edu>
Cc: GCC Development <gcc@gcc.gnu.org>
Subject: Re: A strange code snippet: jump to a return instruction
Date: Fri, 10 Jan 2014 08:49:00 -0000	[thread overview]
Message-ID: <CAKOQZ8wgv5DAnnGWJ=RY1z6QskJKiEwueW7A9bbA_SCMUd5fyA@mail.gmail.com> (raw)
In-Reply-To: <323a99768b082a2654c32eb487867d51@cs.wisc.edu>

On Thu, Jan 9, 2014 at 3:00 PM, xmeng <xmeng@cs.wisc.edu> wrote:
>
> Here is a strange code snippet in gcc.bin in version 4.7.0:
>
> 0000000000402e20 <_ZL28if_exists_else_spec_functioniPPKc>:
>   402e20:       31 c0                   xor    %eax,%eax
>   402e22:       83 ff 02                cmp    $0x2,%edi
>   402e25:       75 11                   jne    402e38
>   402e27:       53                      push   %rbx
>   402e28:       48 8b 3e                mov    (%rsi),%rdi
>   402e2b:       48 89 f3                mov    %rsi,%rbx
>   402e2e:       80 3f 2f                cmpb   $0x2f,(%rdi)
>   402e31:       74 0d                   je     402e40
>   402e33:       48 8b 43 08             mov    0x8(%rbx),%rax
>   402e37:       5b                      pop    %rbx
>   402e38:       f3 c3                   repz retq
>   402e3a:       66 0f 1f 44 00 00       nopw   0x0(%rax,%rax,1)
>   402e40:       be 04 00 00 00          mov    $0x4,%esi
>   402e45:       e8 3e fa ff ff          callq  402888 <access@plt>
>   402e4a:       85 c0                   test   %eax,%eax
>   402e4c:       75 e5                   jne    402e33
>   402e4e:       48 8b 03                mov    (%rbx),%rax
>   402e51:       5b                      pop    %rbx
>   402e52:       eb e4                   jmp    402e38
>   402e54:       66 66 66 2e 0f 1f 84    data32 data32 nopw
> %cs:0x0(%rax,%rax,1)
>   402e5b:       00 00 00 00 00
>
> The last instruction of this function is a two bytes jump "jmp 402e38". It
> jumps to a two bytes return "repz retq". Why not just emit a two bytes
> return at the end of the function, instead we jump to the return?
>
> I actually find similar "jump to a return" snippets in every version from
> 4.7.0 to 4.8.2, but I don't find any such case for 4.6 or prior.
>
> Is there any reason for emitting such code snippets?

I doubt it.  Please file a bug report with a test case as described at
http://gcc.gnu.org/bugs/ .  Thanks.

Ian

      reply	other threads:[~2014-01-09 23:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-09 23:46 xmeng
2014-01-10  8:49 ` Ian Lance Taylor [this message]

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='CAKOQZ8wgv5DAnnGWJ=RY1z6QskJKiEwueW7A9bbA_SCMUd5fyA@mail.gmail.com' \
    --to=iant@google.com \
    --cc=gcc@gcc.gnu.org \
    --cc=xmeng@cs.wisc.edu \
    /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).