mirror of
https://github.com/systemd/systemd.git
synced 2025-02-02 13:47:27 +03:00
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:
parent
11696fbbd1
commit
09444a2e76
@ -2143,8 +2143,8 @@ if efi_arch == 'x64' and cc.links('''
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
have_pyelftools = pymod.find_installation('python3', required : false, modules : ['elftools']).found()
|
have_pyelftools = pymod.find_installation('python3', required : false, modules : ['elftools']).found()
|
||||||
if get_option('bootloader') == 'true' and (not python_39 or not have_pyelftools)
|
if get_option('bootloader') == 'true' and not have_pyelftools
|
||||||
error('EFI bootloader support requires Python >= 3.9 and pyelftools.')
|
error('EFI bootloader support requires pyelftools.')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
conf.set10(
|
conf.set10(
|
||||||
@ -2152,7 +2152,6 @@ conf.set10(
|
|||||||
get_option('efi') and
|
get_option('efi') and
|
||||||
get_option('bootloader') in ['auto', 'true'] and
|
get_option('bootloader') in ['auto', 'true'] and
|
||||||
efi_arch != '' and
|
efi_arch != '' and
|
||||||
python_39 and
|
|
||||||
have_pyelftools,
|
have_pyelftools,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ class PeRelocationBlock(LittleEndianStructure):
|
|||||||
|
|
||||||
def __init__(self, PageRVA: int):
|
def __init__(self, PageRVA: int):
|
||||||
super().__init__(PageRVA)
|
super().__init__(PageRVA)
|
||||||
self.entries: list[PeRelocationEntry] = []
|
self.entries: typing.List[PeRelocationEntry] = []
|
||||||
|
|
||||||
|
|
||||||
class PeRelocationEntry(LittleEndianStructure):
|
class PeRelocationEntry(LittleEndianStructure):
|
||||||
@ -281,7 +281,7 @@ def convert_elf_section(elf_s: ELFSection) -> PeSection:
|
|||||||
return pe_s
|
return pe_s
|
||||||
|
|
||||||
|
|
||||||
def copy_sections(elf: ELFFile, opt: PeOptionalHeader) -> list[PeSection]:
|
def copy_sections(elf: ELFFile, opt: PeOptionalHeader) -> typing.List[PeSection]:
|
||||||
sections = []
|
sections = []
|
||||||
|
|
||||||
for elf_s in elf.iter_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(
|
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
|
# fmt: off
|
||||||
[target] = [
|
[target] = [
|
||||||
@ -330,8 +330,8 @@ def convert_elf_reloc_table(
|
|||||||
elf: ELFFile,
|
elf: ELFFile,
|
||||||
elf_reloc_table: ElfRelocationTable,
|
elf_reloc_table: ElfRelocationTable,
|
||||||
image_base: int,
|
image_base: int,
|
||||||
sections: list[PeSection],
|
sections: typing.List[PeSection],
|
||||||
pe_reloc_blocks: dict[int, PeRelocationBlock],
|
pe_reloc_blocks: typing.Dict[int, PeRelocationBlock],
|
||||||
):
|
):
|
||||||
NONE_RELOC = {
|
NONE_RELOC = {
|
||||||
"EM_386": ENUM_RELOC_TYPE_i386["R_386_NONE"],
|
"EM_386": ENUM_RELOC_TYPE_i386["R_386_NONE"],
|
||||||
@ -377,7 +377,7 @@ def convert_elf_reloc_table(
|
|||||||
|
|
||||||
|
|
||||||
def convert_elf_relocations(
|
def convert_elf_relocations(
|
||||||
elf: ELFFile, opt: PeOptionalHeader, sections: list[PeSection]
|
elf: ELFFile, opt: PeOptionalHeader, sections: typing.List[PeSection]
|
||||||
) -> typing.Optional[PeSection]:
|
) -> typing.Optional[PeSection]:
|
||||||
dynamic = elf.get_section_by_name(".dynamic")
|
dynamic = elf.get_section_by_name(".dynamic")
|
||||||
if dynamic is None:
|
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"]:
|
if not flags_tag["d_val"] & ENUM_DT_FLAGS_1["DF_1_PIE"]:
|
||||||
raise RuntimeError("ELF file is not a 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():
|
for reloc_type, reloc_table in dynamic.get_relocation_tables().items():
|
||||||
if reloc_type not in ["REL", "RELA"]:
|
if reloc_type not in ["REL", "RELA"]:
|
||||||
raise RuntimeError("Unsupported relocation type {elf_reloc_type}.")
|
raise RuntimeError("Unsupported relocation type {elf_reloc_type}.")
|
||||||
@ -433,7 +433,7 @@ def convert_elf_relocations(
|
|||||||
|
|
||||||
|
|
||||||
def write_pe(
|
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.write(b"MZ")
|
||||||
file.seek(0x3C, io.SEEK_SET)
|
file.seek(0x3C, io.SEEK_SET)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user