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

Uninitialized TLS key is used due to dependencies between static objects #1815

Closed
rbelenov opened this issue Feb 14, 2014 · 4 comments
Closed
Labels

Comments

@rbelenov
Copy link
Contributor

The problem is that static object ThreadLocalManager::s_manager (declared in hphp/util/thread_local.h) is used during initialization of the HPHP::s_255_255_255_255 constant (defined in hphp/runtime/ext/ext_network.cpp); the stack that leads to ThreadLocalManager use is the following
#0 0x0000003710e0c500 in pthread_setspecific () from /lib64/libpthread.so.0
#1 0x0000000001bff66f in HPHP::ThreadLocalSetValue (key=0, value=0x7ffff4ff2e30) at /home/dev/hiphop-git-master/hhvm/hphp/util/thread-local.h:74
#2 0x0000000001bff6c4 in HPHP::ThreadLocalManager::setTop (this=0x77a0ca0 HPHP::ThreadLocalManager::s_manager, p=0x7ffff4ff2e30) at /home/dev/hiphop-git-master/hhvm/hphp/util/thread-local.h:115
#3 0x0000000001d54355 in HPHP::ThreadLocalNoCheckHPHP::BigintData::create (this=0x7ffff4ff2e30) at /home/dev/hiphop-git-master/hhvm/hphp/util/thread-local.h:211
#4 0x0000000001d542e8 in HPHP::ThreadLocalNoCheckHPHP::BigintData::getCheck (this=0x7ffff4ff2e30) at /home/dev/hiphop-git-master/hhvm/hphp/util/thread-local.h:219
#5 0x0000000001d4ffbf in HPHP::zend_get_bigint_data () at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/zend-strtod.cpp:388
#6 0x0000000001bb9b91 in HPHP::is_numeric_string (str=0x77ec598 "255.255.255.255", length=15, lval=0x7fffffffdf18, dval=0x7fffffffdf10, allow_errors=1) at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/zend-functions.cpp:155
#7 0x0000000001c9f156 in HPHP::StringData::isNumericWithVal (this=0x77ec580, lval=@0x7fffffffdf18: 236502621073, dval=@0x7fffffffdf10: 6.9533558074638622e-310, allow_errors=1)

at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/string-data.cpp:514

#8 0x0000000001c9f05f in HPHP::StringData::preCompute (this=0x77ec580) at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/string-data.cpp:490
#9 0x0000000001c9f0af in HPHP::StringData::setStatic (this=0x77ec580) at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/string-data.cpp:497
#10 0x0000000001c9ce0d in HPHP::StringData::MakeShared (sl=..., trueStatic=true) at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/string-data.cpp:108
#11 0x0000000001c9cefe in HPHP::StringData::MakeStatic (sl=...) at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/string-data.cpp:121
#12 0x0000000001c302fd in HPHP::(anonymous namespace)::insertStaticString (slice=...) at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/static-string-table.cpp:133
#13 0x0000000001c30595 in HPHP::makeStaticString (slice=...) at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/static-string-table.cpp:177
#14 0x0000000001c30733 in HPHP::makeStaticString (str=0x37319b1 "255.255.255.255", len=15) at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/static-string-table.cpp:200
#15 0x0000000001c307f3 in HPHP::makeStaticString (str=0x37319b1 "255.255.255.255") at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/static-string-table.cpp:211
#16 0x0000000001bee5bb in HPHP::StaticString::StaticString (this=0x5786da8 HPHP::s_255_255_255_255, s=0x37319b1 "255.255.255.255") at /home/dev/hiphop-git-master/hhvm/hphp/runtime/base/type-string.cpp:556
#17 0x0000000001fa803c in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at /home/dev/hiphop-git-master/hhvm/hphp/runtime/ext/ext_network.cpp:278
#18 0x0000000001fa8600 in _GLOBAL__sub_I__ZN4HPHP12ResolverInit5s_resE () at /home/dev/hiphop-git-master/hhvm/hphp/runtime/ext/ext_network.cpp:1109
#19 0x000000000348d44d in __libc_csu_init ()
#20 0x0000003710a1ec70 in __libc_start_main () from /lib64/libc.so.6
#21 0x0000000001ba5c39 in _start ()

The ThreadLocalManager was not yet called (the order of the static object initialization is undefined), so the key is 0 (and pthread lib is not aware that it is used).

The problem was found when trying to profile hhvm with Intel Vtune Amplifier but it can affect regular execution as well. Probably some simple string class (that does not use thread local manager) may be used fro this s_255_... constant to fix the problem.

@rbelenov
Copy link
Contributor Author

PS The problem is found on the master code branch.

@scannell
Copy link
Contributor

Thanks for reporting this. Feel free to submit a PR if you (or someone else reading this) gets to this before we do.

@LiraNuna
Copy link
Contributor

This was supposed to be resolved with #2209, the constant is unused.

@rbelenov
Copy link
Contributor Author

The constant should be removed from https://github.com/facebook/hhvm/blob/master/hphp/runtime/ext/std/ext_std_network.cpp if it's really not used - the problem is caused by the object constructor even if the constant is not referenced in the code.

LiraNuna pushed a commit that referenced this issue Apr 28, 2014
Summary: D1258331 changed the way the function `ip2long` behaved, but didn't remove the constant.
The constant causes a race condition when the application is being ran under Intel's vtune.

Fixes #1815

Reviewed By: @fredemmott

Differential Revision: D1292121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants