Verbose-asm equivalent

Is there an equivalent to verbose-asm for zig?

As a reminder (man gcc):

           Put  extra  commentary  information  in  the generated assembly code to make it more readable.  This option is generally only of use to those who actually need to read the generated assembly code
           (perhaps while debugging the compiler itself).
           -fno-verbose-asm, the default, causes the extra information to be omitted and is useful when comparing two assembler files.
           The added comments include:
           *   information on the compiler version and command‐line options,
           *   the source code lines associated with the assembly instructions, in the form FILENAME:LINENUMBER:CONTENT OF LINE,
           *   hints on which high‐level expressions correspond to the various assembly instruction operands.

           For example, given this C source file:
                   int test (int n)
                     int i;
                     int total = 0;

                     for (i = 0; i < n; i++)
                       total += i * i;

                     return total;

           compiling to (x86_64) assembly via -S and emitting the result direct to stdout via -o -
                   gcc -S test.c -fverbose-asm -Os -o -
           gives output similar to this:

                           .file   "test.c"
                   # GNU C11 (GCC) version 7.0.0 20160809 (experimental) (x86_64-pc-linux-gnu)
                   # options passed:

                           .globl  test
                           .type   test, @function
                   # test.c:4:   int total = 0;
                           xorl    %eax, %eax      # <retval>
                   # test.c:6:   for (i = 0; i < n; i++)
                           xorl    %edx, %edx      # i
                   # test.c:6:   for (i = 0; i < n; i++)
                           cmpl    %edi, %edx      # n, i
                           jge     .L5     #,
                   # test.c:7:     total += i * i;
                           movl    %edx, %ecx      # i, tmp92
                           imull   %edx, %ecx      # i, tmp92
                   # test.c:6:   for (i = 0; i < n; i++)

I don’t know if Zig can dump this itself, but you can produce a similar result by dissassembling a binary with debug symbols using objdump --source-comment. If you want file names and line numbers you can add -l.


Yes it doesn’t produce a result as detailed as -fverbose-asm but it’s indeed much better than the basic output:

objdump -lSd your_binary