Skip to content

Zig 0.9.1 update#29

Closed
hazeycode wants to merge 12 commits into
alexnask:masterfrom
hazeycode:master
Closed

Zig 0.9.1 update#29
hazeycode wants to merge 12 commits into
alexnask:masterfrom
hazeycode:master

Conversation

@hazeycode

@hazeycode hazeycode commented Dec 30, 2021

Copy link
Copy Markdown

Some more fixups for Zig 0.9.1 on top of some of @nektro's changes from #27

Most of these additional changes relate to building tests. However, when attempting to build tests with Zig 0.9.0, the compiler crashes during codegen

❯ zig build test
Code Generation [1798/2200] crypto.ecc.muladd_small... broken LLVM module found: Call parameter type does not match function signature!
  %229 = getelementptr inbounds { %"?[]const u8", i16 }, { %"?[]const u8", i16 }* %0, i32 0, i32 0, !dbg !38311
 %"?[]align(8) u8"*  call fastcc void @std.mem.Allocator.resize.431(%"?[]const u8"* sret(%"?[]align(8) u8") %229, %std.mem.Allocator* %2, %"[]u8"* %23, i64 %227), !dbg !38311

This is a bug in the Zig compiler.thread 116721 panic: 
???:?:?: 0x5629d097f337 in ??? (???)
???:?:?: 0x5629d18a17bb in ??? (???)
???:?:?: 0x5629d18c86a2 in ??? (???)
???:?:?: 0x5629d18cd7cd in ??? (???)
???:?:?: 0x5629d189d48f in ??? (???)
???:?:?: 0x5629d0d71884 in ??? (???)
???:?:?: 0x5629d0d3374a in ??? (???)
???:?:?: 0x5629d0b16135 in ??? (???)
???:?:?: 0x5629d0b09362 in ??? (???)
???:?:?: 0x5629d0b04f01 in ??? (???)
???:?:?: 0x5629d0a93b7f in ??? (???)
???:?:?: 0x5629d09adb8d in ??? (???)
???:?:?: 0x5629d097db76 in ??? (???)
???:?:?: 0x5629d097d309 in ??? (???)
???:?:?: 0x7f18ae251b24 in ??? (???)

edit: update Zig 0.9.0 -> 0.9.1

@hazeycode

Copy link
Copy Markdown
Author

Also pinging @marler8997, who may also be interested in these changes

Comment thread src/crypto.zig
var seed: [std.rand.DefaultCsprng.secret_seed_length]u8 = undefined;
try std.os.getrandom(&seed);
break :blk &std.rand.DefaultCsprng.init(seed).random;
break :blk &std.rand.DefaultCsprng.init(seed).random();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is a bug. The instance of DefaultCsprng must outlive the reference to it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch @marler8997. Presumably the tests will fail until this is modified to return the value rather than address. Unfortunately I'm still not sure why the tests fail to compile.

@Chris3606 Chris3606 May 21, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tracked this down entirely yet, but the compilation failure appears to originate from the final test in main ("Connecting to client.badssl.com with a client certificate").

Specifically, some piece of code that is compiled only when the options struct passed to client_connect has a client_certificates value.

Still sorting through trying to find something more useful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I debugged this test failure a while ago and I believe it was just because the certificate the test is expecting is different than what the website currently serves up. The test probably shouldn't expect the certificate never to change, rather, just verify it's valid.

@Chris3606 Chris3606 May 21, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the tests that fail at runtime, I believe you are correct. However I was talking about the OP's issue mentioned in the PR description, where the tests fail to compile; the compiler crashes with an error similar to this (sorry this was probably unclear in my original comment):

Code Generation [1750/2032] std.mem.Allocator.reallocAdvancedWithRetAddr... broken LLVM module found: Call parameter type does not match function signature!
  %229 = getelementptr inbounds { %"?[]const u8", i16 }, { %"?[]const u8", i16 }* %0, i32 0, i32 0, !dbg !36943
 %"?[]align(8) u8"*  call fastcc void @std.mem.Allocator.resize.403(%"?[]const u8"* sret(%"?[]align(8) u8") %229, %std.mem.Allocator* %2, %"[]u8"* %23, i64 %227), !dbg !36943

This is a bug in the Zig compiler.thread 821 panic:
Unable to dump stack trace: debug info stripped

Just finished looking at this in more detail, and the issue originates from the sign function in pcks1-1_5.zig, line 128:

return allocator.resize(
        enc_buf.ptr[0 .. rsa_result.limbs.len * @sizeOf(usize)],
        signature_length,
    );

the allocator.resize call is what's causing the compiler crash. I'm not entirely sure why; could be a data type/alignment issue, since the original value that enc_buf was derived from is casted from its original type to []u8 before being passed in? Could also be the code is fine and it is exclusively the result of a (stage 1) compiler bug, in which case I have no idea.

@hazeycode hazeycode changed the title Zig update Zig 0.9.0 update Feb 7, 2022
@hazeycode hazeycode changed the title Zig 0.9.0 update Zig 0.9.1 update Mar 7, 2022
@hazeycode

Copy link
Copy Markdown
Author

Closing in favour of #27

@hazeycode hazeycode closed this Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants