https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101431

            Bug ID: 101431
           Summary: gcc-generated DWARF5 .debug_line directory entries
                    violate the DWARF5 spec
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roc at ocallahan dot org
  Target Milestone: ---

For the "Line Number Program Header" "directories" field, the DWARF5 spec says

"The first entry is the current directory of the compilation. Each additional
path entry is either a full path name or is relative to the current directory
of
the compilation."

In a simple testcase (see below) I get the following tables emitted (gcc
11.1.1):

The Directory Table:
  0 out
  1 out
  2 /usr/include

The File Name Table
  Entry Dir     Time    Size    Name
  0     0       0       0       file.c
  1     1       0       0       file.c
  2     1       0       0       message.h
  3     2       0       0       stdio.h

The compilation unit info from .debug_info is

UNIT<header overall offset = 0x0000006a>:
  dwo_id           = 0x6ef97fe679ccccda
< 0><0x00000014>  DW_TAG_skeleton_unit
                    DW_AT_low_pc                0x00201728
                    DW_AT_high_pc               <offset-from-lowpc>21
                    DW_AT_stmt_list             <.debug_line+0x000000bd>
                    DW_AT_dwo_name              out/main.dwo
                    DW_AT_comp_dir              /tmp/pernosco-submit-test
                    DW_AT_GNU_pubnames          yes
                    DW_AT_addr_base             <.debug_addr+0x00000030>

The correct path for 'file.c' is /tmp/pernosco-submit-test/out/file.c.

Clearly, treating directory entry 1 as relative to directory entry 0 would give
the wrong file path (something containing 'out/out'). It looks like gcc intends
all directory entries to be treated as relative to the DW_AT_comp_dir from the
.debug_info unit?

Note that if the latter is true, then that violates the intent of the new
behavior in DWARF5:

> In DWARF Version 5, the current directory is explicitly present in the
directories field. This is needed to support the common practice of stripping
all but the line number sections ( .debug_line and .debug_line_str ) from an
executable.

To reproduce this bug:

git clone --recurse-submodules https://github.com/Pernosco/pernosco-submit-test
cd pernosco-submit-test
./build.sh
dwarfdump -l out/main.debug

Reply via email to