From add63e0317b6e27dd4077b19e998e6c56a3becb5 Mon Sep 17 00:00:00 2001 From: Aaron Merey Date: Fri, 9 Feb 2024 21:10:19 -0500 Subject: [PATCH] Handle DW_AT_decl_file 0 Modify dwarf_decl_file to support DW_AT_decl_file with value 0. Because of inconsistencies in the DWARF 5 spec, it is ambiguous whether DW_AT_decl_file value 0 is a valid .debug_line file table index for the main source file or if it means that there is no source file specified. dwarf_decl_file interprets DW_AT_decl_file 0 as meaning no source file is specified. This works with DWARF 5 produced by gcc, which duplicates the main source file name at index 0 and 1 of the file table and avoids using DW_AT_decl_file 0. However clang uses DW_AT_decl_file 0 for the main source index with no duplication at another index. In this case dwarf_decl_file will be unable to find the file name of the main file. This patch changes dwarf_decl_file to treat DW_AT_decl_file 0 as a normal index into the file table, allowing it to work with DWARF 5 debuginfo produced by clang. As for earlier DWARF versions which exclusively use DW_AT_decl_file 0 to indicate that no source file is specified, dwarf_decl_file will now return the name "???" if called on a DIE with DW_AT_decl_file 0. https://sourceware.org/bugzilla/show_bug.cgi?id=31111 Signed-off-by: Aaron Merey --- libdw/dwarf_decl_file.c | 11 ++--------- tests/Makefile.am | 3 ++- tests/run-allfcts.sh | 17 +++++++++++++++++ tests/testfile-dwarf5-line-clang.bz2 | Bin 0 -> 2777 bytes 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100755 tests/testfile-dwarf5-line-clang.bz2 diff --git a/libdw/dwarf_decl_file.c b/libdw/dwarf_decl_file.c index 75662a334..7dde4af07 100644 --- a/libdw/dwarf_decl_file.c +++ b/libdw/dwarf_decl_file.c @@ -48,13 +48,6 @@ dwarf_decl_file (Dwarf_Die *die) &idx) != 0) return NULL; - /* Zero means no source file information available. */ - if (idx == 0) - { - __libdw_seterrno (DWARF_E_NO_ENTRY); - return NULL; - } - /* Get the array of source files for the CU. */ struct Dwarf_CU *cu = attr_mem.cu; if (cu->lines == NULL) @@ -70,8 +63,8 @@ dwarf_decl_file (Dwarf_Die *die) if (cu->lines == (void *) -1l) { - /* If the file index is not zero, there must be file information - available. */ + /* If DW_AT_decl_file was present, there should be file information + available. */ __libdw_seterrno (DWARF_E_INVALID_DWARF); return NULL; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 13bd9d568..b075e3c36 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -634,7 +634,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-largealign.o.bz2 run-strip-largealign.sh \ run-funcretval++11.sh \ test-ar-duplicates.a.bz2 \ - run-dwfl-core-noncontig.sh testcore-noncontig.bz2 + run-dwfl-core-noncontig.sh testcore-noncontig.bz2 \ + testfile-dwarf5-line-clang.bz2 if USE_VALGRIND diff --git a/tests/run-allfcts.sh b/tests/run-allfcts.sh index 9c0a55d86..4dd0284a8 100755 --- a/tests/run-allfcts.sh +++ b/tests/run-allfcts.sh @@ -170,4 +170,21 @@ testrun_compare ${abs_builddir}/allfcts testfile-lto-gcc9 <<\EOF /home/mark/src/tests/testfile-lto-main.c:6:main EOF +# = dwarf5-line.c = +# int +# main (int argc, char **argv) +# { +# return 0; +# } + +# Using clang version 17.0.4 (Fedora 17.0.4-1.fc39) +# clang -gdwarf-5 -o testfile-dwarf5-line-clang dwarf5-line.c + +testfiles testfile-dwarf5-line-clang + +# Check that dwarf_decl_file can handle .debug_line file table index 0 +testrun_compare ${abs_builddir}/allfcts testfile-dwarf5-line-clang <<\EOF +/home/amerey/test/dwarf5-line.c:2:main +EOF + exit 0 diff --git a/tests/testfile-dwarf5-line-clang.bz2 b/tests/testfile-dwarf5-line-clang.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..bdd66e9638f667705e983c6c7515f55867318285 GIT binary patch literal 2777 zc-jHk3MTbJT4*^jL0KkKSw!Q^-~bB{|NsC0|Nrmr|NH;%|M&mr|NsB~Y3J!9q*Lwf z=2Z6I|6kwNS4)NM@} zs2U9b0MkGK&;S4c00000000000009K2tgjCo~MF(Q}suv9#d)!r1dgAC+Z=SA?g}4 zP-H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