From: Eli Bendersky Date: Thu, 24 Nov 2011 06:12:37 +0000 (+0200) Subject: it's alive, ALIVEhg sthg st! DWARF relocations seem to be working fine X-Git-Tag: v0.10~70 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=149315a4e5573d96fd43a0cca0c89c9adcfebdf1;p=pyelftools.git it's alive, ALIVEhg sthg st! DWARF relocations seem to be working fine --- diff --git a/elftools/dwarf/compileunit.py b/elftools/dwarf/compileunit.py index fda4980..fbe4a8b 100644 --- a/elftools/dwarf/compileunit.py +++ b/elftools/dwarf/compileunit.py @@ -113,7 +113,10 @@ class CompileUnit(object): # First pass: parse all DIEs and place them into self._dielist die_offset = self.cu_die_offset while die_offset < cu_boundary: - die = DIE(cu=self, stream=self.dwarfinfo.stream, offset=die_offset) + die = DIE( + cu=self, + stream=self.dwarfinfo.debug_info_sec.stream, + offset=die_offset) self._dielist.append(die) die_offset += die.size diff --git a/elftools/dwarf/descriptions.py b/elftools/dwarf/descriptions.py index 6676827..037aa7e 100644 --- a/elftools/dwarf/descriptions.py +++ b/elftools/dwarf/descriptions.py @@ -35,7 +35,7 @@ def describe_attr_value(attr, die, section_offset): #------------------------------------------------------------------------------- def _describe_attr_ref(attr, die, section_offset): - return '<0x%x>' % (attr.value + die.cu.cu_offset - section_offset) + return '<0x%x>' % (attr.value + die.cu.cu_offset) def _describe_attr_value_passthrough(attr, die, section_offset): return attr.value diff --git a/elftools/dwarf/die.py b/elftools/dwarf/die.py index f438934..82d65e9 100644 --- a/elftools/dwarf/die.py +++ b/elftools/dwarf/die.py @@ -162,12 +162,7 @@ class DIE(object): # The offset of the .debug_info section in the stream. Used to compute # relative offset of attribute values to the beginning of the section. - section_offset = self.dwarfinfo.debug_info_loc.offset - - # Some attribute values need relocations. These are computed with the - # help of a DWARFRelocationManager for .debug_info, which is held by - # DWARFInfo for this purpose. - relocation_manager = self.dwarfinfo.relocation_manager['.debug_info'] + section_offset = self.dwarfinfo.debug_info_sec.global_offset # Guided by the attributes listed in the abbreviation declaration, parse # values from the stream. @@ -176,18 +171,6 @@ class DIE(object): attr_offset = self.stream.tell() raw_value = struct_parse(structs.Dwarf_dw_form[form], self.stream) - # raw_value may need to be relocated, if there's a relocation - # registered for this offset in the relocation manager. - # Relocations are listed by offset relative to the beginning of - # the section. - offset_from_section = attr_offset - section_offset - if relocation_manager.has_relocation(offset_from_section): - # Applying the relocation may change the stream, so preserve it - with preserve_stream_pos(self.stream): - raw_value = relocation_manager.apply_relocation( - offset=offset_from_section, - value=raw_value) - value = self._translate_attr_value(form, raw_value) self.attributes[name] = AttributeValue( name=name, diff --git a/elftools/dwarf/dwarfinfo.py b/elftools/dwarf/dwarfinfo.py index 3a66871..bfbba8d 100644 --- a/elftools/dwarf/dwarfinfo.py +++ b/elftools/dwarf/dwarfinfo.py @@ -107,7 +107,7 @@ class DWARFInfo(object): if offset not in self._abbrevtable_cache: self._abbrevtable_cache[offset] = AbbrevTable( structs=self.structs, - stream=self.stream, + stream=self.debug_abbrev_sec.stream, offset=offset) return self._abbrevtable_cache[offset] @@ -117,7 +117,7 @@ class DWARFInfo(object): """ return struct_parse( CString(''), - self.stream, + self.debug_str_sec.stream, stream_pos=offset) #------ PRIVATE ------# @@ -138,7 +138,7 @@ class DWARFInfo(object): # instance suitable for this CU and use it to parse the rest. # initial_length = struct_parse( - self.structs.Dwarf_uint32(''), self.stream, offset) + self.structs.Dwarf_uint32(''), self.debug_info_sec.stream, offset) dwarf_format = 64 if initial_length == 0xFFFFFFFF else 32 # At this point we still haven't read the whole header, so we don't @@ -153,14 +153,14 @@ class DWARFInfo(object): address_size=4) cu_header = struct_parse( - cu_structs.Dwarf_CU_header, self.stream, offset) + cu_structs.Dwarf_CU_header, self.debug_info_sec.stream, offset) if cu_header['address_size'] == 8: cu_structs = DWARFStructs( little_endian=self.little_endian, dwarf_format=dwarf_format, address_size=8) - cu_die_offset = self.stream.tell() + cu_die_offset = self.debug_info_sec.stream.tell() dwarf_assert( self._is_supported_version(cu_header['version']), "Expected supported DWARF version. Got '%s'" % cu_header['version']) diff --git a/scripts/readelf.py b/scripts/readelf.py index 85b8f0b..2de7cb6 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -24,7 +24,8 @@ from elftools import __version__ from elftools.common.exceptions import ELFError from elftools.elf.elffile import ELFFile from elftools.elf.segments import InterpSegment -from elftools.elf.sections import SymbolTableSection, RelocationSection +from elftools.elf.sections import SymbolTableSection +from elftools.elf.relocation import RelocationSection from elftools.elf.descriptions import ( describe_ei_class, describe_ei_data, describe_ei_version, describe_ei_osabi, describe_e_type, describe_e_machine, @@ -33,7 +34,7 @@ from elftools.elf.descriptions import ( describe_symbol_type, describe_symbol_bind, describe_symbol_visibility, describe_symbol_shndx, describe_reloc_type, ) -from elftools.dwarf.dwarfinfo import DWARFInfo, DebugSectionLocator +from elftools.dwarf.dwarfinfo import DWARFInfo from elftools.dwarf.descriptions import describe_attr_value @@ -496,13 +497,11 @@ class ReadElf(object): self._emitline('Contents of the .debug_info section:\n') # Offset of the .debug_info section in the stream - section_offset = self._dwarfinfo.debug_info_loc.offset + section_offset = self._dwarfinfo.debug_info_sec.global_offset - print '&&& section_offset', section_offset - for cu in self._dwarfinfo.iter_CUs(): self._emitline(' Compilation Unit @ offset %s:' % - self._format_hex(cu.cu_offset - section_offset)) + self._format_hex(cu.cu_offset)) self._emitline(' Length: %s (%s)' % ( self._format_hex(cu['unit_length']), '%s-bit' % cu.dwarf_format())) @@ -523,13 +522,13 @@ class ReadElf(object): continue self._emitline(' <%s><%x>: Abbrev Number: %s (%s)' % ( die_depth, - die.offset - section_offset, + die.offset, die.abbrev_code, die.tag)) for attr in die.attributes.itervalues(): self._emitline(' <%2x> %-18s: %s' % ( - attr.offset - section_offset, + attr.offset, attr.name, describe_attr_value( attr, die, section_offset))) diff --git a/z.py b/z.py index b0cdfb2..865d75b 100644 --- a/z.py +++ b/z.py @@ -31,8 +31,4 @@ topdie = cu.get_top_DIE() print topdie dinfo_sec = efile.get_section_by_name('.debug_info') -relman = DWARFRelocationManager(efile, dinfo_sec.name) - -print relman._reloc_section.name, relman._reloc_section['sh_offset'] -#pprint.pprint(relman._relocs)