public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: xmeng <xmeng@cs.wisc.edu> To: gcc-bugs@gcc.gnu.org Subject: A strange code snippet: jump to a return instruction Date: Fri, 10 Jan 2014 17:21:00 -0000 [thread overview] Message-ID: <6aae7b70b97410b991c7756cdfda67bc@cs.wisc.edu> (raw) 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? It smells like a code generation bug to me. 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. The gcc.bin is compiled with the following configurations: Reading specs from /afs/cs.wisc.edu/s/gcc-4.7.0/amd64_rhel6/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.0/specs COLLECT_GCC=/s/gcc-4.7.0/amd64_rhel6/bin/gcc.bin COLLECT_LTO_WRAPPER=/afs/cs.wisc.edu/s/gcc-4.7.0/amd64_rhel6/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.7.0/configure --prefix=/s/gcc-4.7.0/amd64_rhel6 --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,fortran --disable-dssi --enable-plugin --with-cpu=generic Thread model: posix gcc version 4.7.0 (GCC) I think you can find such code snippet in your gcc.bin by searching for the function "_ZL28if_exists_else_spec_functioniPPKc" Thanks --Xiaozhu
reply other threads:[~2014-01-10 17:21 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=6aae7b70b97410b991c7756cdfda67bc@cs.wisc.edu \ --to=xmeng@cs.wisc.edu \ --cc=gcc-bugs@gcc.gnu.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: linkBe 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).