Page MenuHomeFreeBSD

libdwarf: Hide SHT_NOBITS sections.
ClosedPublic

Authored by markj on Jul 11 2020, 6:45 PM.

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

Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 32253
Build 29743: arc lint + arc unit

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.