Hi. I trying to make shared/static library and use...
# kotlin-native
r
Hi. I trying to make shared/static library and use it in C project (php extencion).
kotlinc -opt ./hellokt.kt -o hellokt -produce dynamic
kotlinc -opt ./hellokt.kt -o hellokt -produce static
With shared library all working, but with static library I receive segfault. Why it can be? Mabe I need to provide some specific keys to c compiler?
o
could you please provide stacktrace of crash from debugger?
r
Copy code
(gdb) run -dextension=./modules/hello.so -r "echo hello('JoE');"
Starting program: /opt/rh/rh-php71/root/usr/bin/php -dextension=./modules/hello.so -r "echo hello('JoE');"
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00005555557b0682 in zend_register_functions ()
(gdb) bt
#0  0x00005555557b0682 in zend_register_functions ()
#1  0x00005555557b16b7 in zend_register_module_ex ()
#2  0x00005555556ecc36 in php_load_extension ()
#3  0x000055555579dace in zend_llist_apply ()
#4  0x000055555574f59a in php_ini_register_extensions ()
#5  0x0000555555747da9 in php_module_startup ()
#6  0x000055555584796d in php_cli_startup ()
#7  0x0000555555624838 in main ()
Library loaded on step
php_load_extension
and registered as module on step
zend_register_module_ex
. Also, if I do not use any library function inside c code, then no crash occured
If I use
-p dynamic
(
libhellokt.so
) - extension work normally
o
Could you try to add
initRuntimeIfNeeded
call before calling Kotlin functionality, i.e. just before println?
r
No effect
Copy code
fun kt_print(string: String) {
    konan.initRuntimeIfNeeded()
    println("Hello, $string!!!")
}
Solved. I know how, but don't understand why. If interesting I can write later, after some research