From ea1f7fd627a2734414392fdefb2a656919544566 Mon Sep 17 00:00:00 2001 From: Yann Rouillard Date: Thu, 20 Jun 2013 01:48:38 +0200 Subject: [PATCH] add support for solaris .SUNW_ldynsym section --- elftools/elf/elffile.py | 2 +- elftools/elf/enums.py | 1 + test/test_solaris_support.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/elftools/elf/elffile.py b/elftools/elf/elffile.py index 458273f..58b5459 100644 --- a/elftools/elf/elffile.py +++ b/elftools/elf/elffile.py @@ -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) diff --git a/elftools/elf/enums.py b/elftools/elf/enums.py index deb9f35..3058083 100644 --- a/elftools/elf/enums.py +++ b/elftools/elf/enums.py @@ -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, diff --git a/test/test_solaris_support.py b/test/test_solaris_support.py index 9f64efd..4462c81 100644 --- a/test/test_solaris_support.py +++ b/test/test_solaris_support.py @@ -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() -- 2.30.2