From 96a8bb104e0acd14940331a4dd069b1f3905296c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Wed, 11 Nov 2020 13:54:01 +0100 Subject: [PATCH] tools: Read entire ELF ahead of time to reduce seek/read overhead --- tools/util/elf.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/util/elf.py b/tools/util/elf.py index 76d90e38..aff99a0b 100644 --- a/tools/util/elf.py +++ b/tools/util/elf.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from typing import Any, Dict, NamedTuple +import io from elftools.elf.elffile import ELFFile @@ -12,8 +13,11 @@ diff_settings.apply(_config, {}) _root = utils.get_repo_root() -base_elf = ELFFile((_root / _config["baseimg"]).open("rb")) -my_elf = ELFFile((_root / _config["myimg"]).open("rb")) +base_elf_data = io.BytesIO((_root / _config["baseimg"]).read_bytes()) +my_elf_data = io.BytesIO((_root / _config["myimg"]).read_bytes()) + +base_elf = ELFFile(base_elf_data) +my_elf = ELFFile(my_elf_data) my_symtab = my_elf.get_section_by_name(".symtab") if not my_symtab: utils.fail(f'{_config["myimg"]} has no symbol table')