Say I need a proc called 'sub'
(why - because I am writing a compiler that generates MASM source. The programmer can call a function whatever they like, and because it might be part of a library called from another program written in another language I cant mangle the name)
I have worked out I need this
option nokeyword:<sub>
but now I cannot use the sub
instruction. I guessed that maybe I could turn it back on by doing
option nokeyword:<>
ie , clear the list of un-reserved words. But that doesnt work
I looked at the output of msvc with /FA to see what it does, but the code it generates gets rejected by ml64. I cant find another compiler that generates MASM as an intermediate
Say I need a proc called 'sub'
(why - because I am writing a compiler that generates MASM source. The programmer can call a function whatever they like, and because it might be part of a library called from another program written in another language I cant mangle the name)
I have worked out I need this
option nokeyword:<sub>
but now I cannot use the sub
instruction. I guessed that maybe I could turn it back on by doing
option nokeyword:<>
ie , clear the list of un-reserved words. But that doesnt work
I looked at the output of msvc with /FA to see what it does, but the code it generates gets rejected by ml64. I cant find another compiler that generates MASM as an intermediate
Share Improve this question asked Mar 18 at 17:44 pm100pm100 50.4k24 gold badges92 silver badges154 bronze badges 3 |2 Answers
Reset to default 4Well here's the answer - hinted at by @jester
mangle the name, say sub -> __sub
then add alias <sub> = <__sub>
An alias can be a reserved word.
Using ALIAS
didn't work well for me when trying to create static libraries. I'd end up with the mangled name in the symbol table as External and the real name (created by ALIAS
) as WeakExternal. Then, when linking against it, it would generally call the WeakExternal one, which for some reason pointed to an empty region of memory. If someone knows how to fix that, I'd like to hear.
Anyway, the method I found was to simply use =
to declare a new name for the mangled proc name.
First I would declare all my mangled procs as private: @@@sub PROC PRIVATE
. This is the equivalent of marking it static
in C and prevents anything from linking against it.
If I'm calling it within this ASM file I simply use the mangled name: call @@@sub
.
To make it available to other compilation units, I put the following at the bottom of the ASM file, because OPTION NOKEYWORD
will of course render "sub" unusable after this.
OPTION NOKEYWORD: <sub>
sub = @@@sub
PUBLIC sub
ALIAS
? – Jester Commented Mar 18 at 18:29