llvm/llvm-project

Clang Generates DWARF Info That Valgrind Can't Read

gavinhoward opened this issue ยท 5 comments

I ran the following:

$ git clone https://github.com/gavinhoward/bc.git
$ cd bc
$ # -g enables debug info.
$ # -O0 sets the optimization level.
$ # -v enables a Valgrind build.
$ CC=clang ./configure -g -O0 -v
$ make
$ printf 'halt\n' | \
    valgrind --error-exitcode=100 --leak-check=full --show-leak-kinds=all \
    --errors-for-leak-kinds=all --num-callers=500 --child-silent-after-fork=yes \
    bin/bc tests/bc/scripts/screen.bc

I get the following output:

==26137== Memcheck, a memory error detector
==26137== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==26137== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==26137== Command: bin/bc tests/bc/decimal.txt
==26137==
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
==26137== Valgrind: debuginfo reader: ensure_valid failed:
==26137== Valgrind:   during call to ML_(img_get)
==26137== Valgrind:   request for range [4771378, +4) exceeds
==26137== Valgrind:   valid image size of 646808 for image:
==26137== Valgrind:   "<snip>/bin/bc"
==26137==
==26137== Valgrind: debuginfo reader: Possibly corrupted debuginfo file.
==26137== Valgrind: I can't recover.  Giving up.  Sorry.
==26137==

I expected the following output:

==37446== Memcheck, a memory error detector
==37446== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==37446== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==37446== Command: bin/bc tests/bc/scripts/screen.bc
==37446==
480
==37446==
==37446== HEAP SUMMARY:
==37446==     in use at exit: 0 bytes in 0 blocks
==37446==   total heap usage: 1,772 allocs, 1,772 frees, 430,647 bytes allocated
==37446==
==37446== All heap blocks were freed -- no leaks are possible
==37446==
==37446== For lists of detected and suppressed errors, rerun with: -s
==37446== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

This is with Clang 14.0.6 and Valgrind 3.19.0.

I have confirmed that GCC 11.3.0 works. This is why I believe this is a Clang issue, not a Valgrind issue. I could be wrong, though.

I have also confirmed that -ggdb does not work with Clang.

The uname -a for the system:

Linux <hostname> 5.15.52-gentoo-x86_64 #1 SMP PREEMPT Sun Jul 10 21:15:48 MDT 2022 x86_64 <cpu>

This Gentoo system is up-to-date.

@llvm/issue-subscribers-debuginfo

Form code 0x25 is new in DWARF v5, which is Clang's default. Probably it is not gcc's default.
Try compiling with -gdwarf-4 instead of just -g to get DWARF v4 output; probably valgrind can read that.

That does indeed work. I'll just have to use that workaround until Valgrind updates, I guess.

Thank you for the help.

That does indeed work.

Unless a precompiled shared library is linked with dwarf-5 by clang.

For those who googled this issue, it's fixed in Valgrind 3.20, released October 2022. https://bugs.kde.org/show_bug.cgi?id=452758