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

bad alignment cast in macho linking code #14558

Closed
andrewrk opened this issue Feb 5, 2023 · 4 comments · Fixed by #14575
Closed

bad alignment cast in macho linking code #14558

andrewrk opened this issue Feb 5, 2023 · 4 comments · Fixed by #14575
Labels
bug Observed behavior contradicts documented or intended behavior linking os-macos
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Feb 5, 2023

A user on IRC reported the following stack trace against zig 0.10.1:

thread 473118 panic: incorrect alignment
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/link/MachO/Object.zig:114:72: 0x1030338ab in link.MachO.Object.parse (zig2)
                    @alignCast(@alignOf(macho.nlist_64), &self.contents[symtab.symoff]),
                                                                       ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/link/MachO/Archive.zig:230:21: 0x1030485f7 in link.MachO.Archive.parseObject (zig2)
    try object.parse(gpa, cpu_arch);
                    ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/link/MachO/zld.zig:1056:55: 0x102d4af7f in link.MachO.zld.Zld.resolveSymbolsInArchives (zig2)
                const object = try archive.parseObject(gpa, cpu_arch, offsets.items[0]);
                                                      ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/link/MachO/zld.zig:4219:41: 0x102ad5443 in link.MachO.zld.linkWithZld (zig2)
        try zld.resolveSymbolsInArchives(&resolver);
                                        ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/link/MachO.zig:427:44: 0x10281667f in link.MachO.flush (zig2)
        .one_shot => return zld.linkWithZld(self, comp, prog_node),
                                           ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/link.zig:797:72: 0x10281345b in link.File.flush (zig2)
            .macho => return @fieldParentPtr(MachO, "base", base).flush(comp, prog_node),
                                                                       ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/Compilation.zig:2516:24: 0x10278ca2f in Compilation.flush (zig2)
    comp.bin_file.flush(comp, prog_node) catch |err| switch (err) {
                       ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/Compilation.zig:2480:27: 0x10277fb67 in Compilation.update (zig2)
            try comp.flush(main_progress_node);
                          ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/main.zig:3361:20: 0x102701857 in main.updateModule (zig2)
    try comp.update();
                   ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/main.zig:3028:17: 0x10263e09f in main.buildOutputType (zig2)
    updateModule(gpa, comp, hook) catch |err| switch (err) {
                ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/main.zig:230:31: 0x1025c6f6b in main.mainArgs (zig2)
        return buildOutputType(gpa, arena, args, .{ .build = .Exe });
                              ^
/private/tmp/nix-build-zig-0.10.1.drv-0/source/src/stage1.zig:56:24: 0x1025c68a3 in main (zig2)
        stage2.mainArgs(gpa, arena, args) catch unreachable;
                       ^

I examined the corresponding master branch code, and it looks to me like the problem is still there:

@alignCast(@alignOf(macho.nlist_64), &self.contents[symtab.symoff]),

Note that this field is marked align(1), so the alignment cast is completely unnecessary:

in_symtab: ?[]align(1) const macho.nlist_64 = null,

cc @kubkon

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-macos linking labels Feb 5, 2023
@andrewrk andrewrk added this to the 0.11.0 milestone Feb 5, 2023
@kubkon
Copy link
Member

kubkon commented Feb 5, 2023

Nice catch, thanks @andrewrk. There is one more issue like this in the linker codebase that I will fix together with this and #14559

@Anton-4
Copy link

Anton-4 commented Feb 21, 2023

Will this fix make it to 0.10.2?
I'm asking because this issue seems to be a blocker to getting zig 10 available on nix for darwin. Being able to use zig through nix is really convenient for roc contributors and also essential for when we want to release roc on nix.

@winterqt
Copy link
Contributor

@Anton-4 See #14559 (comment).

@kubkon Are you still interested in backporting the patches for us? I tried a bit ago and was unsuccessful, though I suppose you can do it easier :)

@kubkon
Copy link
Member

kubkon commented Feb 22, 2023

@winterqt Oh shoot, yeah. I was meant to do that a while back but my attention got diverted by other work. I will work on a patch for Nix shortly.

@Anton-4 There will not be a 0.10.2 patch release, and the changes will make it into 0.11.0. However, I will try to come up with a patch with @winterqt specifically for Nix in the meantime.

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 linking os-macos
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants