Allow for multiple code sections when finding glue

This commit is contained in:
Elliot Nunn 2019-10-04 11:23:42 +08:00
parent 491e85d8a8
commit 610ec9c8d9

View File

@ -251,7 +251,7 @@ def repr(obj):
return accum
elif isinstance(obj, dict):
if set(obj) in (set(('kind', 'weakFlag', 'name')), set(('section', 'offset', 'to'))):
if set(obj) in (set(('kind', 'weakFlag', 'name')), set(('section', 'offset', 'to')), set(('file', 'offset', 'function'))):
oneline = True
else:
oneline = False
@ -549,7 +549,14 @@ def dump_locations(from_path, to_path):
"""Create some useful files: glue.txt
"""
with open(path.join(from_path, 'code'), 'rb') as f: code = f.read()
with open(path.join(from_path, 'sections.txt')) as f: section_list = eval(f.read())
gluelocs = []
for idx, sec in enumerate(section_list):
if sec['sectionKind'] != 'code': continue
with open(path.join(from_path, sec['filename']), 'rb') as f: code = f.read()
gluescan = []
for i in range(0, len(code) - 24, 4):
@ -566,19 +573,17 @@ def dump_locations(from_path, to_path):
toc_vectors = {}
for rel in relocs:
if rel['section'] == 1 and rel['to'][0] == 'import':
if 'data' in section_list[rel['section']]['sectionKind'] and rel['to'][0] == 'import':
toc_vectors[rel['offset']] = imports[rel['to'][1]]
gluelocs = []
for code_ofs, toc_ofs in gluescan:
try:
gluelocs.append((code_ofs, toc_vectors[toc_ofs]))
gluelocs.append(dict(file=sec['filename'], offset=code_ofs, function=toc_vectors[toc_ofs]))
except KeyError:
pass
gluelocs.sort()
# Okay, let's do a nasty cross-referencing job!
gluelocs.sort(key=lambda dct: tuple(dct.values()))
to_path = path.join(to_path, 'locations')
os.makedirs(to_path, exist_ok=True)