Hello
I am developing a C++ library that requires some external assembly functions to be included.
Currently, the C/C++ functions are being declared this way (generic format, not the exact code):
-------------------------------------------------------------------
#if defined _WIN32
#define DLL_ENTITY __declspec(dllexport)
#endif
#if defined _WIN32
DLL_ENTITY
#endif
int Function (int argument);
-------------------------------------------------------------------
and compile it (using a Makefile) with GCC using the -fPIC flag to create relocatable code that can be used from the programs linked to my library. For example (one command output of my Makefile):
g++ -I`pwd`/.. -Wall -fPIC -march=x86-64 -mtune=generic -g -c sort.cpp
and in Windows I create and configure a project with executable format DLL option in Visual Studio, then it does all the job.
Okay, my assembly functions look like this:
-------------------------------------------------------------------
global function
global _function
function:
_function:
ENTER reserved_bytes,nest_level
; ...get possible parameters...
; ...do something...
LEAVE
ret
-------------------------------------------------------------------
Well, according to the NASM manual, for the Windows DLL libraries I must add something like:
export function
My doubts are these:
1) For Linux it does not mention nothing about 'export', I guess it is the same way as the C/C++ function/class prototypes that do not require any special treatment, they are declared in the same way as in standalone programs. Is it right? Just use 'export' for Windows and nothing for Linux?
2) What about the relocatable code generation? For Windows, the 'export' keyword makes it relocatable or JUST EXPORTABLE? And for Linux, do I need to use some flag equivalent to -fPIC or I must create the relocatable code by using BASED addressing? For example:
add WORD[BP+myNumber],10h
instead of
add WORD[myNumber],10h
but in this case, how can I find the base address of the function to set BP (EBP/RBP) to it?