354c3a72138ee9041c204bfca281b0bf7fd7d639
1 #-------------------------------------------------------------------------------
4 # Test 'R_ARM_CALL' relocation type support.
5 # Compare the '.text' section data of ELF file that was relocated by elftools
6 # with an ELF file that was relocated by linker.
8 # Dmitry Koltunov (koltunov@ispras.ru)
9 # This code is in the public domain
10 #-------------------------------------------------------------------------------
15 from elftools
.common
.py3compat
import BytesIO
16 from elftools
.elf
.elffile
import ELFFile
17 from elftools
.elf
.relocation
import RelocationHandler
20 def do_relocation(rel_elf
):
21 data
= rel_elf
.get_section_by_name('.text').data()
22 rh
= RelocationHandler(rel_elf
)
27 rel
= rel_elf
.get_section_by_name('.rel.text')
28 rh
.apply_section_relocations(stream
, rel
)
29 return stream
.getvalue()
32 class TestARMRElocation(unittest
.TestCase
):
34 test_dir
= os
.path
.join('test', 'testfiles_for_unittests')
35 with
open(os
.path
.join(test_dir
, 'arm_reloc_unrelocated.o'), 'rb') as rel_f
, \
36 open(os
.path
.join(test_dir
, 'arm_reloc_relocated.elf'), 'rb') as f
:
37 rel_elf
= ELFFile(rel_f
)
40 # Comparison of '.text' section data
41 self
.assertEquals(do_relocation(rel_elf
),
42 elf
.get_section_by_name('.text').data())
44 if __name__
== '__main__':