https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79425
Bug ID: 79425 Summary: Inline assembly getting clobbered in some case Product: gcc Version: 5.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mini at cs dot technion.ac.il Target Milestone: --- I am getting inline assembly code clobbered if I #include<algorithm>, it is the 1st code in the .text segment, AND I use -std=c++11 This is the INCORRECT behavior. As you can see, the label reg_in is gone: $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) $ cat prog.c #include <algorithm> //void foo(){} __asm__ volatile ("reg_in: \n\t" "pushf\n\t" "push %rbp\n\t" "mov %rsp,%rbp\n\t" "push %rdi\n\t" "push %rsi\n\t" "push %rdx\n\t" "push %rcx\n\t" "push %r8 \n\t" "push %r9 \n\t" "push %rax\n\t" ); int main(int argc, char *argv[]) { } $ g++ -std=c++11 prog.c $ objdump -d a.out # I put here only partial output 00000000004004b0 <frame_dummy>: 4004b0: bf 20 0e 60 00 mov $0x600e20,%edi 4004b5: 48 83 3f 00 cmpq $0x0,(%rdi) 4004b9: 75 05 jne 4004c0 <frame_dummy+0x10> 4004bb: eb 93 jmp 400450 <register_tm_clones> 4004bd: 0f 1f 00 nopl (%rax) 4004c0: b8 00 00 00 00 mov $0x0,%eax 4004c5: 48 85 c0 test %rax,%rax 4004c8: 74 f1 je 4004bb <frame_dummy+0xb> 4004ca: 55 push %rbp 4004cb: 48 89 e5 mov %rsp,%rbp 4004ce: ff d0 callq *%rax 4004d0: 5d pop %rbp 4004d1: e9 7a ff ff ff jmpq 400450 <register_tm_clones> 00000000004004d6 <main>: 4004d6: 55 push %rbp 4004d7: 48 89 e5 mov %rsp,%rbp 4004da: 89 7d fc mov %edi,-0x4(%rbp) 4004dd: 48 89 75 f0 mov %rsi,-0x10(%rbp) 4004e1: b8 00 00 00 00 mov $0x0,%eax 4004e6: 5d pop %rbp 4004e7: c3 retq 4004e8: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1) 4004ef: 00 If I do 1 of the following, I get the correct result 1. uncomment void foo(){} 2. remove #include <algorithm> The examples below, are of CORRECT behaviors. Here the label reg_in stays: $ vi prog.c $ g++ -std=c++11 prog.c $ cat prog.c #include <algorithm> void foo(){} __asm__ volatile ("reg_in: \n\t" "pushf\n\t" "push %rbp\n\t" "mov %rsp,%rbp\n\t" "push %rdi\n\t" "push %rsi\n\t" "push %rdx\n\t" "push %rcx\n\t" "push %r8 \n\t" "push %r9 \n\t" "push %rax\n\t" ); int main(int argc, char *argv[]) { } $ objdump -d a.out # I put here only partial output 00000000004004b0 <frame_dummy>: 4004b0: bf 20 0e 60 00 mov $0x600e20,%edi 4004b5: 48 83 3f 00 cmpq $0x0,(%rdi) 4004b9: 75 05 jne 4004c0 <frame_dummy+0x10> 4004bb: eb 93 jmp 400450 <register_tm_clones> 4004bd: 0f 1f 00 nopl (%rax) 4004c0: b8 00 00 00 00 mov $0x0,%eax 4004c5: 48 85 c0 test %rax,%rax 4004c8: 74 f1 je 4004bb <frame_dummy+0xb> 4004ca: 55 push %rbp 4004cb: 48 89 e5 mov %rsp,%rbp 4004ce: ff d0 callq *%rax 4004d0: 5d pop %rbp 4004d1: e9 7a ff ff ff jmpq 400450 <register_tm_clones> 00000000004004d6 <_Z3foov>: 4004d6: 55 push %rbp 4004d7: 48 89 e5 mov %rsp,%rbp 4004da: 90 nop 4004db: 5d pop %rbp 4004dc: c3 retq 00000000004004dd <reg_in>: 4004dd: 9c pushfq 4004de: 55 push %rbp 4004df: 48 89 e5 mov %rsp,%rbp 4004e2: 57 push %rdi 4004e3: 56 push %rsi 4004e4: 52 push %rdx 4004e5: 51 push %rcx 4004e6: 41 50 push %r8 4004e8: 41 51 push %r9 4004ea: 50 push %rax 00000000004004eb <main>: 4004eb: 55 push %rbp 4004ec: 48 89 e5 mov %rsp,%rbp 4004ef: 89 7d fc mov %edi,-0x4(%rbp) 4004f2: 48 89 75 f0 mov %rsi,-0x10(%rbp) 4004f6: b8 00 00 00 00 mov $0x0,%eax 4004fb: 5d pop %rbp 4004fc: c3 retq 4004fd: 0f 1f 00 nopl (%rax) $ vi prog.c $ g++ -std=c++11 prog.c $ cat prog.c //#include <algorithm> //void foo(){} __asm__ volatile ("reg_in: \n\t" "pushf\n\t" "push %rbp\n\t" "mov %rsp,%rbp\n\t" "push %rdi\n\t" "push %rsi\n\t" "push %rdx\n\t" "push %rcx\n\t" "push %r8 \n\t" "push %r9 \n\t" "push %rax\n\t" ); int main(int argc, char *argv[]) { } $ objdump -d a.out # I put here only partial output 00000000004004b0 <frame_dummy>: 4004b0: bf 20 0e 60 00 mov $0x600e20,%edi 4004b5: 48 83 3f 00 cmpq $0x0,(%rdi) 4004b9: 75 05 jne 4004c0 <frame_dummy+0x10> 4004bb: eb 93 jmp 400450 <register_tm_clones> 4004bd: 0f 1f 00 nopl (%rax) 4004c0: b8 00 00 00 00 mov $0x0,%eax 4004c5: 48 85 c0 test %rax,%rax 4004c8: 74 f1 je 4004bb <frame_dummy+0xb> 4004ca: 55 push %rbp 4004cb: 48 89 e5 mov %rsp,%rbp 4004ce: ff d0 callq *%rax 4004d0: 5d pop %rbp 4004d1: e9 7a ff ff ff jmpq 400450 <register_tm_clones> 00000000004004d6 <reg_in>: 4004d6: 9c pushfq 4004d7: 55 push %rbp 4004d8: 48 89 e5 mov %rsp,%rbp 4004db: 57 push %rdi 4004dc: 56 push %rsi 4004dd: 52 push %rdx 4004de: 51 push %rcx 4004df: 41 50 push %r8 4004e1: 41 51 push %r9 4004e3: 50 push %rax 00000000004004e4 <main>: 4004e4: 55 push %rbp 4004e5: 48 89 e5 mov %rsp,%rbp 4004e8: 89 7d fc mov %edi,-0x4(%rbp) 4004eb: 48 89 75 f0 mov %rsi,-0x10(%rbp) 4004ef: b8 00 00 00 00 mov $0x0,%eax 4004f4: 5d pop %rbp 4004f5: c3 retq 4004f6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 4004fd: 00 00 00