* A strange code snippet: jump to a return instruction
@ 2014-01-09 23:46 xmeng
2014-01-10 8:49 ` Ian Lance Taylor
0 siblings, 1 reply; 2+ messages in thread
From: xmeng @ 2014-01-09 23:46 UTC (permalink / raw)
To: gcc
Hi,
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?
Thanks
--Xiaozhu
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: A strange code snippet: jump to a return instruction
2014-01-09 23:46 A strange code snippet: jump to a return instruction xmeng
@ 2014-01-10 8:49 ` Ian Lance Taylor
0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2014-01-10 8:49 UTC (permalink / raw)
To: xmeng; +Cc: GCC Development
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-01-09 23:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-09 23:46 A strange code snippet: jump to a return instruction xmeng
2014-01-10 8:49 ` Ian Lance Taylor
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).