summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2024-03-23 12:04:14 +0100
committerGitHub <noreply@github.com>2024-03-23 12:04:14 +0100
commitda867fa3c3f18e47ef46457e7792deb60d773613 (patch)
tree480d8750b468bd456be3a88f5e83d1ad1f902971 /tools
parentMerge pull request #31779 from keszybz/elf2efi-clang-18 (diff)
parentefi: check if all sections of our EFI binaries are properly aligned (diff)
downloadsystemd-da867fa3c3f18e47ef46457e7792deb60d773613.tar.xz
systemd-da867fa3c3f18e47ef46457e7792deb60d773613.zip
Merge pull request #31907 from mrc0mmand/efi-shenanigans
efi: check if all sections of our EFI binaries are properly aligned
Diffstat (limited to 'tools')
-rwxr-xr-xtools/check-efi-alignment.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/check-efi-alignment.py b/tools/check-efi-alignment.py
new file mode 100755
index 0000000000..bb33ac0809
--- /dev/null
+++ b/tools/check-efi-alignment.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python3
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# vi: set tw=110 sw=4 ts=4 et:
+
+import sys
+
+import pefile
+
+
+def main():
+ pe = pefile.PE(sys.argv[1], fast_load=True)
+
+ for section in pe.sections:
+ name = section.Name.rstrip(b"\x00").decode()
+ file_addr = section.PointerToRawData
+ virt_addr = section.VirtualAddress
+ print(f"{name:10s} file=0x{file_addr:08x} virt=0x{virt_addr:08x}")
+
+ if file_addr % 512 != 0:
+ print(f"File address of {name} section is not aligned to 512 bytes", file=sys.stderr)
+ return 1
+
+ if virt_addr % 512 != 0:
+ print(f"Virt address of {name} section is not aligned to 512 bytes", file=sys.stderr)
+ return 1
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ print(f"Usage: {sys.argv[0]} pe-image")
+ sys.exit(1)
+
+ sys.exit(main())