This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A strange code snippet: jump to a return instruction


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]