1818#include "php.h"
1919#include "zend_system_id.h"
2020#include "zend_extensions.h"
21+ #include "zend_abi_signature.h"
2122#include "ext/standard/md5.h"
2223#include "ext/hash/php_hash.h"
2324
@@ -44,14 +45,6 @@ ZEND_API zend_result zend_add_system_entropy(const char *module_name, const char
4445void zend_startup_system_id (void )
4546{
4647 PHP_MD5Init (& context );
47- PHP_MD5Update (& context , PHP_VERSION , sizeof (PHP_VERSION )- 1 );
48- PHP_MD5Update (& context , ZEND_EXTENSION_BUILD_ID , sizeof (ZEND_EXTENSION_BUILD_ID )- 1 );
49- PHP_MD5Update (& context , ZEND_BIN_ID , sizeof (ZEND_BIN_ID )- 1 );
50- if (strstr (PHP_VERSION , "-dev" ) != 0 ) {
51- /* Development versions may be changed from build to build */
52- PHP_MD5Update (& context , __DATE__ , sizeof (__DATE__ )- 1 );
53- PHP_MD5Update (& context , __TIME__ , sizeof (__TIME__ )- 1 );
54- }
5548 zend_system_id [0 ] = '\0' ;
5649}
5750
@@ -66,6 +59,27 @@ void zend_finalize_system_id(void)
6659 unsigned char digest [16 ];
6760 uint8_t hooks = 0 ;
6861
62+ if (EG (portable_build )) {
63+ /* Portable build mode: Use the ABI signature and major/minor version */
64+ int major_version = PHP_MAJOR_VERSION ;
65+ int minor_version = PHP_MINOR_VERSION ;
66+
67+ PHP_MD5Update (& context , (const unsigned char * )& major_version , sizeof (int ));
68+ PHP_MD5Update (& context , (const unsigned char * )& minor_version , sizeof (int ));
69+ PHP_MD5Update (& context , (const unsigned char * )zend_opcache_abi_signature , strlen (zend_opcache_abi_signature ));
70+ } else {
71+ /* Default strict mode: Use the original full-fat build ID */
72+ PHP_MD5Update (& context , PHP_VERSION , sizeof (PHP_VERSION )- 1 );
73+ PHP_MD5Update (& context , ZEND_EXTENSION_BUILD_ID , sizeof (ZEND_EXTENSION_BUILD_ID )- 1 );
74+ if (strstr (PHP_VERSION , "-dev" ) != 0 ) {
75+ PHP_MD5Update (& context , __DATE__ , sizeof (__DATE__ )- 1 );
76+ PHP_MD5Update (& context , __TIME__ , sizeof (__TIME__ )- 1 );
77+ }
78+ }
79+
80+ /* These are always critical for compatibility */
81+ PHP_MD5Update (& context , ZEND_BIN_ID , sizeof (ZEND_BIN_ID )- 1 );
82+
6983 if (zend_ast_process ) {
7084 hooks |= ZEND_HOOK_AST_PROCESS ;
7185 }
0 commit comments