Other llvm-mc assembler in FreeBSD toolchain

Since llvm/clang is the default compiler on FreeBSD I thought it would be interesting doing some low-level assembly coding using the llvm internal assembler. I've been scouring the web and these forums for prior work on using the LLVM internal assembler using intel syntax on FreeBSD, but I've been running up short. For older 32bit architectures, the Developer's Manual is excellent and there's an excellent repo on github topcat001/assembly with 64bit examples. Both of those use NASM, though.

Is anyone who reads this aware of any projects, examples or documentation on using llvm-mc with intel syntax?

llvm-mc is rather incompatible with NASM syntax. It's also pretty much entirely undocumented and the references I've found are pretty much "don't do this", "read the source" or "try it out". Sure, semi-reverse-engineering LLVM is the last resort, but does anyone have something to share?
 
To answer my own question: "Don't do this" is the correct answer.

While llvm-mc understands intel syntax instructions just fine, you are still stuck with GNU-style declarations for the ELF format. At least with GNU-declarations and AT&T statements it's somewhat visually consistent-- it still makes my eyes hurt, but mixing GNU/Intel makes my eyes bleed instead :eek:

The solution is to roll my own assembler and use llvm-mc as it was intended-- to translate a stream of instructions to machine code. I wrote a small declarative language and handled the ELF format with libelf instead, available in the system libraries (man elf, sections 3, 5). Code goes in the sections so marked, as per the ELF spec. Then just link with 'ld' as usual. Full docs in chapter 6 of the libelf manual: https://master.dl.sourceforge.net/p...elf-by-example/20200330/libelf-by-example.pdf

I've been using FreeBSD since the late 90s, but I'm still all impressed when my OS helps me solve software problems rather than cause them.
 
Back
Top