add support for solaris .SUNW_ldynsym section
authorYann Rouillard <yann@pleiades.fr.eu.org>
Wed, 19 Jun 2013 23:48:38 +0000 (01:48 +0200)
committerYann Rouillard <yann@pleiades.fr.eu.org>
Wed, 19 Jun 2013 23:48:38 +0000 (01:48 +0200)
elftools/elf/elffile.py
elftools/elf/enums.py
test/test_solaris_support.py

index 458273f2c1e25a3a45f98dcd404fe4e6bb32d3c8..58b54595b99ce5ce0086e0c60fc46a0565a295e6 100644 (file)
@@ -249,7 +249,7 @@ class ELFFile(object):
             return StringTableSection(section_header, name, self.stream)
         elif sectype == 'SHT_NULL':
             return NullSection(section_header, name, self.stream)
-        elif sectype in ('SHT_SYMTAB', 'SHT_DYNSYM'):
+        elif sectype in ('SHT_SYMTAB', 'SHT_DYNSYM', 'SHT_SUNW_LDYNSYM'):
             return self._make_symbol_table_section(section_header, name)
         elif sectype == 'SHT_SUNW_syminfo':
             return self._make_sunwsyminfo_table_section(section_header, name)
index deb9f35d9d32716308595679784d2c0eb7b601f7..3058083261bdd914f872a33fda400c27f2b54ae4 100644 (file)
@@ -194,6 +194,7 @@ ENUM_SH_TYPE = dict(
     SHT_LOUSER=0x80000000,
     SHT_HIUSER=0xffffffff,
     SHT_AMD64_UNWIND=0x70000001,
+    SHT_SUNW_LDYNSYM=0x6ffffff3,
     SHT_SUNW_syminfo=0x6ffffffc,
     SHT_ARM_EXIDX=0x70000001,
     SHT_ARM_PREEMPTMAP=0x70000002,
index 9f64efdce2884f80a78d53545d7220ba5ad925ad..4462c8127fe88677cd47b91ebbd8c1f62b92fa8a 100644 (file)
@@ -9,6 +9,7 @@ try:
 except ImportError:
     import unittest
 import os
+import copy
 
 from utils import setup_syspath; setup_syspath()
 from elftools.elf.elffile import ELFFile
@@ -52,5 +53,35 @@ class TestSolarisSupport(unittest.TestCase):
     def test_SUNW_syminfo_section_sparc64(self):
         self._test_SUNW_syminfo_section_generic('exe_solaris64_cc.elf.sparc')
 
+    ldsynsym_reference_data = [b'', b'exe_solaris32.elf', b'crti.s', b'crt1.o',
+                               b'crt1.s', b'fsr.s', b'values-Xa.c',
+                               b'exe_solaris64.elf.c', b'crtn.s']
+
+    def _test_SUNW_ldynsym_section_generic(self, testfile, reference_data):
+        with open(os.path.join('test', 'testfiles_for_unittests',
+                               testfile), 'rb') as f:
+            elf = ELFFile(f)
+            ldynsym_section = elf.get_section_by_name(b'.SUNW_ldynsym')
+            self.assertIsNotNone(ldynsym_section)
+
+            for symbol, ref_symbol_name in zip(
+                    ldynsym_section.iter_symbols(), reference_data):
+
+                self.assertEqual(symbol.name, ref_symbol_name)
+
+    def test_SUNW_ldynsym_section_x86(self):
+        reference_data = TestSolarisSupport.ldsynsym_reference_data
+        self._test_SUNW_ldynsym_section_generic('exe_solaris32_cc.elf',
+                                                reference_data)
+
+    def test_SUNW_ldynsym_section_x64(self):
+        reference_data = copy.deepcopy(
+            TestSolarisSupport.ldsynsym_reference_data)
+        reference_data[1] = b'exe_solaris64.elf'
+        reference_data[3] = b'crt1x.o'
+        reference_data[5] = b'fsrx.s'
+        self._test_SUNW_ldynsym_section_generic('exe_solaris64_cc.elf',
+                                                reference_data)
+
 if __name__ == '__main__':
     unittest.main()