1 #-------------------------------------------------------------------------------
4 # Yann Rouillard (yann@pleiades.fr.eu.org)
5 # This code is in the public domain
6 #-------------------------------------------------------------------------------
8 import unittest2
as unittest
14 from utils
import setup_syspath
; setup_syspath()
15 from elftools
.elf
.elffile
import ELFFile
16 from elftools
.elf
.constants
import SUNW_SYMINFO_FLAGS
19 class TestSolarisSupport(unittest
.TestCase
):
21 def _test_SUNW_syminfo_section_generic(self
, testfile
):
22 with
open(os
.path
.join('test', 'testfiles_for_unittests',
23 testfile
), 'rb') as f
:
25 syminfo_section
= elf
.get_section_by_name('.SUNW_syminfo')
26 self
.assertIsNotNone(syminfo_section
)
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()
35 self
.assertNotEqual(len(exit_symbols
), 0)
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
)
44 def test_SUNW_syminfo_section_x86(self
):
45 self
._test
_SUNW
_syminfo
_section
_generic
('exe_solaris32_cc.elf')
47 def test_SUNW_syminfo_section_x64(self
):
48 self
._test
_SUNW
_syminfo
_section
_generic
('exe_solaris64_cc.elf')
50 def test_SUNW_syminfo_section_sparc32(self
):
51 self
._test
_SUNW
_syminfo
_section
_generic
('exe_solaris32_cc.sparc.elf')
53 def test_SUNW_syminfo_section_sparc64(self
):
54 self
._test
_SUNW
_syminfo
_section
_generic
('exe_solaris64_cc.sparc.elf')
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']
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
:
64 ldynsym_section
= elf
.get_section_by_name('.SUNW_ldynsym')
65 self
.assertIsNotNone(ldynsym_section
)
67 for symbol
, ref_symbol_name
in zip(
68 ldynsym_section
.iter_symbols(), reference_data
):
70 self
.assertEqual(symbol
.name
, ref_symbol_name
)
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',
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',
86 if __name__
== '__main__':