News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

EXPORT keyword

Started by asmfan, April 26, 2006, 06:31:56 PM

Previous topic - Next topic

asmfan

I dont understand why EXPORT keyword mangles proc names (with _ and @n) in executables not only in import libraries. when using .DEF files EXPORTS statement it doesnt happen and we have normal exported names in executables. Do you know the answer? And then what for EXPORT if it works so bad?
Thanks:)
Russia is a weird place

PBrennick

asmfan.
I don't think I understand your question.  If it is working in your DEF files, where is it NOT working?

Paul
The GeneSys Project is available from:
The Repository or My crappy website

asmfan

Paul, i meant EXPORT and EXPORTS are different keywords for ml.exe and link respectively. The first one is in ASM files in proc declaration (e.g. SomeProc   PROC  EXPORT   a:DWORD) and the second one is in DEF files. Both have their purpose to make names exported in binaries, but first produces mangled names in binaries and the second pure (unmangled) ones. The question is is EXPORT (in asm files) works incorrectly?
Russia is a weird place

PBrennick

asmfan,
I, for one have never used the assembly declaration EXPORT.  Instead, I have always used PUBLIC and PRIVATE alsong with NEAR and FAR, the last two have not used in years.  I think you should try declaring your PROC as PUBLIC so it can be called externally.  I haven't done that in years, but used to do it all the time when using overlays.  In libraries, this is done by the linker as EXPORTS

Paul
The GeneSys Project is available from:
The Repository or My crappy website

asmfan

The deal is that public, privat, near...etc. flags working with obj files, while export and exports make an export section in executables (exe, dll) to export procs for example totally:) external. All problems in this name mangling in binaries. Why MS's ml.exe supports EXPORT keyword if it works so? Dont know...
Russia is a weird place

PBrennick

I am sorry I can not help you with that, maybe Hutch has a clue.  I am used to name mangling but not quite the way you are describing it.

Try http://en.wikipedia.org/wiki/Name_mangling

Paul
The GeneSys Project is available from:
The Repository or My crappy website

asmfan

Thanks Paul, but it's not quite the same that i would like to hear of. Say in one case we have in exe's exports _SomeProc@4 and in the other case just SomeProc. What definition works more correct in asm or in def file?
Russia is a weird place

PBrennick

You should use the undecorated name in the DEF file and then if the name gets manngled (decorated) it will still be associated with the undecorated name.  Name decoration is an automated thing and not a user thing.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

asmfan

That's it both ways automatically decorate names in export lib files but the first way also decorates them in PE32 EXEs... You write normal names and in exe export table they look mangled!8)
Russia is a weird place

MichaelW

It depends on the langtype attribute in the PROC definition:

(STDCALL specified in language field of MODEL directive)
SomeProc proc EXPORT arg1:DWORD
Exported name = _SomeProc@4

SomeProc proc STDCALL EXPORT arg1:DWORD
Exported name = _SomeProc@4

SomeProc proc SYSCALL EXPORT arg1:DWORD
SomeProc proc C EXPORT arg1:DWORD
Exported name = SomeProc

SomeProc proc BASIC EXPORT arg1:DWORD
SomeProc proc PASCAL EXPORT arg1:DWORD
SomeProc proc FORTRAN EXPORT arg1:DWORD
Exported name = SOMEPROC
eschew obfuscation

asmfan

Ok, another example:
Say we need to access ExitProcess from Kernel32.dll not having lib. Making your dll with def file we building a correct kernel32.lib while using EXPORT definition we cannot build correct lib! Why? Is it works incorrect? Glitch of ml? MS? Is it Purposely?
Russia is a weird place

PBrennick

asmfan,
I am going to sit this one out because not only was I confused before; your last post has me VERY confused!
Paul
The GeneSys Project is available from:
The Repository or My crappy website

asmfan

I just tried to say that name mangling is useful only in import libraries (.lib) not in executables. When we call appropriate function we call it via lib that checks language calling convention demangling names and then it is correct it gives us to use the function with unmangled names. While EXPORT mechanism doesnt do the last point and you call the same mangled name as in lib... Thats all:)
Russia is a weird place

Vortex

asmfan,

If you are interested, you can build import libraries with non-decorated function names.

asmfan

Paul, you should NOT be confused by my posts because they are legal (i think:) i use the same technique that INC2L.exe does. So you shouldn't treat it as some hacking... Also masm32 use such technique to build its import libs..
They were only examples.. The question was different. I tried to compare EXPORT and EXPORTS ways to create exported functions with unmangled names in binaries. I'm not doing something evil or bad. Sorry if i misunderstood.
Russia is a weird place