Difference between revisions of "Duby/Capstone"

From havefunsoft wiki
Jump to: navigation, search
m (See Also)
m (Static Linking)
Line 18: Line 18:
 
However, there are certain dependencies that must be resolved first.  
 
However, there are certain dependencies that must be resolved first.  
 
   {$linklib libcapstone} // library itself
 
   {$linklib libcapstone} // library itself
   {$linklib libmsvcrt} // following symbols are used:
+
   {$linklib libmsvcrt}   // MS Visual C runtime (mingw bindings)
                      // _malloc _calloc _realloc _free _vsnprintf
+
  {$linklib libgcc}      // C++ library
                      // _memset _memcpy _strncpy _sprintf _strlen
+
* '''libmsvcrt''' for  _malloc _calloc _realloc _free _vsnprintf _memset _memcpy _strncpy _sprintf _strlen _strrchr _strncmp _strstr _strcmp _strchr _memmove _strcpy _atoi _tolower
                      // _strrchr _strncmp _strstr _strcmp _strchr
+
* '''libgcc''' for ___ctzdi2  ___popcountsi2 ___popcountdi2 ___umoddi3 ___udivdi3
                      // _memmove _strcpy _atoi _tolower
+
Such dependencies are pretty typical for mingw compilation.
  {$linklib libgcc}    // following symbols are used:
 
                      // ___ctzdi2  ___popcountsi2 ___popcountdi2
 
                      // ___umoddi3 ___udivdi3
 
 
 
 
 
The dependencies are pretty typical for mingw compilation.
 
  
 
==See Also==
 
==See Also==

Revision as of 09:48, 31 October 2017

Capstone Engine is an open source library for disassembly.


Compiling with Mingw

The default compilation doesn't work and fails with a linking error:

./arch/Sparc/SparcInstPrinter.o:SparcInstPrinter.c:(.text+0x4e0): multiple definition of `imaxabs'
./arch/PowerPC/PPCInstPrinter.o:PPCInstPrinter.c:(.text+0x16030): first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [libcapstone.so] Error 1

(for whatever reason "imaxabs" is included in resulting files as a stand-alone function, rather than inline function)

The following command line should be used to compile the library on MinGW (with gcc installed)

CFLAGS="-llibmingwex" ./make.sh gcc

Adding libmingwex library for compilation prevents imaxabs to be inserted into .o file (because the function is implemented in mingwex)

Static Linking

Once the static library is built, it's possible to link it statically to the executable. However, there are certain dependencies that must be resolved first.

 {$linklib libcapstone} // library itself
 {$linklib libmsvcrt}   // MS Visual C runtime (mingw bindings)
 {$linklib libgcc}      // C++ library
  • libmsvcrt for _malloc _calloc _realloc _free _vsnprintf _memset _memcpy _strncpy _sprintf _strlen _strrchr _strncmp _strstr _strcmp _strchr _memmove _strcpy _atoi _tolower
  • libgcc for ___ctzdi2 ___popcountsi2 ___popcountdi2 ___umoddi3 ___udivdi3

Such dependencies are pretty typical for mingw compilation.

See Also