From 4706679daca21b5d637afaf5b55858b26f0f8c16 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mon, 4 May 2020 10:19:38 +0100 Subject: [PATCH] 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. --- gas/ChangeLog | 9 +++++++++ gas/dwarf2dbg.c | 2 +- gas/testsuite/gas/elf/elf.exp | 1 + gas/testsuite/gas/elf/pr25917.d | 9 +++++++++ gas/testsuite/gas/elf/pr25917.s | 4 ++++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gas/testsuite/gas/elf/pr25917.d create mode 100644 gas/testsuite/gas/elf/pr25917.s diff --git a/gas/ChangeLog b/gas/ChangeLog index 1b973f584d1..630289cb67b 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,12 @@ +2020-05-04 Nick Clifton + + 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. + 2020-04-30 Alex Coplan * config/tc-aarch64.c (fix_insn): Implement for diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c index 9fdb34f209b..213f3828877 100644 --- a/gas/dwarf2dbg.c +++ b/gas/dwarf2dbg.c @@ -1995,7 +1995,7 @@ out_dir_and_file_list (void) /* Emit directory list. */ if (DWARF2_LINE_VERSION >= 5) { - if (dirs[0] == NULL) + if (dirs == NULL || dirs[0] == NULL) dir = remap_debug_filename ("."); else dir = remap_debug_filename (dirs[0]); diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp index 31026e4148e..86b304ae34f 100644 --- a/gas/testsuite/gas/elf/elf.exp +++ b/gas/testsuite/gas/elf/elf.exp @@ -274,6 +274,7 @@ if { [is_elf_format] } then { run_dump_test "dwarf2-18" $dump_opts run_dump_test "dwarf2-19" $dump_opts run_dump_test "dwarf-5-file0" $dump_opts + run_dump_test "pr25917" run_dump_test "bss" run_dump_test "bad-bss" run_dump_test "bad-section-flag" diff --git a/gas/testsuite/gas/elf/pr25917.d b/gas/testsuite/gas/elf/pr25917.d new file mode 100644 index 00000000000..6f83bbb5c5d --- /dev/null +++ b/gas/testsuite/gas/elf/pr25917.d @@ -0,0 +1,9 @@ +#as: --gdwarf-5 +#name: DWARF5: no files or directories +#readelf: -wl + +#... + The Directory Table is empty. + + No Line Number Statements. +#pass diff --git a/gas/testsuite/gas/elf/pr25917.s b/gas/testsuite/gas/elf/pr25917.s new file mode 100644 index 00000000000..ec8d5a9f9a1 --- /dev/null +++ b/gas/testsuite/gas/elf/pr25917.s @@ -0,0 +1,4 @@ + .section .debug_info,"",%progbits +.Ldebug_info0: + .dc.l 0x30 + .dc.l 0x5 -- 2.30.2