最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

assembly - how to create a MASMML64 proc with the same name as a reserved word - Stack Overflow

programmeradmin5浏览0评论

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
  • Have you tried using ALIAS? – Jester Commented Mar 18 at 18:29
  • @Jester - yup I just worked it out – pm100 Commented Mar 18 at 18:41
  • @Jester but see stackoverflow/questions/79518750/… – pm100 Commented Mar 18 at 22:35
Add a comment  | 

2 Answers 2

Reset to default 4

Well 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
发布评论

评论列表(0)

  1. 暂无评论