Bug 26850 - as -g: remove non-executable sections' contribution from DW_AT_ranges
Summary: as -g: remove non-executable sections' contribution from DW_AT_ranges
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Nick Clifton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-06 17:28 UTC by Fangrui Song
Modified: 2020-11-12 11:46 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-11-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-11-06 17:28:43 UTC
% cat a.s
.section .alloc0,"a"
ret
.section .alloc1,"a"
ret
.section .nonalloc,""
ret

% as -gdwarf-2 a.s -o a.o

% llvm-dwarfdump a.o
a.o:    file format elf64-x86-64

.debug_info contents:
0x00000000: Compile Unit: length = 0x0000001e, format = DWARF32, version = 0x0002, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000022)

0x0000000b: DW_TAG_compile_unit
              DW_AT_stmt_list   (0x00000000)
              DW_AT_ranges      (0x00000000
                 [0x0000000000000000, 0x0000000000000001)
                 [0x0000000000000000, 0x0000000000000001)
                 [0x0000000000000000, 0x0000000000000001))
              DW_AT_name        ("a.s")
              DW_AT_comp_dir    ("/tmp/c")
              DW_AT_producer    ("GNU AS 2.35.1")
              DW_AT_language    (DW_LANG_Mips_Assembler)

DW_AT_ranges (since DWARF v3; probably ok to have it in -gdwarf-2) probably should not have contribution from non-executable sections.
Comment 1 Sourceware Commits 2020-11-12 11:44:11 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bcb78b47614ed252226da1a688558a17d8a99ce8

commit bcb78b47614ed252226da1a688558a17d8a99ce8
Author: Nick Clifton <nickc@redhat.com>
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.
    
            PR 26850
            * 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.
Comment 2 Nick Clifton 2020-11-12 11:46:44 UTC
Hi Fangrui,

  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.

Cheers
  Nick