from ..construct import ConstructError
from .structs import ELFStructs
from .sections import (
- Section, StringTableSection, SymbolTableSection, NullSection)
+ Section, StringTableSection, SymbolTableSection, NullSection,
+ RelocationSection)
from .segments import Segment, InterpSegment
return NullSection(section_header, name, self.stream)
elif sectype in ('SHT_SYMTAB', 'SHT_DYNSYM'):
return self._make_symbol_table_section(section_header, name)
+ elif sectype in ('SHT_REL', 'SHT_RELA'):
+ return RelocationSection(
+ section_header, name, self.stream, self.structs)
else:
return Section(section_header, name, self.stream)
yield self.get_symbol(i)
+class RelocationSection(Section):
+ def __init__(self, header, name, stream, elfstructs):
+ super(RelocationSection, self).__init__(header, name, stream)
+ self.elfstructs = elfstructs
+ if self.header['sh_type'] == 'SHT_REL':
+ expected_size = self.elfstructs.Elf_Rel.sizeof()
+ elif self.header['sh_type'] == 'SHT_RELA':
+ expected_size = self.elfstructs.Elf_Rela.sizeof()
+ else:
+ elf_assert(False, 'Unknown relocation type section')
+
+ elf_assert(
+ self.header['sh_entsize'] == expected_size,
+ 'Expected sh_entsize of SHT_REL section to be %s' % expected_size)
+
+
class Symbol(object):
""" Symbol object - representing a single symbol entry from a symbol table
section.
Elf_Sym:
Symbol table entry
+
+ Elf_Rel, Elf_Rela:
+ Entries in relocation sections
"""
def __init__(self, little_endian=True, elfclass=32):
assert elfclass == 32 or elfclass == 64
self._create_phdr()
self._create_shdr()
self._create_sym()
+ self._create_rel()
def _create_ehdr(self):
self.Elf_Ehdr = Struct('Elf_Ehdr',
self.Elf_word('p_flags'),
self.Elf_word('p_align'),
)
- else:
+ else: # 64
self.Elf_Phdr = Struct('Elf_Phdr',
Enum(self.Elf_word('p_type'), **ENUM_P_TYPE),
self.Elf_word('p_flags'),
self.Elf_xword('sh_entsize'),
)
+ def _create_rel(self):
+ # r_info is hierarchical. To access the type, use
+ # container['r_info']['type']
+ if self.elfclass == 32:
+ r_info_struct = BitStruct('r_info',
+ BitField('sym', 24),
+ BitField('type', 8))
+ else: # 64
+ r_info_struct = BitStruct('r_info',
+ BitField('sym', 32),
+ Padding(24),
+ BitField('type', 8))
+
+ self.Elf_Rel = Struct('Elf_Rel',
+ self.Elf_addr('r_offset'),
+ r_info_struct,
+ )
+ self.Elf_Rela = Struct('Elf_Rela',
+ self.Elf_addr('r_offset'),
+ r_info_struct,
+ self.Elf_sxword('r_addend'),
+ )
+
def _create_sym(self):
# st_info is hierarchical. To access the type, use
# container['st_info']['type']
rc, stdout = run_exe(exe_path, args)
if rc != 0:
testlog.error("@@ aborting - '%s' returned '%s'" % (exe_path, rc))
- break
+ return False
stdouts.append(stdout)
testlog.info('....comparing output...')
success, errmsg = compare_output(*stdouts)