@@ -33,15 +33,25 @@ abstract class UnixBuilderBase extends BuilderBase
3333
3434 private static array $ undefined_symbols = [];
3535
36- public static function getUndefinedSymbols (): array
36+ public static function getDynamicExportSymbols (): array
3737 {
3838 if (count (self ::$ undefined_symbols )) {
3939 return self ::$ undefined_symbols ;
4040 }
4141
42- $ undefined = [];
42+ if (SPCTarget::isStatic ()) { // no reason to keep symbols when we can't load shared extensions!
43+ return [];
44+ }
4345
44- $ addSymbolsFromString = function (string $ out , &$ list ) {
46+ // keep all symbols defined in libphp.a
47+ $ defined = [];
48+ $ libphp = BUILD_LIB_PATH . '/libphp.a ' ;
49+ if (!is_file ($ libphp )) {
50+ throw new WrongUsageException ('You must build libphp.a before calling this function. ' );
51+ }
52+ $ cmd = 'nm -g --defined-only -P ' . escapeshellarg ($ libphp ) . ' 2>/dev/null ' ;
53+ $ out = shell_exec ($ cmd ) ?: '' ;
54+ if ($ out !== '' ) {
4555 foreach (preg_split ('/\R/ ' , trim ($ out )) as $ line ) {
4656 if ($ line === '' ) {
4757 continue ;
@@ -52,40 +62,14 @@ public static function getUndefinedSymbols(): array
5262 }
5363 $ name = preg_replace ('/@.*$/ ' , '' , $ name );
5464 if ($ name !== '' && $ name !== false ) {
55- $ list [$ name ] = true ;
65+ $ defined [$ name ] = true ;
5666 }
5767 }
58- };
59-
60- // collect undefined symbols from shared extensions
61- $ files = glob (rtrim (BUILD_MODULES_PATH , '/ ' ) . DIRECTORY_SEPARATOR . '*.so ' ) ?: [];
62- foreach ($ files as $ so ) {
63- $ cmd = 'nm -D --undefined-only -P ' . escapeshellarg ($ so ) . ' 2>/dev/null ' ;
64- $ out = shell_exec ($ cmd );
65- if ($ out !== '' ) {
66- $ addSymbolsFromString ($ out , $ undefined );
67- }
6868 }
69+ sort ($ defined , SORT_STRING );
6970
70- // keep only symbols defined in libphp.a
71- $ defined = [];
72- $ libphp = BUILD_LIB_PATH . '/libphp.a ' ;
73- if (!is_file ($ libphp )) {
74- throw new WrongUsageException ('You must build libphp.a statically before calling this function. ' );
75- }
76- $ cmd = 'nm -g --defined-only -P ' . escapeshellarg ($ libphp ) . ' 2>/dev/null ' ;
77- $ out = shell_exec ($ cmd ) ?: '' ;
78- if ($ out !== '' ) {
79- $ addSymbolsFromString ($ out , $ defined );
80- }
81- // intersect: only undefined symbols that libphp.a actually defines
82- $ keys = array_intersect_key ($ undefined , $ defined );
83-
84- $ list = array_keys ($ keys );
85- sort ($ list , SORT_STRING );
86-
87- self ::$ undefined_symbols = $ list ;
88- return $ list ;
71+ self ::$ undefined_symbols = $ defined ;
72+ return self ::$ undefined_symbols ;
8973 }
9074
9175 public function proveLibs (array $ sorted_libraries ): void
@@ -209,7 +193,7 @@ protected function sanityCheck(int $build_target): void
209193 foreach (glob (BUILD_LIB_PATH . "/libphp*. {$ suffix }" ) as $ file ) {
210194 unlink ($ file );
211195 }
212- $ symbols = self ::getUndefinedSymbols (); // returns unique, version-stripped names
196+ $ symbols = self ::getDynamicExportSymbols (); // returns unique, version-stripped names
213197 // turn list into many --export-dynamic-symbol=... flags
214198 $ dynamic_exports = implode (
215199 ' ' ,
@@ -340,7 +324,7 @@ protected function buildFrankenphp(): void
340324 $ debugFlags = $ this ->getOption ('no-strip ' ) ? '-w -s ' : '' ;
341325 $ dynamic_exports = '' ;
342326 if (getenv ('SPC_CMD_VAR_PHP_EMBED_TYPE ' ) === 'static ' ) {
343- $ symbols = self ::getUndefinedSymbols (); // returns unique, version-stripped names
327+ $ symbols = self ::getDynamicExportSymbols (); // returns unique, version-stripped names
344328 // turn list into many --export-dynamic-symbol=... flags
345329 $ dynamic_exports = ' ' . implode (
346330 ' ' ,
0 commit comments