ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.84k stars 2.48k forks source link

Symbols are not included in macho binary #14199

Open danielchasehooper opened 1 year ago

danielchasehooper commented 1 year ago

Zig Version

0.11.0-dev.449+665eba93c

Steps to Reproduce and Observed Behavior

reproduced on a M1 Pro running macOS 13.1

  1. Put this in a file named deploy.zig:
    
    const std = @import("std");

pub fn main() !void { var gpaimpl = std.heap.GeneralPurposeAllocator(.{}){}; try std.fs.cwd().deleteTree("build"); = try std.fs.cwd().makeOpenPath("build", .{}); var static_dir = try std.fs.cwd().openIterableDir("static", .{}); var in_file = try static_dir.dir.openFile("bla", .{ .mode = .readonly }); = try in_file.readToEndAlloc(gpa_impl.allocator(), 50 * 1_048_576); }



2. compile with `zig build-exe deploy.zig`
3. open Instruments.app
4. file>New
5. choose the `time profiler` template 
6. in the top left of the resulting window, click your computer's name -> submenu -> `choose target..`
7. locate the `deploy` binary you generated in step 2
8. click the record button in the main instruments window
9. after recording is complete, select the `time profiler` instrument row
10. show the detail area with cmd+0

the function addresses are not symbolicated

### Expected Behavior

stack traces should be symbolicated. If I comment out any line in the above code, recompile, then rerecord from instruments, the stack traces are suddenly symbolicated.
kubkon commented 1 year ago

Thanks for the report @danielchasehooper!

kubkon commented 1 year ago

Could you re-check if this now fixed for you in latest master? It worked for me with Zig version 0.11.0-dev.2374+a329450aa

Screenshot 2023-04-05 at 08 31 20
danielchasehooper commented 1 year ago

Yes, fixed in 0.11.0-dev.2652+8ba937c78

karlseguin commented 1 year ago

This appears to have reverted? Like @danielchasehooper, I get symbols in 0.11.0-dev.2652+8ba937c78 but I don't from the latest (0.11.0-dev.2892+fd6200eda)

kubkon commented 1 year ago

This appears to have reverted? Like @danielchasehooper, I get symbols in 0.11.0-dev.2652+8ba937c78 but I don't from the latest (0.11.0-dev.2892+fd6200eda)

I will reopen and investigate. Intel or M1?

karlseguin commented 1 year ago

M2

kubkon commented 1 year ago

I'll re-test with latest master locally on the M1 and see if it regressed, and report back.

pcarrier commented 1 year ago

Same issue here with https://github.com/pcarrier/zgraph

danielchasehooper commented 1 year ago

@kubkon Since this bug seems to be sensitive to the code that goes into the binary, I think it'd be worthwhile to go back to the zig version this was filed under and determining the root cause, even if its unreproducible on latest zig. It's possible that it stops reproducing in new builds due to changes in the standard library, and not because the underlying issue was fixed.

gatesn commented 1 year ago

The symbols work for me with -O Debug, but seem to be missing with -O ReleaseFast -fno-strip. Is that expected?

ziord commented 10 months ago

This still happens with 0.12.0-dev.888+130227491