public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "roc at ocallahan dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug debug/101431] New: gcc-generated DWARF5 .debug_line directory entries violate the DWARF5 spec
Date: Tue, 13 Jul 2021 03:45:09 +0000	[thread overview]
Message-ID: <bug-101431-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2021-07-13  3:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13  3:45 roc at ocallahan dot org [this message]
2021-07-13  3:58 ` [Bug debug/101431] " roc at ocallahan dot org
2021-07-13  7:23 ` jakub at gcc dot gnu.org
2021-07-13  7:29 ` roc at ocallahan dot org
2021-07-13  7:29 ` rguenth at gcc dot gnu.org
2021-07-13  7:31 ` rguenth at gcc dot gnu.org
2021-07-13  7:37 ` rguenth at gcc dot gnu.org
2021-07-13  8:40 ` jakub at gcc dot gnu.org
2021-07-13  9:07 ` ebotcazou at gcc dot gnu.org
2021-07-13  9:10 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-101431-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).