NULL termination with IAR Embedded Workbench compiler (#146)
authorgerthmar <gerth@hallihallo.ch>
Thu, 15 Jun 2017 13:51:32 +0000 (15:51 +0200)
committerEli Bendersky <eliben@users.noreply.github.com>
Thu, 15 Jun 2017 13:51:32 +0000 (06:51 -0700)
* Exectued changes for IAR Embedded Workbench output .elf File

* applied review findings

elftools/dwarf/die.py [changed mode: 0644->0755]
elftools/dwarf/structs.py

old mode 100644 (file)
new mode 100755 (executable)
index 1b42066..2c04362
@@ -192,6 +192,19 @@ class DIE(object):
                 raw_value=raw_value,
                 offset=attr_offset)
 
+        # count and then consume any null termination bytes to avoid wrong die size calculation
+        zero_term = 0
+        with preserve_stream_pos(self.stream):
+            while True:
+                b = self.stream.read(1)
+                if b == 0:
+                    zero_term += 1
+                else:
+                    break
+        if zero_term > 0:
+            # there was at least one zero termination -> consume all of them
+            self.stream.read(zero_term)
+
         self.size = self.stream.tell() - self.offset
 
     def _translate_attr_value(self, form, raw_value):
index 562cccdcbe0504c183ac76a492e167baa3238603..b21bd931d5175047a0cb6e1a96946804f1dfd21e 100644 (file)
@@ -203,7 +203,7 @@ class DWARFStructs(object):
             DW_FORM_flag_present = StaticField('', 0),
             DW_FORM_sec_offset = self.Dwarf_offset(''),
             DW_FORM_exprloc = self._make_block_struct(self.Dwarf_uleb128),
-            DW_FORM_ref_sig8 = self.Dwarf_offset(''),
+            DW_FORM_ref_sig8 = self.Dwarf_uint64(''),
 
             DW_FORM_GNU_strp_alt=self.Dwarf_offset(''),
             DW_FORM_GNU_ref_alt=self.Dwarf_offset(''),