Page MenuHomeFreeBSD

libdwarf: Hide SHT_NOBITS sections.
ClosedPublic

Authored by markj on Jul 11 2020, 6:45 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 7, 10:39 AM
Unknown Object (File)
Tue, Nov 5, 3:02 AM
Unknown Object (File)
Fri, Nov 1, 11:09 AM
Unknown Object (File)
Sun, Oct 27, 3:01 AM
Unknown Object (File)
Oct 23 2024, 11:56 AM
Unknown Object (File)
Oct 21 2024, 9:00 AM
Unknown Object (File)
Oct 16 2024, 8:58 AM
Unknown Object (File)
Oct 1 2024, 7:53 AM
Subscribers

Details

Summary

gnu_debuglink external debug files will contain an .eh_frame section
with type SHT_NOBITS. libdwarf does not handle such sections (or
rather, it expects all debug sections to not have type SHT_NOBITS).
Modify _dwarf_find_section() to hide SHT_NOBITS sections from consumers;
this is basically what SGI libdwarf does.

Diagnosed by: Paco Pascal

Test Plan

readelf -wf <file> would always crash on an external debug file. Now we
get:

> readelf -wf /usr/lib/debug/bin/cat.debug        
                                       
The section .eh_frame contains:
                                       
readelf: dwarf_get_fde_list_eh failed: No entry found [dwarf_get_fde_list_eh(92)]
                                       
The section .debug_frame contains:                                             
                                                                               
00000000 00000014 ffffffff CIE      
  Version:                      4   
  Augmentation:                 ""  
  Code alignment factor:        1   
  Data alignment factor:        -8    
  Return address column:        16 
                                       
  DW_CFA_def_cfa: r7 (rsp) ofs 8                                               
  DW_CFA_offset: r16 (rip) at cfa-8
  DW_CFA_nop               
  DW_CFA_nop                           
  DW_CFA_nop                                                                   
  DW_CFA_nop                                                                   

...

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Jul 11 2020, 6:45 PM
markj created this revision.
markj edited the test plan for this revision. (Show Details)

To elaborate a bit more, elf_getdata() will return a NULL data buffer for a section of type NOBITS. I looked through _dwarf_find_section() callers and they all appear to expect to be able to dereference ds->ds_data when ds->ds_size > 0. Another solution might be to skip NOBITS sections in _dwarf_elf_init().

This revision is now accepted and ready to land.Jul 16 2020, 3:54 PM

Avoid loading NOBITS sections in the first place.

This revision now requires review to proceed.Jul 20 2020, 6:00 PM

Another solution might be to skip NOBITS sections in _dwarf_elf_init().

I ended up going this way instead, I think it is closer to SGI libdwarf's logic.

This revision was not accepted when it landed; it landed in state Needs Review.Jul 20 2020, 6:23 PM
This revision was automatically updated to reflect the committed changes.