From f3afd81c81f2550faeafcb52394a49ff9aef4c4a Mon Sep 17 00:00:00 2001 From: m-this <52073029+m-this@users.noreply.github.com> Date: Wed, 8 Jul 2026 10:11:27 +0200 Subject: [PATCH] fix(php): pass /FORCE:MULTIPLE when linking php-cgi.exe and micro.sfx - php.exe already links with /FORCE:MULTIPLE for extension-bundled duplicate symbols, cgi and micro did not - imagick's MagickCore defines gettimeofday, also defined in php's time.obj, and both links failed with LNK2005 --- src/Package/Target/php/windows.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Package/Target/php/windows.php b/src/Package/Target/php/windows.php index d8cc7293..dfc09882 100644 --- a/src/Package/Target/php/windows.php +++ b/src/Package/Target/php/windows.php @@ -201,7 +201,10 @@ trait windows throw new PatchException('Windows Makefile patching for php-cgi.exe target', 'Cannot patch windows CGI Makefile, Makefile does not contain "$(BUILD_DIR)\php-cgi.exe:" line'); } $lines[$line_num] = '$(BUILD_DIR)\php-cgi.exe: $(DEPS_CGI) $(CGI_GLOBAL_OBJS) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(ASM_OBJS) $(BUILD_DIR)\php-cgi.exe.res $(BUILD_DIR)\php-cgi.exe.manifest'; - $lines[$line_num + 1] = "\t" . '@"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CGI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CGI) $(BUILD_DIR)\php-cgi.exe.res /out:$(BUILD_DIR)\php-cgi.exe $(LDFLAGS) $(LDFLAGS_CGI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286'; + // /FORCE:MULTIPLE /ignore:4006: same reason as the php.exe target above. Without it the + // CGI link fails with LNK2005 (e.g. imagick's MagickCore defines gettimeofday, which + // php's time.obj also defines). + $lines[$line_num + 1] = "\t" . '@"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CGI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CGI) $(BUILD_DIR)\php-cgi.exe.res /out:$(BUILD_DIR)\php-cgi.exe $(LDFLAGS) $(LDFLAGS_CGI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286 /FORCE:MULTIPLE /ignore:4006'; FileSystem::writeFile("{$package->getSourceDir()}\\Makefile", implode("\r\n", $lines)); // Patch cgi-static, comment ZEND_TSRMLS_CACHE_DEFINE() @@ -268,6 +271,19 @@ trait windows } } + #[BeforeStage('php', [self::class, 'makeMicroForWindows'])] + #[PatchDescription('Add /FORCE:MULTIPLE to the micro.sfx link, matching the CLI and CGI targets')] + public function patchMicroTarget(TargetPackage $package): void + { + $makefile = "{$package->getSourceDir()}\\Makefile"; + if (str_contains(FileSystem::readFile($makefile), 'LDFLAGS_MICRO=/FORCE:MULTIPLE')) { + return; + } + // Same reason as the php.exe and php-cgi.exe targets: extension-bundled libs duplicate + // symbols from php's own objects and the link fails with LNK2005. + FileSystem::replaceFileStr($makefile, "\r\nLDFLAGS_MICRO=", "\r\nLDFLAGS_MICRO=/FORCE:MULTIPLE /ignore:4006 "); + } + #[Stage] public function makeMicroForWindows(TargetPackage $package, PackageBuilder $builder, PackageInstaller $installer): void {