public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/112726] New: Sometimes incorrect DW_AT_decl_file with -gdwarf-5 and -fdebug-prefix-map
@ 2023-11-27 12:36 gprocida at google dot com
  2023-12-06 13:37 ` [Bug debug/112726] " gprocida at google dot com
  0 siblings, 1 reply; 2+ messages in thread
From: gprocida at google dot com @ 2023-11-27 12:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112726
           Summary: Sometimes incorrect DW_AT_decl_file with -gdwarf-5 and
                    -fdebug-prefix-map
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gprocida at google dot com
  Target Milestone: ---

I've noticed a difference in GCC between DWARF 4 and DWARF 5. This only occurs
with -fdebug-prefix-map as far as I can tell, so it may be a bug in that code
path. Clang has a slightly different bug.

The issue is that DW_AT_decl_file attributes (sometimes) have the implicit
DW_AT_comp_dir explicitly prepended. This leads to confusion with the output
from tools such as llvm-dwarfdump that (very unhelpfully) also prepend the
implicit prefix. More significantly, it breaks tools (like libabigail, for
example) that expect

source file name = compilation directory + "/" + declaration file name

Beware! llvm-dwarfdump prepends DW_AT_comp_dir, always ("p") in the below
example.

Anything with "p/p" in the displayed path is wrong. For GCC, that's the case of
compiling x.c in /tmp and stripping off the prefix "/tm".

/tmp$ head x.c z/x.c 
==> x.c <==
int x;

==> z/x.c <==
int x;
/tmp$ for f in x z/x; do for g in 4 5; do for c in gcc-11 gcc-12 gcc-13
clang-13 clang-14 clang-15 clang-16; do $c -gdwarf-$g -fdebug-prefix-map=/tm=
-c $f.c -o $f.o; echo -n "$f $g $c"; llvm-dwarfdump $f.o | grep
DW_AT_decl_file; done; done; done
x 4 gcc-11                DW_AT_decl_file       ("p/x.c")
x 4 gcc-12                DW_AT_decl_file       ("p/x.c")
x 4 gcc-13                DW_AT_decl_file       ("p/x.c")
x 4 clang-13                DW_AT_decl_file     ("p/x.c")
x 4 clang-14                DW_AT_decl_file     ("p/x.c")
x 4 clang-15                DW_AT_decl_file     ("p/x.c")
x 4 clang-16                DW_AT_decl_file     ("p/x.c")
x 5 gcc-11                DW_AT_decl_file       ("p/p/x.c")
x 5 gcc-12                DW_AT_decl_file       ("p/p/x.c")
x 5 gcc-13                DW_AT_decl_file       ("p/p/x.c")
x 5 clang-13                DW_AT_decl_file     ("p/p/x.c")
x 5 clang-14                DW_AT_decl_file     ("p/p/x.c")
x 5 clang-15                DW_AT_decl_file     ("p/p/x.c")
x 5 clang-16                DW_AT_decl_file     ("p/p/x.c")
z/x 4 gcc-11                DW_AT_decl_file     ("p/z/x.c")
z/x 4 gcc-12                DW_AT_decl_file     ("p/z/x.c")
z/x 4 gcc-13                DW_AT_decl_file     ("p/z/x.c")
z/x 4 clang-13                DW_AT_decl_file   ("p/z/x.c")
z/x 4 clang-14                DW_AT_decl_file   ("p/z/x.c")
z/x 4 clang-15                DW_AT_decl_file   ("p/z/x.c")
z/x 4 clang-16                DW_AT_decl_file   ("p/z/x.c")
z/x 5 gcc-11                DW_AT_decl_file     ("p/z/x.c")
z/x 5 gcc-12                DW_AT_decl_file     ("p/z/x.c")
z/x 5 gcc-13                DW_AT_decl_file     ("p/z/x.c")
z/x 5 clang-13                DW_AT_decl_file   ("p/p/z/x.c")
z/x 5 clang-14                DW_AT_decl_file   ("p/p/z/x.c")
z/x 5 clang-15                DW_AT_decl_file   ("p/p/z/x.c")
z/x 5 clang-16                DW_AT_decl_file   ("p/p/z/x.c")

And for completeness:

/tmp$ gcc-13 -v
Using built-in specs.
COLLECT_GCC=gcc-13
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 13.2.0-4'
--with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-13
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-13-oyarai/gcc-13-13.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-oyarai/gcc-13-13.2.0/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=28
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Debian 13.2.0-4)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug debug/112726] Sometimes incorrect DW_AT_decl_file with -gdwarf-5 and -fdebug-prefix-map
  2023-11-27 12:36 [Bug debug/112726] New: Sometimes incorrect DW_AT_decl_file with -gdwarf-5 and -fdebug-prefix-map gprocida at google dot com
@ 2023-12-06 13:37 ` gprocida at google dot com
  0 siblings, 0 replies; 2+ messages in thread
From: gprocida at google dot com @ 2023-12-06 13:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Giuliano Procida <gprocida at google dot com> ---
Much of the initial report can be ignored, `llvm-dwarfdump` is buggy for DWARF
5 before version 15.

Here's a much simpler statement:

gcc -gdwarf-5 -fdebug-prefix-map=$(pwd)= -c foo.c is broken and the prefix is
not removed from the DWARF compilation directory / directory used for
DW_AT_decl_file.

For Clang, DWARF 4, a slightly shorter prefix or a source file in subdirectory,
things work better.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-06 13:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-27 12:36 [Bug debug/112726] New: Sometimes incorrect DW_AT_decl_file with -gdwarf-5 and -fdebug-prefix-map gprocida at google dot com
2023-12-06 13:37 ` [Bug debug/112726] " gprocida at google dot com

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).