add syminfo boundto description function
authorYann Rouillard <yann@pleiades.fr.eu.org>
Sat, 11 May 2013 17:00:45 +0000 (19:00 +0200)
committerYann Rouillard <yann@pleiades.fr.eu.org>
Sat, 11 May 2013 17:00:45 +0000 (19:00 +0200)
elftools/elf/descriptions.py
elftools/elf/enums.py
elftools/elf/structs.py
scripts/elfdump.py

index baf4205dbda583eff94a64d4827425a54dc94d7d..2fb70749d1c80aaf5770139fd5b8b766993c7a92 100644 (file)
@@ -100,6 +100,9 @@ def describe_syminfo_flags(x):
         s += _DESCR_SYMINFO_FLAGS[flag] if (x & flag) else ''
     return s
 
+def describe_symbol_boundto(x):
+    return _DESCR_SYMINFO_BOUNDTO.get(x, '%3s' % x)
+
 #-------------------------------------------------------------------------------
 _unknown = '<unknown>'
 
@@ -265,6 +268,13 @@ _DESCR_SYMINFO_FLAGS = {
     SYMINFO_FLAGS.SYMINFO_FLG_DEFERRED: 'P',
 }
 
+_DESCR_SYMINFO_BOUNDTO = dict(
+    SYMINFO_BT_SELF='<self>',
+    SYMINFO_BT_PARENT='<parent>',
+    SYMINFO_BT_NONE='',
+    SYMINFO_BT_EXTERN='<extern>',
+)
+
 _DESCR_RELOC_TYPE_i386 = dict(
         (v, k) for k, v in iteritems(ENUM_RELOC_TYPE_i386))
 
index aca085ff9b1646e8020132a5866e4459dbf90c5c..2c3028236a1a77bd9ff3ab366973b947ad1f1661 100644 (file)
@@ -447,3 +447,12 @@ ENUM_RELOC_TYPE_x64 = dict(
     _default_=Pass,
 )
 
+# Syminfo Bound To special values
+ENUM_SYMINFO_BOUNDTO = dict(
+    SYMINFO_BT_SELF=0xffff,
+    SYMINFO_BT_PARENT=0xfffe,
+    SYMINFO_BT_NONE=0xfffd,
+    SYMINFO_BT_EXTERN=0xfffc,
+    _default_=Pass,
+)
+
index 7b9365fcfb4118be3183ea77f4d9ed2ae4870ee6..93edd1305c29804fb0757153d546667efbe6756a 100644 (file)
@@ -206,6 +206,6 @@ class ELFStructs(object):
 
     def _create_syminfo(self):
         self.Elf_Syminfo = Struct('Elf_Syminfo',
-            self.Elf_half('si_boundto'),
+            Enum(self.Elf_half('si_boundto'), **ENUM_SYMINFO_BOUNDTO),
             self.Elf_half('si_flags'),
         )
index eb149dd85468615c0ce335439b30af4b784e4b8a..3eb7ffcf5010058dc01a201bfccdb4861343c33f 100755 (executable)
@@ -35,7 +35,7 @@ from elftools.elf.descriptions import (
     describe_sh_type, describe_sh_flags,
     describe_symbol_type, describe_symbol_bind, describe_symbol_visibility,
     describe_symbol_shndx, describe_reloc_type, describe_dyn_tag,
-    describe_syminfo_flags,
+    describe_syminfo_flags, describe_symbol_boundto,
     )
 from elftools.dwarf.dwarfinfo import DWARFInfo
 from elftools.dwarf.descriptions import (
@@ -95,14 +95,8 @@ class Elfdump(object):
                 index = ''
                 if syminfo['si_flags'] & SYMINFO_FLAGS.SYMINFO_FLG_CAP:
                     boundto = '<symbol capabilities>'
-                elif syminfo['si_boundto'] == 0xffff:
-                    boundto = '<self>'
-                elif syminfo['si_boundto'] == 0xfffe:
-                    boundto = '<parent>'
-                elif syminfo['si_boundto'] == 0xfffc:
-                    boundto = '<extern>'
-                elif syminfo['si_boundto'] == 0xfffd:
-                    boundto = ''
+                elif not isinstance(syminfo['si_boundto'], int):
+                    boundto = describe_symbol_boundto(syminfo['si_boundto'])
                 else:
                     dyn_tag = dyntable.get_tag(syminfo['si_boundto'])
                     if syminfo['si_flags'] & SYMINFO_FLAGS.SYMINFO_FLG_FILTER: