@@ -193,7 +193,7 @@ protected function buildCli(): void
193193 ->exec ("{$ SPC_CMD_PREFIX_PHP_MAKE } {$ vars } cli " );
194194
195195 if (!$ this ->getOption ('no-strip ' , false )) {
196- shell ()->cd (SOURCE_PATH . '/php-src/sapi/cli ' )->exec ('strip --strip-all php ' );
196+ shell ()->cd (SOURCE_PATH . '/php-src/sapi/cli ' )->exec ('strip --strip-unneeded php ' );
197197 }
198198 if ($ this ->getOption ('with-upx-pack ' )) {
199199 shell ()->cd (SOURCE_PATH . '/php-src/sapi/cli ' )
@@ -256,7 +256,7 @@ protected function buildFpm(): void
256256 ->exec ("{$ SPC_CMD_PREFIX_PHP_MAKE } {$ vars } fpm " );
257257
258258 if (!$ this ->getOption ('no-strip ' , false )) {
259- shell ()->cd (SOURCE_PATH . '/php-src/sapi/fpm ' )->exec ('strip --strip-all php-fpm ' );
259+ shell ()->cd (SOURCE_PATH . '/php-src/sapi/fpm ' )->exec ('strip --strip-unneeded php-fpm ' );
260260 }
261261 if ($ this ->getOption ('with-upx-pack ' )) {
262262 shell ()->cd (SOURCE_PATH . '/php-src/sapi/fpm ' )
@@ -280,47 +280,72 @@ protected function buildEmbed(): void
280280 ->exec (getenv ('SPC_CMD_PREFIX_PHP_MAKE ' ) . ' INSTALL_ROOT= ' . BUILD_ROOT_PATH . " {$ vars } install " );
281281
282282 $ ldflags = getenv ('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS ' );
283+ $ libDir = BUILD_LIB_PATH ;
284+ $ modulesDir = BUILD_MODULES_PATH ;
285+ $ libphpSo = "{$ libDir }/libphp.so " ;
283286 $ realLibName = 'libphp.so ' ;
287+
284288 if (preg_match ('/-release\s+(\S+)/ ' , $ ldflags , $ matches )) {
285289 $ release = $ matches [1 ];
286- $ realLibName = 'libphp- ' . $ release . '.so ' ;
287- $ cwd = getcwd ();
288- $ libphpPath = BUILD_LIB_PATH . '/libphp.so ' ;
289- $ libphpRelease = BUILD_LIB_PATH . '/ ' . $ realLibName ;
290- if (!file_exists ($ libphpRelease ) && file_exists ($ libphpPath )) {
291- rename ($ libphpPath , $ libphpRelease );
290+ $ realLibName = "libphp- {$ release }.so " ;
291+ $ libphpRelease = "{$ libDir }/ {$ realLibName }" ;
292+ if (!file_exists ($ libphpRelease ) && file_exists ($ libphpSo )) {
293+ rename ($ libphpSo , $ libphpRelease );
292294 }
293295 if (file_exists ($ libphpRelease )) {
294- chdir (BUILD_LIB_PATH );
295- if (file_exists ($ libphpPath )) {
296- unlink ($ libphpPath );
296+ chdir ($ libDir );
297+ if (file_exists ($ libphpSo )) {
298+ unlink ($ libphpSo );
297299 }
298300 symlink ($ realLibName , 'libphp.so ' );
301+ shell ()->exec (sprintf (
302+ 'patchelf --set-soname %s %s ' ,
303+ escapeshellarg ($ realLibName ),
304+ escapeshellarg ($ libphpRelease )
305+ ));
299306 }
300- if (is_dir (BUILD_MODULES_PATH )) {
301- chdir (BUILD_MODULES_PATH );
307+ if (is_dir ($ modulesDir )) {
308+ chdir ($ modulesDir );
302309 foreach ($ this ->getExts () as $ ext ) {
303310 if (!$ ext ->isBuildShared ()) {
304311 continue ;
305312 }
306313 $ name = $ ext ->getName ();
307314 $ versioned = "{$ name }- {$ release }.so " ;
308315 $ unversioned = "{$ name }.so " ;
309- if (is_file (BUILD_MODULES_PATH . "/ {$ versioned }" )) {
310- rename (BUILD_MODULES_PATH . "/ {$ versioned }" , BUILD_MODULES_PATH . "/ {$ unversioned }" );
311- shell ()->cd (BUILD_MODULES_PATH )
312- ->exec (sprintf (
313- 'patchelf --set-soname %s %s ' ,
314- escapeshellarg ($ unversioned ),
315- escapeshellarg ($ unversioned )
316- ));
316+ $ src = "{$ modulesDir }/ {$ versioned }" ;
317+ $ dst = "{$ modulesDir }/ {$ unversioned }" ;
318+ if (is_file ($ src )) {
319+ rename ($ src , $ dst );
320+ shell ()->exec (sprintf (
321+ 'patchelf --set-soname %s %s ' ,
322+ escapeshellarg ($ unversioned ),
323+ escapeshellarg ($ dst )
324+ ));
317325 }
318326 }
319327 }
320- chdir ($ cwd );
328+ chdir (getcwd ());
329+ }
330+
331+ $ target = "{$ libDir }/ {$ realLibName }" ;
332+ if (file_exists ($ target )) {
333+ [, $ output ] = shell ()->execWithResult ("readelf -d " . escapeshellarg ($ target ));
334+ $ output = join ("\n" , $ output );
335+ if (preg_match ('/SONAME.*\[(.+)\]/ ' , $ output , $ sonameMatch )) {
336+ $ currentSoname = $ sonameMatch [1 ];
337+ if ($ currentSoname !== basename ($ target )) {
338+ shell ()->exec (sprintf (
339+ 'patchelf --set-soname %s %s ' ,
340+ escapeshellarg (basename ($ target )),
341+ escapeshellarg ($ target )
342+ ));
343+ }
344+ }
321345 }
346+
322347 if (!$ this ->getOption ('no-strip ' , false ) && file_exists (BUILD_LIB_PATH . '/ ' . $ realLibName )) {
323- shell ()->cd (BUILD_LIB_PATH )->exec ("strip --strip-all {$ realLibName }" );
348+ shell ()->cd (BUILD_LIB_PATH )->exec ("strip --strip-unneeded {$ realLibName }" );
324349 }
325350 $ this ->patchPhpScripts ();
326351 }
@@ -382,7 +407,7 @@ private function processMicroUPXLegacy(): void
382407 private function processMicroUPX (): void
383408 {
384409 if (version_compare ($ this ->getMicroVersion (), '0.2.0 ' ) >= 0 && !$ this ->getOption ('no-strip ' , false )) {
385- shell ()->exec ('strip --strip-all ' . SOURCE_PATH . '/php-src/sapi/micro/micro.sfx ' );
410+ shell ()->exec ('strip --strip-unneeded ' . SOURCE_PATH . '/php-src/sapi/micro/micro.sfx ' );
386411
387412 if ($ this ->getOption ('with-upx-pack ' )) {
388413 // strip first
0 commit comments