build.exe options. Name mangling and linking.

Note, I’m new to build.exe so this is quite possibly a simplton question.

I’m trying to call a separate driver directly from my file system driver.
I link my file system driver with the .lib file built from the other
driver. Unfortunalty, the default options in build.exe cause the exported
function in my FS driver to get mangled (see detail below) so I get an
unresolved external symbol error.

Does anyone know the build.exe option to not mangle function names with an
appended “@-index” string? (e.g. in the example below I don’t want the
@12” appended to the function name)

exported function name from other driver in .lib file: __imp__foo
mangled function name in file system driver: __imp__foo@12

Thanks!

The function is not mangled, but using stdcall to pass parameters.
The other driver is probably using fastcall (or maybe this was cdecl).
Anyway, build assumes that drivers use stdcall, thus /Gz is automatically
included when drivers are compiled for cl.exe command line. Any function that
does not explicitly define calling conversion will use that.
The other driver is probably incorrectly built if it does not use stdcall.
You can use __cdecl or __fastcall in the header file where the functions are
defined, to resolve this (note, I mentioned both, because I am not sure which
conversion uses no parameter extra characters)

Regards, Dejan.

xxxxx@charter.net wrote:

Note, I’m new to build.exe so this is quite possibly a simplton question.

I’m trying to call a separate driver directly from my file system driver.
I link my file system driver with the .lib file built from the other
driver. Unfortunalty, the default options in build.exe cause the exported
function in my FS driver to get mangled (see detail below) so I get an
unresolved external symbol error.

Does anyone know the build.exe option to not mangle function names with an
appended “@-index” string? (e.g. in the example below I don’t want the
@12” appended to the function name)

exported function name from other driver in .lib file: __imp__foo
mangled function name in file system driver: __imp__foo@12

Thanks!


You are currently subscribed to ntfsd as: xxxxx@alfasp.com
To unsubscribe send a blank email to %%email.unsub%%


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32 developers.

Thanks! Live and re-learn :slight_smile:

FYI,

__stdcall - An underscore (_) is prefixed to the name. The name is
followed by the at sign (@) followed by the number of bytes (in decimal)
in the argument list. Therefore, the function declared as int func( int a,
double b ) is decorated as follows: _func@12.

__cdecl - Underscore character (_) is prefixed to names.

> Does anyone know the build.exe option to not mangle function names
with an

appended “@-index” string? (e.g. in the example below I don’t want
the
@12” appended to the function name)

Declare the function as __cdecl in the header.

Max

Everything said was true:
__cdecl => underscore prepended
__stdcall => underscore prepended and number of bytes of parameters appended
with @ sign
__fastcall => @ prepended and @ sign and number of bytes parameters appended

For example:
type t.c

void __stdcall Stdcall(void) { }
void __cdecl Cdecl(void) { }
void __fastcall Fastcall(void) { }

cl -nologo -c t.c

dumpbin -symbols t.obj | findstr /i external

006 00000000 SECT2 notype () External | _Stdcall@0
007 00000005 SECT2 notype () External | _Cdecl
008 0000000A SECT2 notype () External | @Fastcall@0

if you want exports do not be “mangled” this way, use a .def file instead of
__declspec(dllexport).

Mangling on other platforms (Mips, Alpha, PowerPC, IA64) I think varies…I
think on all the rest the names are left asis, or maybe _ is prepended.

On other platforms __stdcall/__cdecl/__fastcall may make no difference, for
example on x86 in C++ you can overload on function pointer type like:

typedef void (__stdcall * SPFN)(void);
typedef void (__cdecl * CPFN)(void);
typedef void (__fastcall * FPFN)(void);

void F(SPFN p) { (*p)(); }
void F(CPFN p) { (*p)(); }
void F(FPFN p) { (*p)(); }

but you can’t do that on all.

  • Jay