[PATCH] srcfiles: Always process the "zero" file table entry (CU comp_dir/name)

Ross Burton ross@burtonini.com
Tue Sep 22 13:54:01 GMT 2026


Hi Mark,

I just added this patch to our build system and tested a moderate
sized build. I can confirm that a reasonably large number of source
files were added to the listings which most likely should have been
there in the first place, and nothing else appears to have changed.

So from my end, this is good. Thanks!

Cheers,
Ross

On Tue, 22 Sept 2026 at 12:46, Mark Wielaard <mark@klomp.org> wrote:
>
> If the main CU file doesn't contain any references to the file table
> it wouldn't show up in the src files list (except if --cu-only was
> given). This is because file entry "zero" is special. It cannot be
> referred to by DW_AT file attributes (because zero means, no
> file). But technically it should be equal to (implicitly before
> DWARF5) the DW_AT_name of the main CU DIE (using a zero directory
> entry, equal to DW_AT_comp_dir). collect_sourcefiles skipped this
> implicit zero entry unless --cu-only was given.
>
> Fix this by always handling the zero file table entry. And for
> --cu-only to just exit the loop early, so no other entries are handled
> This is also an optimization, before --cu-only would go through all
> indexes, but always added the CU name. Which worked, because
> duplicates were removed, but was somewhat inefficient.
>
>            * src/srcfiles.cxx (collect_sourcefiles): Go from index
>            zero, exit after zero index for CU_only, always handle
>            index zero specially.
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=34666
>
> Signed-off-by: Mark Wielaard <mark@klomp.org>
> ---
>  src/srcfiles.cxx | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/src/srcfiles.cxx b/src/srcfiles.cxx
> index 9bbb6ef10473..e2fc0f128d71 100644
> --- a/src/srcfiles.cxx
> +++ b/src/srcfiles.cxx
> @@ -273,10 +273,14 @@ collect_sourcefiles (Dwfl_Module *dwflmod,
>              clog << "skipping cu=" << cuname << " due to empty comp_dir" << endl;
>            continue;
>          }
> -      for (size_t f = 1; f < nfiles; ++f)
> +      for (size_t f = 0; f < nfiles; ++f)
>          {
> +         /* For --cu-only we are only interested in the "zero" entry.  */
> +         if (CU_only && f != 0)
> +           break;
> +
>            const char *hat;
> -          if (CU_only)
> +          if (f == 0)
>            {
>              if (strcmp(cuname, "<unknown>") == 0 || strcmp(cuname, "<artificial>") == 0 )
>                continue;
> --
> 2.55.0
>


More information about the Elfutils-devel mailing list