Including assembly file as part of .elf build

I am porting my old 0.8.1 Zig PinePhone project to 0.14.0 under Asahi Linux. I especially wanted to simplify the very long build shell script. Also, because of the large number of code changes required, I decided I should start with a single simple Zig program, just to toggle the Phone LEDs.

My program builds, and using addObjCopy I am able to extract the binary from the elf file ready for packaging up for my JumpDrive SDCard. However, I suspect I need to include some arm64 CPU initialisation. Since I am replicating a lot of the articles from porting NuttX with Zig to PinePhone. I can see such an assembly file exists there.

My question: when I add this assembly to my buildfile using addAssemblyFile it skips over #includes and #defines, leading to errors when they are used in the assembly. I started to tweak the assembly to remove them, but it feels wrong. Then I recalled that I changed the file extension for .S to .s and a little research is showing that maybe the assembly file I have needs to be handled in Zig differently, but I dont know how. Is there an option on addAssemblyFile that supports macros/defines/includes etc ?

If an assembly file needs to be preprocessed, its extension should indeed be .S; .s assembly files are assembled as-is without running the preprocessor. This is the case with gcc/clang command line drivers too.

1 Like

Thanks for the confirmation. Is there a way to process the .S file using addAssemblyFile or do I need to drop out to a command line tool for this?

I’m not sure what you mean. If the file name ends in .S (upper case), it will be preprocessed; you don’t need to do anything special.

I think I was building the wrong ‘flavour’ of arm code and my ld file was wonky as probably still is, since the first 8 bytes of assembly look garbage, but it is processing the macros and defines now, thanks. (aarch64,freestanding,none with cpu set as cortex_a53). I can see a asm-nop from Zig appearing which is also reassuring. Are there more options on addObjCopy available, other than the .format=.bin I am using? Maybe the extra 8 bytes are something that needs to be stripped…

My code still doesnt run, but a step closer, thanks!