]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Correct bounds check when working around GAS DWARF 5 directory table bug
authorKeith Seitz <keiths@redhat.com>
Fri, 19 Sep 2025 17:51:57 +0000 (10:51 -0700)
committerKeith Seitz <keiths@redhat.com>
Fri, 19 Sep 2025 17:51:57 +0000 (10:51 -0700)
commit409704cf48b4a7f31d02d61966ac579da46c9b1f
tree138b9b602cbebb4f169620a3570c00317a8c008b
parent2e56a99e6418cdc211efce6a358270dcef591933
Correct bounds check when working around GAS DWARF 5 directory table bug

Recent Go toolchains are causing GDB to crash on a relatively recent
workaround for a GAS bug:

commit a833790a626d9620319d0ca6aee23daa584d445c
Date:   Wed Nov 1 00:33:12 2023 +0100

    [gdb/symtab] Work around gas PR28629

In the original GAS bug, the first directory table entry did not contain
the current directory of the compilation. So the above commit added a
workaround fix to prepend the second directory table entry.

However recent Go toolchain compilations (specifically on aarch64)
only output a single directory table entry. Looking at the workaround:

       if (lh->version == 5 && lh->is_valid_file_index (1))
         {
           std::string dir = lh->include_dir_at (1);
           fnd.set_comp_dir (std::move (dir));
         }

`lh->is_valid_file_index (1)' is true, but since the directory table only
has one entry, `include_dir_at (1)' returns nullptr. Consequently the
std::string ctor will segfault. Since there are no guarantees that the file
and directory tables are the same size, a better bounds check is to simply
rely on `include_dir_at' to ensure a valid directory table entry.

I have updated the workaround commit's test, gdb.dwarf2/dw2-gas-workaround.exp
and tested on x86_64 and aarch64 RHEL 9 and Fedora 41.

Approved-By: Andrew Burgess <aburgess@redhat.com>
(cherry picked from commit 31cb4bb676dde0db3f24e03380a02ae92633c98f)
gdb/dwarf2/read.c
gdb/testsuite/gdb.dwarf2/dw2-gas-workaround.exp