% cat a.s
% as -gdwarf-2 a.s -o a.o
% llvm-dwarfdump a.o
a.o: file format elf64-x86-64
0x00000000: Compile Unit: length = 0x0000001e, format = DWARF32, version = 0x0002, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000022)
DW_AT_producer ("GNU AS 2.35.1")
DW_AT_ranges (since DWARF v3; probably ok to have it in -gdwarf-2) probably should not have contribution from non-executable sections.
The master branch has been updated by Nick Clifton <email@example.com>:
Author: Nick Clifton <firstname.lastname@example.org>
Date: Thu Nov 12 11:43:20 2020 +0000
Stop Gas from generating line info or address ranges for sections that do not contain code or are not loaded.
* dwarf2dbg.c (dwarf2_gen_line_info_1): Do not record lines in
sections that are not executable or not loadable.
(out_debug_line): Move warning message into dwarf2_gen_line_info_1.
* testsuite/gas/elf/dwarf2-20.s: New test.
* testsuite/gas/elf/dwarf2-20.d: New test driver.
* testsuite/gas/elf/elf.exp: Run the new test.
* testsuite/gas/elf/warn-2.s: Use the .nop directive.
Agreed. I have applied a patch to implement this suggestion. I also
extended it to cover sections that are not loaded as well, since I do
not see how debug information for them would be useful either.