-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Seg fault observed while loading dl with RTLD_DEEPBIND #11291
Comments
The Line 55 in 0e45ed7
I'm guessing you're using an outdated header. You may be relying on outdated function signatures, but I'm not sure how that is related to |
Thanks for the quick response. The issue occurs even without TSRMLS_FETCH(); While researching I saw a similar discussion. |
@aswingit If you're not using |
Please see the response below
|
@aswingit Could you enable the debug flag? Otherwise the last frame isn't visible, which is where the crash actually happens. Edit: Hmm, you probably alread are, otherwise |
Maybe @nielsdos has an idea on what could cause this, especially regarding |
The reason the last frame isn't visible is because the segfault occurs when zend_printf_to_smart_string() is called. zend_printf_to_smart_string is a function pointer, defined as a global variable in zend.c. The address you see at the top frame is probably correct: zend_printf_to_smart_string is NULL, hence the crash. |
@aswingit How are you compiling and linking your extension? I find it odd that I see both the CGI SAPI and libphp.so in the backtrace. I think that might be the root cause of your issue. The linker will try to use the symbols from libphp.so instead of what has been setup by the CGI SAPI binary. |
I am building hello_world.so externally and linking with libphp.so.
|
Okay, that is indeed the problem, so it's not actually a bug in PHP. You're not supposed to compile it like that, because now you're already linking to the PHP library instead of relying on the runtime to link against the SAPI binary. This causes the global symbol conflict you were seeing. Fortunately it's easy to fix. There's an extension example you can find on GitHub: https://github.com/dstogov/php-extension. You can just replace the relevant C code with your own and use the configuration files in that repo. Then you can take a look at https://www.zend.com/resources/php-extensions/building-and-installing-php-extension to see how to setup the build environment (with phpize) and then how to configure and make your extension. Hope this helps, if you're still stuck after following the instructions please let us know. |
Description
Issue:
I encountered a segmentation fault when attempting to load a hello_world module using the dl() function. The seg fault does not occur when I remove the RTLD_DEEPBIND mode in the dlopen() function from zend_portability.h.
Version:
I'm using PHP version 8.1.3.
Setup:
Here's the setup I have:
a) I have a hello world module that is built as a dynamic library.
b) I'm loading the dynamic library using the dl() function in PHP and invoking the hello_world function. However, I'm experiencing a segmentation fault with the following stack trace:
PHP Version
PHP 8.1.3
Operating System
No response
The text was updated successfully, but these errors were encountered: