Skip to content

too much junk is outputted into object file #15353

Closed

Description

@andrewrk

zig version: 0.11.0-dev.2653+2568da2f4

const std = @import("std");

pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, start: ?usize) noreturn {
    _ = .{ msg, st, start };
    unreachable;
}

export fn entry() void {}

Look at all this garbage:

$ zig build-obj test.zig
$ readelf -s test.o | grep FUNC
     2: 0000000000000000   162 FUNC    LOCAL  DEFAULT    1 target.Target.Cp[...]
     3: 00000000000000b0   220 FUNC    LOCAL  DEFAULT    1 target.Target.Cp[...]
     5: 0000000000000190    54 FUNC    LOCAL  DEFAULT    1 test2.panic
     6: 00000000000001d0    53 FUNC    LOCAL  DEFAULT    1 builtin.panicOut[...]
     8: 0000000000000220   555 FUNC    LOCAL  DEFAULT    1 debug.panicExtra[...]
    10: 0000000000000450    53 FUNC    LOCAL  DEFAULT    1 builtin.panicSta[...]
    11: 0000000000000490   308 FUNC    LOCAL  DEFAULT    1 fmt.bufPrint__an[...]
    13: 00000000000005d0   300 FUNC    LOCAL  DEFAULT    1 mem.copy__anon_1469
    14: 0000000000000700   555 FUNC    LOCAL  DEFAULT    1 debug.panicExtra[...]
    15: 0000000000000d90    40 FUNC    LOCAL  DEFAULT    1 io.fixed_buffer_[...]
    16: 0000000000000dc0    21 FUNC    LOCAL  DEFAULT    1 io.fixed_buffer_[...]
    17: 0000000000000930   360 FUNC    LOCAL  DEFAULT    1 fmt.format__anon_1595
    18: 0000000000000c50   215 FUNC    LOCAL  DEFAULT    1 builtin.returnError
    19: 0000000000000de0   139 FUNC    LOCAL  DEFAULT    1 io.fixed_buffer_[...]
    21: 0000000000000e70   308 FUNC    LOCAL  DEFAULT    1 fmt.bufPrint__an[...]
    23: 0000000000000aa0   425 FUNC    LOCAL  DEFAULT    1 io.writer.Writer[...]
    24: 0000000000000d30    81 FUNC    LOCAL  DEFAULT    1 fmt.formatType__[...]
    25: 0000000000001430   115 FUNC    LOCAL  DEFAULT    1 io.writer.Writer[...]
    28: 0000000000002050    61 FUNC    LOCAL  DEFAULT    1 fmt.formatValue_[...]
    29: 0000000000003d00   360 FUNC    LOCAL  DEFAULT    1 fmt.format__anon_1830
    30: 0000000000000fb0  1141 FUNC    LOCAL  DEFAULT    1 io.fixed_buffer_[...]
    34: 00000000000014b0    69 FUNC    LOCAL  DEFAULT    1 debug.assert
    35: 0000000000001500   459 FUNC    LOCAL  DEFAULT    1 fmt.Parser.specifier
    36: 00000000000016d0   238 FUNC    LOCAL  DEFAULT    1 fmt.Parser.maybe
    37: 00000000000017c0   445 FUNC    LOCAL  DEFAULT    1 fmt.Parser.until
    39: 0000000000001980   769 FUNC    LOCAL  DEFAULT    1 fmt.Parser.number
    43: 0000000000001c90   261 FUNC    LOCAL  DEFAULT    1 fmt.Parser.char
    44: 0000000000001da0   283 FUNC    LOCAL  DEFAULT    1 fmt.Parser.peek
    45: 0000000000001ec0   393 FUNC    LOCAL  DEFAULT    1 fmt.ArgState.nextArg
    47: 0000000000002090    78 FUNC    LOCAL  DEFAULT    1 fmt.formatIntVal[...]
    48: 00000000000020e0  2085 FUNC    LOCAL  DEFAULT    1 fmt.formatInt__a[...]
    49: 0000000000002910    18 FUNC    LOCAL  DEFAULT    1 math.absCast__an[...]
    50: 0000000000002930    20 FUNC    LOCAL  DEFAULT    1 fmt.isComptime
    51: 0000000000002950   374 FUNC    LOCAL  DEFAULT    1 fmt.digits2
    53: 0000000000002ad0   331 FUNC    LOCAL  DEFAULT    1 fmt.digitToChar
    54: 0000000000002c20  1393 FUNC    LOCAL  DEFAULT    1 fmt.formatBuf__a[...]
    56: 0000000000003290  1701 FUNC    LOCAL  DEFAULT    1 unicode.utf8Coun[...]
    57: 0000000000003aa0   567 FUNC    LOCAL  DEFAULT    1 io.writer.Writer[...]
    58: 00000000000031a0   232 FUNC    LOCAL  DEFAULT    1 unicode.utf8Byte[...]
    59: 0000000000003940    18 FUNC    LOCAL  DEFAULT    1 mem.readIntNativ[...]
    61: 0000000000003960   306 FUNC    LOCAL  DEFAULT    1 unicode.utf8Decode
    62: 0000000000003e70   489 FUNC    LOCAL  DEFAULT    1 unicode.utf8Decode2
    63: 0000000000004060   828 FUNC    LOCAL  DEFAULT    1 unicode.utf8Decode3
    64: 00000000000043a0  1023 FUNC    LOCAL  DEFAULT    1 unicode.utf8Decode4
    65: 00000000000047a0   111 FUNC    LOCAL  DEFAULT    1 mem.set__anon_1862
    66: 0000000000004810    49 FUNC    LOCAL  DEFAULT    1 math.min__anon_1863
    67: 0000000000003ce0    30 FUNC    LOCAL  DEFAULT    1 fmt.ArgState.has[...]
   112: 0000000000000210     6 FUNC    GLOBAL DEFAULT    1 entry

I expect to see only the entry symbol, even in debug builds. This should be true even if I delete the panic handler override, since the entry function contains no panics.

Activity

  1. added
    bug
    regression
    on Apr 18, 2023
  2. added this to the 0.11.0 milestone on Apr 18, 2023
  3. mlugg commented on Apr 18, 2023

    @mlugg
    Member

    I may be wrong, but I suspect this is highly related to #6256 - I imagine some comptime evaluation in std is hitting e.g. formatting code and causing it to be analyzed and included in the binary.

  4. kubkon commented on Apr 20, 2023

    @kubkon
    Member

    This actually took me by surprise on Windows today when suddenly the symtab is enormous for a very simple Zig source pub fn main() void {}. Oh, and I am talking about our self-hosted x86 backend and Coff linker.

  5. added 6 commits that reference this issue on May 29, 2023
    85ff300
    f8f95eb
    93a8cb5
    1df228c
    1125a02
    4976b58
  6. added a commit that references this issue on May 9, 2024
    919d9e6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugregression

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions