Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php embed sapi:undefinded reference to 'sigsetjmp' #564

Closed
KingBes opened this issue Nov 26, 2024 · 7 comments · Fixed by #573
Closed

php embed sapi:undefinded reference to 'sigsetjmp' #564

KingBes opened this issue Nov 26, 2024 · 7 comments · Fixed by #573
Assignees
Labels
kind/php-and-sapi Issues related to php source and SAPI os/linux Things only for Linux OS question Further information is requested

Comments

@KingBes
Copy link

KingBes commented Nov 26, 2024

System:Ubuntu 、deepin

bulid

./spc build --build-all "apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib" --with-upx-pack --debug

cphp.c

#include <sapi/embed/php_embed.h>

int main(int argc,char **argv){

    PHP_EMBED_START_BLOCK(argc,argv)

    zend_file_handle file_handle;

    zend_stream_init_filename(&file_handle,"index.php");

    if(php_execute_script(&file_handle) == FAILURE){
        php_printf("Failed to execute PHP script.\n");
    }

    PHP_EMBED_END_BLOCK()
    return 0;
}

index.php

<?php

echo "hello world" . PHP_EOL;

build.sh

gcc \
$(./buildroot/bin/php-config --includes) \
-L$(./buildroot/bin/php-config --prefix)/lib \
cphp.c \
-lphp \
$(./buildroot/bin/php-config --libs) \
-lm -lresolv -ldl -lpthread -lc \
-Wl,-rpath=$(./buildroot/bin/php-config --prefix)/lib

89058C07043238F6B5F5294787F6477A

@KingBes
Copy link
Author

KingBes commented Nov 26, 2024

b7e12366-97d5-4e2b-b019-411690340fff

@dunglas
Copy link
Contributor

dunglas commented Nov 27, 2024

Can you try if --with-upx-pack fixes the issue? I'm not sure this flag is really compatible with building a static library.

@KingBes
Copy link
Author

KingBes commented Nov 28, 2024

Can you try if --with-upx-pack fixes the issue? I'm not sure this flag is really compatible with building a static library.

Thanks for the reminder, but the flag --with-upx-pack does not affect the result.

@dunglas
Copy link
Contributor

dunglas commented Nov 28, 2024

That's weird. FrankenPHP is using the embed SAPI and doesn't have this issue.
Would you be able to provide us a minimal reproducer?

@KingBes
Copy link
Author

KingBes commented Nov 29, 2024

I added the whole thing to the zip package. embed-package

@crazywhalecc crazywhalecc added bug Something isn't working kind/php-and-sapi Issues related to php source and SAPI os/linux Things only for Linux OS labels Dec 1, 2024
@crazywhalecc
Copy link
Owner

@KingBes I tested and it's working, but indeed there are some bugs need to be fixed.

I'm using FrankenPHP's default extension combination to build embed SAPI, and changed buildroot/bin/php-config file, set prefix="" to prefix="/path/to/buildroot". My working command:

# spc build command
bin/spc build apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,gmp,gettext,iconv,igbinary,imagick,intl,ldap,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,parallel,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,ssh2,sysvmsg,sysvsem,sysvshm,tidy,tokenizer,xlswriter,xml,xmlreader,xmlwriter,zip,zlib,yaml,zstd --build-cli --build-micro --debug --enable-zts --build-embed

# edit php-config file using sed or vim or something.....

# compile, use musl-gcc (glibc gcc cannot be compiled statically)
/usr/local/musl/bin/x86_64-linux-musl-cc $(buildroot/bin/php-config --includes) -L$(pwd)/buildroot/lib a.c -lphp $(buildroot/bin/php-config --libs) -lm -lresolv -ldl -lpthread -lc -Wl,-rpath=$(pwd)/buildroot/lib -lpq -lpgport -lpgcommon -lgomp -lstdc++ -static

@crazywhalecc
Copy link
Owner

I found some bugs:

  • Linking issue with PHP 8.4 and libpq #560 (strange bug but I do use the same way to make it work: Passing -lpq -lpgcommon -lpgport)
  • php-config --version returns an empty string #563
  • Missing prefix (may be defined in ./configure argument or inserting a patch function in php-config?)
  • Missing build flags in php-config (Maybe adding -lresolv -lstdc++ these flags to php-config would be better?)
  • Missing compiler guide (Most developers are using glibc-gcc incorrectly?)

I'm not sure about the habits of most developers who use embed, so it would be great if you or someone could provide some suggestions.

@crazywhalecc crazywhalecc self-assigned this Dec 4, 2024
@crazywhalecc crazywhalecc added question Further information is requested and removed bug Something isn't working labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/php-and-sapi Issues related to php source and SAPI os/linux Things only for Linux OS question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants