How to build (or port?) MASM ASM files with llvm/clang?

Viewed 654

I'm working on a project that uses the Microsoft tool chain (cl.exe, ml.exe, link.exe) which I'm attempting to port to LLVM/clang as part of an open source effort. Porting the compilation of C files is straight forward enough, but figuring out how to build our many *.asm files (written in MASM syntax) has me stymied.

I'm not able to find a way for the llvm tools (or nasm for that matter) to generate object files from MASM sources. Porting the files themselves would be a lot of unplanned work that I need to avoid if at all possible, especially since many of them don't belong to us.

Any recommendations? Any obscure command line switch out there that might do the trick? I've heard about JWasm, but I haven't investigated it yet. If porting from masm to nasm is the only option, are there any guidelines that would ease the conversion?

1 Answers

There are no command-line options that make NASM, GAS, or LLVM understand MASM syntax and directives.

GAS .intel_syntax noprefix is MASM-like so you'd only have to port the directives (Like proc foo / end foo instead of foo:. And .long 1234 instead of dd 1234) and macros. I'd at least diff the machine code vs. an object file built by MASM to see if it assembles the same way. (modulo absolute addresses maybe). Or at least diff disassembly to see if both versions disassemble back into the same instructions.

I haven't tried JWasm but that's probably your best bet. I think it's supposed to really assemble MASM syntax. In the long run you might want to reduce build deps by porting to GAS .intel_syntax, otherwise just keep using JWasm unless it turns out to have downsides for portability or something.

There's more to assembly language than just the lines with instructions on them. Alignment and layout of data can matter, and any trickery with sections / segments and making them executable vs. not can matter.

Related