hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

no zend_compat extensions in compiled HHVM even when ENABLE_ZEND_COMPAT=ON

Open breezewish opened this issue 12 years ago • 15 comments

I try to compile and use mongo extension, so I cleared all cache, and used cmake -DENABLE_ZEND_COMPAT=ON . and then make.

I did see make compiling zend-compat extensions:

[ 59%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/gettext/gettext.cpp.o
[ 59%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/oauth/oauth.cpp.o
[ 59%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/oauth/provider.cpp.o
[ 59%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/ftp/ftp.cpp.o
[ 59%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/ftp/php_ftp.cpp.o
[ 59%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/hhvm/ZendExecutionStack.cpp.o
[ 59%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/hhvm/zend_hphp_class_to_class_entry.cpp.o
[ 60%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/hhvm/ZendObjectData.cpp.o
[ 60%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/mongo/cursor.cpp.o
[ 60%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/mongo/php_mongo.cpp.o
[ 60%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/mongo/db.cpp.o
[ 60%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/mongo/log_stream.cpp.o
[ 60%] Building CXX object hphp/runtime/CMakeFiles/hphp_runtime_static.dir/ext_zend_compat/mongo/bson.cpp.o
....
[ 77%] Generating ext_hhvm wrapper for ext_zend_compat//gettext/gettext.cpp
[ 77%] Generating ext_hhvm wrapper for ext_zend_compat//oauth/oauth.cpp
[ 77%] Generating ext_hhvm wrapper for ext_zend_compat//oauth/provider.cpp
[ 77%] Generating ext_hhvm wrapper for ext_zend_compat//ftp/ftp.cpp
[ 77%] Generating ext_hhvm wrapper for ext_zend_compat//ftp/php_ftp.cpp
[ 77%] Generating ext_hhvm wrapper for ext_zend_compat//hhvm/ZendExecutionStack.cpp
[ 77%] Generating ext_hhvm wrapper for ext_zend_compat//hhvm/zend_hphp_class_to_class_entry.cpp
[ 77%] Generating ext_hhvm wrapper for ext_zend_compat//hhvm/ZendObjectData.cpp
[ 77%] Generating ext_hhvm wrapper for ext_zend_compat//mongo/cursor.cpp
[ 78%] Generating ext_hhvm wrapper for ext_zend_compat//mongo/php_mongo.cpp
[ 78%] Generating ext_hhvm wrapper for ext_zend_compat//mongo/db.cpp
....
[ 93%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/gettext/gettext.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/oauth/oauth.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/oauth/provider.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/ftp/ftp.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/ftp/php_ftp.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/hhvm/ZendExecutionStack.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/hhvm/zend_hphp_class_to_class_entry.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/hhvm/ZendObjectData.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/mongo/cursor.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/mongo/php_mongo.cpp.ext_hhvm.cpp.o
[ 94%] Building CXX object hphp/runtime/ext_hhvm/CMakeFiles/ext_hhvm_static.dir/__/ext_zend_compat/mongo/db.cpp.ext_hhvm.cpp.o
....

However I cannot use these extensions in compiled HHVM binary. get_loaded_extensions() returns:

Array
(
    [0] => apc
    [1] => bcmath
    [2] => bz2
    [3] => ctype
    [4] => curl
    [5] => date
    [6] => dom
    [7] => exif
    [8] => fb
    [9] => fileinfo
    [10] => filter
    [11] => gd
    [12] => hash
    [13] => hotprofiler
    [14] => iconv
    [15] => icu_ucsdet
    [16] => icu_uspoof
    [17] => idn
    [18] => imap
    [19] => intl.not-done
    [20] => json
    [21] => ldap
    [22] => mbstring
    [23] => mcrypt
    [24] => memcache
    [25] => memcached
    [26] => mysql
    [27] => openssl
    [28] => pcntl
    [29] => pcre
    [30] => PDO
    [31] => pdo_mysql
    [32] => pdo_sqlite
    [33] => phar
    [34] => posix
    [35] => Reflection
    [36] => server
    [37] => session
    [38] => SimpleXML
    [39] => soap
    [40] => sockets
    [41] => SPL
    [42] => sqlite3
    [43] => sysvmsg
    [44] => sysvsem
    [45] => sysvshm
    [46] => thread
    [47] => thrift_protocol
    [48] => tokenizer
    [49] => xhprof
    [50] => xml
    [51] => xmlreader
    [52] => xmlwriter
    [53] => zip
    [54] => zlib
)

breezewish avatar Dec 26 '13 04:12 breezewish

Thanks for reporting this. @sgolemon / @ptarjan should respond when they get back from their holiday.

scannell avatar Dec 26 '13 04:12 scannell

They are turned off at runtime as well. You need -v Eval.EnableZendCompat = true which we turn on during testing: https://github.com/facebook/hhvm/blob/master/hphp/test/config.hdf

ptarjan avatar Dec 26 '13 06:12 ptarjan

It seems not working. I tried -v "Eval.EnableZendCompat = true" and did not get mongodb extension. I also copied https://github.com/facebook/hhvm/blob/master/hphp/test/config.hdf to /etc/hhvm/config.hdf and then run ./hhvm --config /etc/hhvm/config.hdf -m server, still not working :(

breezewish avatar Dec 27 '13 04:12 breezewish

I have same problem. And this is my compile log. https://gist.github.com/higebu/8143126

higebu avatar Dec 27 '13 06:12 higebu

There is one more thing. In hphp/runtime/ext_zend_compat/mongo/php_mongo.cpp:

#ifdef COMPILE_DL_MONGO ZEND_GET_MODULE(mongo) #endif

but COMPILE_DL_MONGO is not set. Similar for other extensions.

Pomyk avatar Dec 28 '13 14:12 Pomyk

@Pomyk ah crap, yes. That define needs to happen. I really need to figure out a way to not need that.

ptarjan avatar Dec 28 '13 19:12 ptarjan

There is also a small bug:

--- a/hphp/runtime/ext_zend_compat/mongo/mcon/mini_bson.cpp
+++ b/hphp/runtime/ext_zend_compat/mongo/mcon/mini_bson.cpp
@@ -46,7 +46,7 @@ static mcon_str *create_simple_header(mongo_connection *con, char *ns)
        if (ns) {
                mcon_str_addl(str, ns, strlen(ns) + 1, 0);
        } else {
-               mcon_str_addl(str, "admin$cwd", 11, 0);
+               mcon_str_addl(str, "admin.$cmd", 11, 0);
        }

After fixing it you can connect to a server but selectDB fails: "selectDB(): could not obtain parameters for parsing". I think it may be caused by calls of php methods from php methods with macros like MONGO_METHOD().

Pomyk avatar Dec 28 '13 21:12 Pomyk

@Pomyk Wow, you're right: https://github.com/mongodb/mongo-php-driver/blob/master/mcon/mini_bson.c#L46 If you want to try to re-import the source from there, you might see other bugs that somehow crept in. MONGO_METHOD should work as all their unit tests are passing (you can see them in test/slow/ext_mongo).

ptarjan avatar Dec 28 '13 23:12 ptarjan

A day of debugging and some more stuff found:

  • HPHP::liveFrame()->numArgs() returns number of arguments of parent function when php method calls php method.
  • ZendExecutionStack::getArg() assumes wrong order of params in SIDE_STACK mode
  • object_init() fails because zend_standard_class_def is not initialized
  • when inserting array of data without _id, a unique _id is added to the array, second attempt to insert the same array fails because it has _id from the previous insert. In php it works.

Sometimes these asserts fail:

  • hphp/runtime/ext_zend_compat/php-src/Zend/zend_operators.h: assert(ret->isProxyArray())
  • hhvm/hphp/runtime/base/hphp-array.cpp:1083: Assertion old->m_allocMode == AllocationMode::smart failed.
  • hhvm/hphp/runtime/base/object-data.cpp:438: Assertion false failed.

I might try to fix some of this stuff but maybe it will be easier to port this extension.

Pomyk avatar Dec 29 '13 21:12 Pomyk

@Pomyk Thanks so much for the finds. I'll definitely look at them too when I'm back from vacation next week. If you write me any unit tests (as pull requests) I'm more than happy to get them working, all I had to work off of was the ones included in test/slow/ext_mongo.

The worry I have about porting this one is that there are so many subtleties. It will be faster to not use the compat layer, but getting the edge cases right will be harder than fixing the mistakes in the compat layer. You are welcome to try it, and if you get it working, we would love to have it as a dynamically linked extension.

ptarjan avatar Dec 30 '13 04:12 ptarjan

I might try to fix some of this stuff but maybe it will be easier to port this extension.

If someone is willing to lead this project, I really like to help. ext-mongo is one of the missing key-features for me. My C++ is currently not good enough to implement ext-mongo for HHVM on my own. :-/

bzikarsky avatar Dec 30 '13 14:12 bzikarsky

We'd be grateful if someone ported the mongo extension as it is a common request. @aatch implemented postgresql as an external and dynamically loaded HHVM extension and would probably be happy to provide advice on the process.

scannell avatar Dec 30 '13 17:12 scannell

Although I just began studying C++ this semester, it will be my pleasure if I could give some help :) MongoDB extension is also a missing key-feature for me.

breezewish avatar Dec 31 '13 03:12 breezewish

COMPILE_DL_* don't need to be set, those are for building as DSOs, which we're not doing here.

I think I know what the issue is though...

sgolemon avatar Jan 05 '14 17:01 sgolemon

I fixed this a while ago

ptarjan avatar Mar 10 '14 23:03 ptarjan