Merge pull request #76 from JaySon-Huang/strings
[pyelftools.git] / test / test_solaris_support.py
1 #-------------------------------------------------------------------------------
2 # elftools tests
3 #
4 # Yann Rouillard (yann@pleiades.fr.eu.org)
5 # This code is in the public domain
6 #-------------------------------------------------------------------------------
7 try:
8 import unittest2 as unittest
9 except ImportError:
10 import unittest
11 import os
12 import copy
13
14 from utils import setup_syspath; setup_syspath()
15 from elftools.elf.elffile import ELFFile
16 from elftools.elf.constants import SUNW_SYMINFO_FLAGS
17
18
19 class TestSolarisSupport(unittest.TestCase):
20
21 def _test_SUNW_syminfo_section_generic(self, testfile):
22 with open(os.path.join('test', 'testfiles_for_unittests',
23 testfile), 'rb') as f:
24 elf = ELFFile(f)
25 syminfo_section = elf.get_section_by_name('.SUNW_syminfo')
26 self.assertIsNotNone(syminfo_section)
27
28 # The test files were compiled against libc.so.1 with
29 # direct binding, hence the libc symbols used
30 # (exit, atexit and _exit) have the direct binding flags
31 # in the syminfo table.
32 # We check that this is properly detected.
33 exit_symbols = [s for s in syminfo_section.iter_symbols()
34 if 'exit' in s.name]
35 self.assertNotEqual(len(exit_symbols), 0)
36
37 for symbol in exit_symbols:
38 # libc.so.1 has the index 0 in the dynamic table
39 self.assertEqual(symbol['si_boundto'], 0)
40 self.assertEqual(symbol['si_flags'],
41 SUNW_SYMINFO_FLAGS.SYMINFO_FLG_DIRECT |
42 SUNW_SYMINFO_FLAGS.SYMINFO_FLG_DIRECTBIND)
43
44 def test_SUNW_syminfo_section_x86(self):
45 self._test_SUNW_syminfo_section_generic('exe_solaris32_cc.elf')
46
47 def test_SUNW_syminfo_section_x64(self):
48 self._test_SUNW_syminfo_section_generic('exe_solaris64_cc.elf')
49
50 def test_SUNW_syminfo_section_sparc32(self):
51 self._test_SUNW_syminfo_section_generic('exe_solaris32_cc.sparc.elf')
52
53 def test_SUNW_syminfo_section_sparc64(self):
54 self._test_SUNW_syminfo_section_generic('exe_solaris64_cc.sparc.elf')
55
56 ldsynsym_reference_data = ['', 'exe_solaris32.elf', 'crti.s', 'crt1.o',
57 'crt1.s', 'fsr.s', 'values-Xa.c',
58 'exe_solaris64.elf.c', 'crtn.s']
59
60 def _test_SUNW_ldynsym_section_generic(self, testfile, reference_data):
61 with open(os.path.join('test', 'testfiles_for_unittests',
62 testfile), 'rb') as f:
63 elf = ELFFile(f)
64 ldynsym_section = elf.get_section_by_name('.SUNW_ldynsym')
65 self.assertIsNotNone(ldynsym_section)
66
67 for symbol, ref_symbol_name in zip(
68 ldynsym_section.iter_symbols(), reference_data):
69
70 self.assertEqual(symbol.name, ref_symbol_name)
71
72 def test_SUNW_ldynsym_section_x86(self):
73 reference_data = TestSolarisSupport.ldsynsym_reference_data
74 self._test_SUNW_ldynsym_section_generic('exe_solaris32_cc.elf',
75 reference_data)
76
77 def test_SUNW_ldynsym_section_x64(self):
78 reference_data = copy.deepcopy(
79 TestSolarisSupport.ldsynsym_reference_data)
80 reference_data[1] = 'exe_solaris64.elf'
81 reference_data[3] = 'crt1x.o'
82 reference_data[5] = 'fsrx.s'
83 self._test_SUNW_ldynsym_section_generic('exe_solaris64_cc.elf',
84 reference_data)
85
86 if __name__ == '__main__':
87 unittest.main()