]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
elf2efi: add parameter to increase reserved space for headers
authorLuca Boccassi <bluca@debian.org>
Tue, 23 May 2023 00:43:59 +0000 (01:43 +0100)
committerLuca Boccassi <bluca@debian.org>
Wed, 24 May 2023 10:06:36 +0000 (11:06 +0100)
When building a minimal empty addon it would not have enough
space to append sections. Add an option that will later be
used to reserve enough space.

tools/elf2efi.py

index 6179ba821327f13a4db33ff7cf5a963b66d58b9e..20d25321c4dc5a8bfc89116b0592f591695c5d9a 100755 (executable)
@@ -512,10 +512,11 @@ def elf2efi(args: argparse.Namespace):
     opt.SizeOfImage = align_to(
         sections[-1].VirtualAddress + sections[-1].VirtualSize, SECTION_ALIGNMENT
     )
+
     opt.SizeOfHeaders = align_to(
         PE_OFFSET
         + coff.SizeOfOptionalHeader
-        + sizeof(PeSection) * coff.NumberOfSections,
+        + sizeof(PeSection) * max(coff.NumberOfSections, args.minimum_sections),
         FILE_ALIGNMENT,
     )
     # DYNAMIC_BASE|NX_COMPAT|HIGH_ENTROPY_VA or DYNAMIC_BASE|NX_COMPAT
@@ -578,6 +579,12 @@ def main():
         type=argparse.FileType("wb"),
         help="Output PE/EFI file",
     )
+    parser.add_argument(
+        "--minimum-sections",
+        type=int,
+        default=0,
+        help="Minimum number of sections to leave space for",
+    )
 
     elf2efi(parser.parse_args())