Global Assembly - linux-gnu vs windows-gnu - error

Hello! The global assembly example in the Zig documentation in section 35.4 compiles for the linux-gnu target but not for the windows-gnu target.

const std = @import("std");
const expect = std.testing.expect;

comptime {
    asm (
        \\.global my_func;
        \\.type my_func, @function;
        \\  lea (%rdi,%rsi,1),%eax
        \\  retq

extern fn my_func(a: i32, b: i32) i32;

pub fn main() !void {
    try expect(my_func(12, 34) == 46);

$ zig build-exe main.zig -target x86_64-linux-gnu

$ zig build-exe main.zig -target x86_64-windows-gnu

The build for the windows target produces the following error message:

`LLVM Emit Object... error: <inline asm>:2:7: expected absolute expression
.type my_func, @function;

How can this issue be resolved? Thanks.

Hey @wfouche, welcome to the forum!

I edited your post to format the code blocks correctly. For code blocks, you need three backticks above and below the block.

1 Like

.type is target/file output type dependent directive

Using as - Assembler Directives ← Ctrl F .def. and/or COFF
example in the answer c - GCC's assembly output of an empty program on x86, win32 - Stack Overflow

1 Like