Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assembly files ignored #19852

Closed
ElectricalNEO opened this issue May 3, 2024 · 4 comments
Closed

Assembly files ignored #19852

ElectricalNEO opened this issue May 3, 2024 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@ElectricalNEO
Copy link

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
@ElectricalNEO ElectricalNEO added the bug Observed behavior contradicts documented or intended behavior label May 3, 2024
@ianprime0509
Copy link
Contributor

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)

@kubkon
Copy link
Member

kubkon commented May 22, 2024

Potentially related #20031

@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label May 22, 2024
@Vexu Vexu added this to the 0.13.0 milestone May 22, 2024
@Khitiara
Copy link

Khitiara commented Jun 7, 2024

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

@Vexu
Copy link
Member

Vexu commented Jul 15, 2024

Fixed by #20068

@Vexu Vexu closed this as completed Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

5 participants