zig
zig copied to clipboard
Assembly files ignored
Zig Version
0.12.0
Steps to Reproduce and Observed Behavior
Compile a program with an assembly source file. The assembly file is ignored. The easiest way to see this is:
// test.S
.error This should throw an error
// main.zig
// This is only needed so that the linker doesn't complain about the entry point
fn main() void {}
$ zig build-exe test.S main.zig
No matter what the assembly file contains, it is ignored
Expected Behavior
The assembly file should be compiled (or, in the above example, an error should be thrown). Here is what version 0.11.0 did:
error(compilation): clang failed with stderr: test.S:1:1: error: .err encountered
.err This should throw an error
This seems like an issue with error reporting, not so much that the assembly file is being completely ignored. For example, the following executable works fine with Zig 0.13.0-dev.69+a96b78c17, printing 4 as expected:
test.S
:
.global get_number
get_number:
movl $4, %eax
ret
main.zig
:
const std = @import("std");
extern fn get_number() u32;
pub fn main() void {
std.debug.print("{}\n", .{get_number()});
}
(compiled using zig build-exe test.S main.zig
as in the original example)
But if I introduce an error into test.S
, then the compilation fails with a linker error without reporting anything about the error in test.S
:
error: ld.lld: undefined symbol: get_number
note: referenced by main.zig:6
note: main.o:(main.main)
Potentially related https://github.com/ziglang/zig/pull/20031
can confirm this is more about error reporting and propogation - errors in included assembly files are not reported and if the assembly could not be compiled then linking still proceeds as normal despite the failed compilation unit. a workaround is to @embedFile
the asm into a global asm block, though that can cause issues when the included asm has .org
or .section
directives so its more useful to check for asm errors than anything
Fixed by #20068