]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
elf2efi: Make compatible with python 3.6 again
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 14 Jul 2023 12:16:44 +0000 (14:16 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 14 Jul 2023 12:41:19 +0000 (14:41 +0200)
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.

meson.build
tools/elf2efi.py

index f8af69911b92fec70c2f5e6df91404b116644e32..395eca1943c1841d1fac7f0441c87bc274607730 100644 (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,
 )
 
index 20d25321c4dc5a8bfc89116b0592f591695c5d9a..e233c8e3abaf6fbd812a8454fbf903f2bf5da7af 100755 (executable)
@@ -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)