ARCv2 Backend

I’m trying to build an application for ARC Classic, and I see that arc is in zig triples, but when I try to execute something like zig build-exe src/main.zig -target arc-freestanding -T src/linker.ld I get:

error: cannot emit arc binary with the LLVM backend; only '-femit-asm' is supported

If you look at the support table for the most recent release, you’ll see that code generation only supports assembly output. If you want to turn that into a binary, you’ll need to use an external ARC assembler that will process the Zig code output.

Note that with ARC being a tier 4 target, C/I tests aren’t run against this backend, so things likely may have more issues than simply lacking a machine code generator.

Ah, thank you for the quick response and link. Bummer, but I can just use the ARC FOSS Toolchain to assemble.

For context, Synopsys don’t even recommend using the ARC backend in LLVM; it’s very incomplete and unmaintained. Similar story for the CSKY backend. I’m honestly not sure why the LLVM project hasn’t removed those backends yet.

Good to know. I grabbed their GNU toolchain and can build C programs just fine - but unfortunately, I can’t figure out how to properly emit the ASM.

Executing zig build-lib -fno-emit-bin -target arc-freestanding -O ReleaseSmall -femit-asm=main.asm src/main.zig results in error: LLVM failed to parse 'arc-unknown-unknown-unknown': Unable to find target for this triple (no targets are registered).

Should I just not even use Zig at all and stick to their official toolchain? I’m just planning on writing some code for a dumb project on the EM9304, so it doesn’t have to be “rigorously” correct

The ARC backend is marked as experimental in LLVM. This means that regular LLVM builds - and by extension Zig releases - don’t include it.

To use it, you’ll have to build LLVM and Zig from source, and make sure to enable the experimental ARC backend when building LLVM.

There is also the alternative path of using Zig’s C backend with -ofmt=c and then passing that to arc-linux-gnu-gcc.

I can’t vouch for how well either approach will work though.

I’ll look into the -ofmt=c route - which will hopefully be a bit quicker to iterate. Thank you so much!