Code fix for x86-64 support of inline assembler in dynlib

272 views
Skip to first unread message

B. Gian James

unread,
Jan 21, 2012, 10:30:08 AM1/21/12
to falc...@googlegroups.com
Hello dev team,
I'm on Linux x86-64 system and when compiling the latest git pull I ran into the following compile errors:

[ 47%] Building CXX object modules/native/dynlib/src/CMakeFiles/dynlib_fm.dir/dynlib_sys_gcc.cpp.o

/home/jamesbl/prog/c++/falcon-master/modules/native/dynlib/src/dynlib_sys_gcc.cpp: Assembler messages:
/home/jamesbl/prog/c++/falcon-master/modules/native/dynlib/src/dynlib_sys_gcc.cpp:95: Error: invalid instruction suffix for `push'
/home/jamesbl/prog/c++/falcon-master/modules/native/dynlib/src/dynlib_sys_gcc.cpp:96: Error: invalid instruction suffix for `push'
/home/jamesbl/prog/c++/falcon-master/modules/native/dynlib/src/dynlib_sys_gcc.cpp:97: Error: invalid instruction suffix for `push'
/home/jamesbl/prog/c++/falcon-master/modules/native/dynlib/src/dynlib_sys_gcc.cpp:111: Error: invalid instruction suffix for `push'
/home/jamesbl/prog/c++/falcon-master/modules/native/dynlib/src/dynlib_sys_gcc.cpp:146: Error: invalid instruction suffix for `pop'
/home/jamesbl/prog/c++/falcon-master/modules/native/dynlib/src/dynlib_sys_gcc.cpp:147: Error: invalid instruction suffix for `pop'
/home/jamesbl/prog/c++/falcon-master/modules/native/dynlib/src/dynlib_sys_gcc.cpp:148: Error: invalid instruction suffix for `pop'
make[2]: *** [modules/native/dynlib/src/CMakeFiles/dynlib_fm.dir/dynlib_sys_gcc.cpp.o] Error 1
make[1]: *** [modules/native/dynlib/src/CMakeFiles/dynlib_fm.dir/all] Error 2
make: *** [all] Error 2

jamesbl@tethys:~/prog/c++/falcon-master$ cat modules/native/dynlib/src/dynlib_sys_gcc.cpp | sed '95,110!d'
   __asm__ __volatile__(
      "pushl   %%ebx \n"            /* Save used registers */
      "pushl   %%esi \n"
      "pushl   %%edi \n"
      "movl    %%esp, %%edi\n"      /* Create a fake frame */

      "1: movl %3, %%esi \n" /* Get next parameter's size */
      "addl    %4, %%esi \n" /* Move count ptrs forward */
      "movl    (%%esi), %%ebx \n"
      "andl    $0x7f, %%ebx \n"   /* We're not interested in knowing the value is float */

x86-64 64-bit instructions are often accomplished by their 32-bit counterparts with needed conversion with the REX prefix. However, the 64-bit versions use an extended register with a different nomenclature. Hence,

pushl %%ebx  ; 32-bit
pushq %%rbx  ; 64-bit

movl %%esp, %%edi   ; 32-bit
movq %%rsp, %%rdi   ; 64-bit

I have added in a preprocessor conditional check for x86-64 architecture as a guard around the 32-bit specific inline assembler from the trunk using what all modern GCC compilers define on 64-bit systems, as:

#ifdef __LP64__
// my 64-bit inline asm conversion
#else
// original 32-bit inline asm
#endif

It compiles to completion now on Linux x86-64 64-bit now. I have attached the diff patch to this post. I hope you can use it.

Regards,
-gian

---
B. Gian James <jamesbl at research.cs.colorado.edu>
Microbial Biochemist / UNIX Alchemist
University of Colorado, Boulder
nevdull @ #falcon
dynlib_sys_gcc_64b.diff

Giancarlo Niccolai

unread,
Jan 22, 2012, 8:21:41 AM1/22/12
to falc...@googlegroups.com
Thank you; We've been waiting for someone helping out with this few ASM lines for a couple of years now! --

We'll apply this changes in the repo asap (I think today).

Bests,
Gian.


Reply all
Reply to author
Forward
0 new messages