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

incorrect data layout string generated on some targets with the new llvm logic #16482

Closed
ghost opened this issue Jul 21, 2023 · 4 comments · Fixed by #16487
Closed

incorrect data layout string generated on some targets with the new llvm logic #16482

ghost opened this issue Jul 21, 2023 · 4 comments · Fixed by #16487
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@ghost
Copy link

ghost commented Jul 21, 2023

Zig Version

0.11.0-dev.4088+c43ee5bb2

Steps to Reproduce and Observed Behavior

Try to compile literally anything (even an empty file reproduces the error) with zig build-exe blah.zig -target wasm32-emscripten

Error:


====== expected this output: =========
e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20␃

======== instead found this: =========
e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20␃

======================================
First difference occurs on line 1:
expected:
e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20
                                     ^ ('\x66')
found:
e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20
                                     ^ ('\x6e')
thread 7254 panic: attempt to unwrap error: TestExpectedEqual
/home/yujiri/code/zig/lib/std/testing.zig:635:9: 0x40c1492 in expectEqualStrings (zig)
        return error.TestExpectedEqual;
        ^
/home/yujiri/code/zig/src/codegen/llvm.zig:865:25: 0x40c3495 in init (zig)
                ) catch unreachable;
                        ^
/home/yujiri/code/zig/src/codegen/llvm.zig:741:32: 0x40c6625 in create (zig)
        obj.* = try Object.init(gpa, options);
                               ^
/home/yujiri/code/zig/src/link/Wasm.zig:527:49: 0x40cff0c in createEmpty (zig)
        wasm.llvm_object = try LlvmObject.create(gpa, options);
                                                ^
/home/yujiri/code/zig/src/link/Wasm.zig:364:27: 0x40e3813 in openPath (zig)
        return createEmpty(allocator, options);
                          ^
/home/yujiri/code/zig/src/link.zig:351:49: 0x40e7580 in openPath (zig)
                    break :f &(try Wasm.openPath(allocator, sub_path, options)).base;
                                                ^
/home/yujiri/code/zig/src/Compilation.zig:1428:48: 0x40f295a in create (zig)
        const bin_file = try link.File.openPath(gpa, .{
                                               ^
/home/yujiri/code/zig/src/main.zig:3078:36: 0x41e642c in buildOutputType (zig)
    const comp = Compilation.create(gpa, .{
                                   ^
/home/yujiri/code/zig/src/main.zig:269:31: 0x405eb31 in mainArgs (zig)
        return buildOutputType(gpa, arena, args, .{ .build = .Exe });
                              ^
/home/yujiri/code/zig/src/main.zig:213:20: 0x405bf85 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/yujiri/code/zig/lib/std/start.zig:608:37: 0x405b9de in main (zig)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7f3bd1f3287f in ??? (???)
???:?:?: 0x7ffdfa0eaaa6 in ??? (???)
fish: Job 1, 'zig build-exe client/main_web.z…' terminated by signal SIGABRT (Abort)

Okay, what the heck even is this? How am I getting a test failure when I'm not running a test?

Expected Behavior

Normal attempt to compile the file...

I have a project that was building successfully for this target in the last few weeks. I think this must be recent.

@ghost ghost added the bug Observed behavior contradicts documented or intended behavior label Jul 21, 2023
@rohlem
Copy link
Contributor

rohlem commented Jul 21, 2023

Okay, what the heck even is this?

I don't think it's a crazy miscompilation / screw-up, just a part of the compiler using std.testing.expectEqualSlices for equivalence testing. Mentioned lines support this:

zig/src/codegen/llvm.zig

Lines 862 to 865 in 426e737

std.testing.expectEqualStrings(
std.mem.span(rep),
builder.data_layout.toSlice(&builder).?,
) catch unreachable;

IMO kind of smart and not the worst idea for pointing out the actual issue (to whoever understands what's happening in that part of the code).

@ghost
Copy link
Author

ghost commented Jul 21, 2023

New information: it also happens for me with windows instead of emscripten, and on wasm64 instead of wasm32, but does not happen on freestanding.

@andrewrk andrewrk added the arch-wasm 32-bit and 64-bit WebAssembly label Jul 22, 2023
@andrewrk andrewrk added this to the 0.12.0 milestone Jul 22, 2023
@andrewrk
Copy link
Member

That's an assertion that the LLVM backend generated the data layout string correctly. Good thing it was added because it caught an issue for you that would have been very difficult to track down otherwise. cc @jacobly0

@andrewrk andrewrk added backend-llvm The LLVM backend outputs an LLVM IR Module. regression It worked in a previous version of Zig, but stopped working. and removed arch-wasm 32-bit and 64-bit WebAssembly labels Jul 22, 2023
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jul 22, 2023
@andrewrk andrewrk changed the title bizarre error when building anything for wasm32-emscripten incorrect data layout string generated on some targets with the new llvm logic Jul 22, 2023
jacobly0 added a commit to jacobly0/zig that referenced this issue Jul 23, 2023
jacobly0 added a commit to jacobly0/zig that referenced this issue Jul 23, 2023
jacobly0 added a commit to jacobly0/zig that referenced this issue Jul 24, 2023
@xdBronch
Copy link
Contributor

i know the support is (extremely) experimental for now but im getting the same type of error with xtensa

====== expected this output: =========
e-m:e-p:32:32-i64:64-i128:128-n32␃

======== instead found this: =========
e-m:e-p:32:32-i64:32-f64:32␃

======================================
First difference occurs on line 1:
expected:
e-m:e-p:32:32-i64:64-i128:128-n32
                  ^ ('\x36')
found:
e-m:e-p:32:32-i64:32-f64:32

should this (or a separate issue) be reopened? should it just be left until xtensa is more supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants