Skip to content

Commit 45303a2

Browse files
authored
[PEFIXUP] Recalculate checksums for kernel-mode images (reactos#8969)
lld can leave the PE checksum field zero for reproducible output. This is acceptable for user-mode images, but Windows rejects kernel-mode images without a valid checksum. Keep preserving linker-produced zero checksums for other images, but force checksum recalculation when pefixup is operating on a kernel-mode image. This was found while validating Clang-built amd64 kmtest drivers against Windows 7: the same driver source built with GCC loaded, while the Clang/lld-built .sys failed with ERROR_BAD_EXE_FORMAT / 0xC1. Recalculating the PE checksum made the Clang-built driver load and the tests run correctly.
1 parent f86835f commit 45303a2

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎sdk/tools/pefixup.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,17 @@ int main(int argc, char **argv)
521521

522522
if (!result)
523523
{
524-
/* Success. Recalculate the checksum only if this is not a reproducible build file */
525-
if (nt_header->OptionalHeader.CheckSum != 0)
524+
int is_kernel_image = (mode == MODE_KERNELDRIVER ||
525+
mode == MODE_WDMDRIVER ||
526+
mode == MODE_KERNELDLL ||
527+
mode == MODE_KERNEL);
528+
529+
/*
530+
* Preserve linker-produced zero checksums unless this is a kernel-mode
531+
* image, where the NT loader requires a valid checksum. This fixes
532+
* lld-built drivers, which otherwise keep the reproducible zero value.
533+
*/
534+
if (nt_header->OptionalHeader.CheckSum != 0 || is_kernel_image)
526535
fix_checksum(buffer, len, nt_header);
527536

528537
/* We could optimize by only writing the changed parts, but keep it simple for now */

0 commit comments

Comments
 (0)