Bug 25917

Summary: segmentation fault with -gdwarf-5
Product: binutils Reporter: Nick Desaulniers <ndesaulniers>
Component: gasAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: amodra, nickc
Priority: P2    
Version: 2.35   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed: 2020-05-04 00:00:00

Description Nick Desaulniers 2020-05-04 02:52:51 UTC
With the fix from https://sourceware.org/bugzilla/show_bug.cgi?id=25612, I can now compile a Linux kernel with Clang and assemble with GNU as with DWARF5.

Testing the same patch set with GCC 7.5+ GNU as (ToT) produces a crash in GNU as.  I reran the kernel build with `make V=1` to get the compiler invocation, then reran that with `-v` to get the assembler invocation.  From there, I've trimmed it down to the following invocation and input.

$ PATH=~/binutils-gdb/binutils:$PATH as -gdwarf-5 -o scripts/mod/empty.o /tmp/ccDA463U.s
/tmp/ccDA463U.s: Assembler messages:
/tmp/ccDA463U.s: Internal error (Segmentation fault).
Please report this bug.

$ cat /tmp/ccDA463U.s 
        .section        .debug_info,"",@progbits
        .long   0x30
        .value  0x5
Comment 1 cvs-commit@gcc.gnu.org 2020-05-04 09:20:26 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:


commit 4706679daca21b5d637afaf5b55858b26f0f8c16
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon May 4 10:19:38 2020 +0100

    Fix an illegal memory access in the assembler when generating a DWARF5 file/directory table with no entries.
            PR 25917
            * dwarf2dbg.c (out_dir_and_file_list): Check for the directory
            table's existence before looking at its entries.
            * testsuite/gas/elf/pr25917.s: New test source file.
            * testsuite/gas/elf/pr25917.d: New test driver.
            * testsuite/gas/elf/elf.exp (run_elf_list_test): Run the new test.
Comment 2 Nick Clifton 2020-05-04 09:21:56 UTC
Hi Nick,

  Thanks for reporting this bug.  It was a simple case of not checking 
  to see if the directory table existed before trying to write it out...

Comment 3 Alan Modra 2020-05-04 10:06:59 UTC
readelf -wL on the testcase is interesting too.
end of data encountered whilst reading LEB
Comment 4 Nick Clifton 2020-05-04 11:29:45 UTC
(In reply to Alan Modra from comment #3)
> readelf -wL on the testcase is interesting too.
> end of data encountered whilst reading LEB

Oops - thanks for catching that Alan - the code is still generating a 
directory table entry even though there are no directories.  I am 
testing a fix now.
Comment 5 cvs-commit@gcc.gnu.org 2020-05-04 12:51:04 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:


commit 070b775f03ebdab6d0d007787fe19b916af4439c
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon May 4 13:50:05 2020 +0100

    GAS: Do not create an entry for the default directory if the directory table is empty.  Improve readelf's decoding of empty directory and file name tables.
            PR 25917
            * dwarf.c (display_debug_lines_decoded): Warn if encountering a
            supicious number of entries for DWARF-5 format directory and file
            name tables.  Do not display file name table header if the table
            is empty.  Do not allocate space for empty tables.
Comment 6 Nick Clifton 2020-05-04 12:51:41 UTC
Right - this time it should be fixed for real.