assembly - GCC incorrectly inlining function with asm block -


in process of porting code watcom gcc noticed incorrectly generated function, , couldn't figure out why happens. here minimal example:

#include <stdio.h>  bool installexceptionhandler(int exceptionno, void (*handler)()) {     bool result;     asm volatile (         "mov  ax, 0x203     \n"         "mov  cx, cs        \n"         "int  0x31          \n"         "sbb  eax, eax      \n"         "not  eax           \n"         : "=eax" (result)         : "ebx" (exceptionno), "edx" (handler)         : "cc", "cx"     );     return result; }  void exception13handler(){}  main() {     if (!installexceptionhandler(13, exception13handler)) {         printf("success!");         return 0;     } else {         printf("failure.");         return 1;     } } 

at line 63 function installexceptionhandler() inlined, remains of asm block. code set input registers edx , ebx missing. if function given __attribute__((noinline)) , actual call emitted, correct code generated. bug in compiler or code not valid?

48                      .globl  _main 50                  _main: 51                  lfb15: 52                      .cfi_startproc 53 0000 55              push    ebp 54                      .cfi_def_cfa_offset 8 55                      .cfi_offset 5, -8 56 0001 89e5            mov ebp, esp 57                      .cfi_def_cfa_register 5 58 0003 83e4f0          , esp, -16 59 0006 83ec10          sub esp, 16 60 0009 e8000000        call    ___main 60      00 61                  /app 62                   # 15 "b.cpp" 1 63 000e 66b80302        mov  ax, 0x203      64 0012 668cc9      mov  cx, cs         65 0015 cd31        int  0x31           66 0017 19c0        sbb  eax, eax       67 0019 f7d0        not  eax       

command line: gcc -o3 -m32 -masm=intel -wa,-adhlns=b.lst b.cpp, gcc -v output: using built-in specs. collect_gcc=g++ collect_lto_wrapper=f:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe target: mingw32 configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --ena ble-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32 -registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-sy stem-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv -prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap ldflags=-s cflags=-d_use_32bit_tim e_t thread model: win32 gcc version 4.8.1 (gcc)

constraints are not register names, specifying constraint "ebx" permitting compiler use signed 32-bit constant , rbx/ebx/bx/bl register or sse register. gcc has chosen use constant , replace occurrence of %1 constant.

to use registers wish require constraints a, b , d.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -