elf2efi: Make compatible with python 3.6 again

CentOS 8 ships python 3.6 so let's try and stay compatible with that
since the only feature we're using that requires python 3.9 is the
streamlined type annotations which are trivial to convert back to
the older stuff to stay compatible with python 3.6.
This commit is contained in:
Daan De Meyer 2023-07-14 14:16:44 +02:00
parent 11696fbbd1
commit 09444a2e76
2 changed files with 10 additions and 11 deletions

View file

@ -2143,8 +2143,8 @@ if efi_arch == 'x64' and cc.links('''
endif
have_pyelftools = pymod.find_installation('python3', required : false, modules : ['elftools']).found()
if get_option('bootloader') == 'true' and (not python_39 or not have_pyelftools)
error('EFI bootloader support requires Python >= 3.9 and pyelftools.')
if get_option('bootloader') == 'true' and not have_pyelftools
error('EFI bootloader support requires pyelftools.')
endif
conf.set10(
@ -2152,7 +2152,6 @@ conf.set10(
get_option('efi') and
get_option('bootloader') in ['auto', 'true'] and
efi_arch != '' and
python_39 and
have_pyelftools,
)

View file

@ -80,7 +80,7 @@ class PeRelocationBlock(LittleEndianStructure):
def __init__(self, PageRVA: int):
super().__init__(PageRVA)
self.entries: list[PeRelocationEntry] = []
self.entries: typing.List[PeRelocationEntry] = []
class PeRelocationEntry(LittleEndianStructure):
@ -281,7 +281,7 @@ def convert_elf_section(elf_s: ELFSection) -> PeSection:
return pe_s
def copy_sections(elf: ELFFile, opt: PeOptionalHeader) -> list[PeSection]:
def copy_sections(elf: ELFFile, opt: PeOptionalHeader) -> typing.List[PeSection]:
sections = []
for elf_s in elf.iter_sections():
@ -304,7 +304,7 @@ def copy_sections(elf: ELFFile, opt: PeOptionalHeader) -> list[PeSection]:
def apply_elf_relative_relocation(
reloc: ElfRelocation, image_base: int, sections: list[PeSection], addend_size: int
reloc: ElfRelocation, image_base: int, sections: typing.List[PeSection], addend_size: int
):
# fmt: off
[target] = [
@ -330,8 +330,8 @@ def convert_elf_reloc_table(
elf: ELFFile,
elf_reloc_table: ElfRelocationTable,
image_base: int,
sections: list[PeSection],
pe_reloc_blocks: dict[int, PeRelocationBlock],
sections: typing.List[PeSection],
pe_reloc_blocks: typing.Dict[int, PeRelocationBlock],
):
NONE_RELOC = {
"EM_386": ENUM_RELOC_TYPE_i386["R_386_NONE"],
@ -377,7 +377,7 @@ def convert_elf_reloc_table(
def convert_elf_relocations(
elf: ELFFile, opt: PeOptionalHeader, sections: list[PeSection]
elf: ELFFile, opt: PeOptionalHeader, sections: typing.List[PeSection]
) -> typing.Optional[PeSection]:
dynamic = elf.get_section_by_name(".dynamic")
if dynamic is None:
@ -387,7 +387,7 @@ def convert_elf_relocations(
if not flags_tag["d_val"] & ENUM_DT_FLAGS_1["DF_1_PIE"]:
raise RuntimeError("ELF file is not a PIE.")
pe_reloc_blocks: dict[int, PeRelocationBlock] = {}
pe_reloc_blocks: typing.Dict[int, PeRelocationBlock] = {}
for reloc_type, reloc_table in dynamic.get_relocation_tables().items():
if reloc_type not in ["REL", "RELA"]:
raise RuntimeError("Unsupported relocation type {elf_reloc_type}.")
@ -433,7 +433,7 @@ def convert_elf_relocations(
def write_pe(
file, coff: PeCoffHeader, opt: PeOptionalHeader, sections: list[PeSection]
file, coff: PeCoffHeader, opt: PeOptionalHeader, sections: typing.List[PeSection]
):
file.write(b"MZ")
file.seek(0x3C, io.SEEK_SET)