From 6c06168e7212616ea08460d487a4b99e89a34108 Mon Sep 17 00:00:00 2001 From: cadmic Date: Sun, 2 Feb 2025 22:42:31 -0800 Subject: [PATCH] fix_bss.py: Gracefully handle EGCS-compiled files (#2452) --- tools/fix_bss.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/fix_bss.py b/tools/fix_bss.py index 05cf4293a2..2a775765af 100755 --- a/tools/fix_bss.py +++ b/tools/fix_bss.py @@ -91,6 +91,11 @@ def read_relocs(object_path: Path, section_name: str) -> list[Reloc]: with open(object_path, "rb") as f: elffile = elftools.elf.elffile.ELFFile(f) symtab = elffile.get_section_by_name(".symtab") + + section = elffile.get_section_by_name(section_name) + if section is None: + return [] + data = elffile.get_section_by_name(section_name).data() reloc_section = elffile.get_section_by_name(f".rel{section_name}") @@ -698,6 +703,12 @@ def process_file( raise FixBssException(f"Could not determine compiler command line for {file}") output(f"Compiler command: {shlex.join(command_line)}") + + if any(s.startswith("tools/egcs/") for s in command_line): + raise FixBssException( + "Can't automatically fix BSS ordering for EGCS-compiled files" + ) + symbol_table, ucode = run_cfe(command_line, keep_files=False) bss_variables = find_bss_variables(symbol_table, ucode)