Skip to content

zig cc strips debuginfo from object files #11194

@sfackler

Description

@sfackler

Zig Version

0.10.0-dev.1355+8a43d67c3

Steps to Reproduce

  1. Create a C file test.c with a main function
  2. Compile it into an object file with debuginfo using GCC: gcc -c -g test.c
  3. Link it with zig cc: zig cc test.o
  4. Look at the sections in the resulting a.out: size -A a.out
  5. Link it with gcc: gcc test.o
  6. Look at the sections in the resulting a.out: size -A a.out

Expected Behavior

The binary contains the .debug_<foo> sections generated in the test.o object file both when created by gcc and by zig cc:

a.out  :
section              size    addr
.interp                28     792
.note.gnu.property     32     824
.note.gnu.build-id     36     856
.note.ABI-tag          32     892
.gnu.hash              36     928
.dynsym               168     968
.dynstr               130    1136
.gnu.version           14    1266
.gnu.version_r         32    1280
.rela.dyn             192    1312
.rela.plt              24    1504
.init                  27    4096
.plt                   32    4128
.plt.got               16    4160
.plt.sec               16    4176
.text                 389    4192
.fini                  13    4584
.rodata                16    8192
.eh_frame_hdr          68    8208
.eh_frame             264    8280
.init_array             8   15800
.fini_array             8   15808
.dynamic              496   15816
.got                   72   16312
.data                  16   16384
.bss                    8   16400
.comment               41       0
.debug_aranges         48       0
.debug_info           767       0
.debug_abbrev         204       0
.debug_line           272       0
.debug_str            640       0
Total                4145

Actual Behavior

The binary does contain debug sections when linked by gcc, but not by zig cc:

a.out  :
section          size      addr
.interp            28   2097832
.note.ABI-tag      32   2097860
.dynsym            96   2097896
.gnu.version        8   2097992
.gnu.version_r     32   2098000
.gnu.hash          28   2098032
.hash              40   2098060
.dynstr            61   2098100
.rela.dyn          48   2098168
.rela.plt          24   2098216
.rodata            12   2098240
.eh_frame_hdr      28   2098252
.eh_frame          84   2098280
.text             230   2102464
.init              23   2102696
.fini               9   2102720
.plt               32   2102736
.dynamic          336   2106864
.got               16   2107200
.got.plt           32   2111312
.comment          251         0
Total            1450

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorzig ccZig as a drop-in C compiler feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions