Re: Crash with mozjs-76 on Linux in _dl_runtime_resolve() / dl_fixup() as soon as program starts

Matthew Gaudet <[email protected]> Wed, 20 May 2020 06:43:14 -0600
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <CAK1KXSbPSEyEON-0EAbOAXtb6BO_ZZeQFd=uOn+ejcO+ByzNjg@mail.gmail.com>
Hi Miles,

So I looked at this for about five minutes (take the following with the
appropriate grain of salt):

My guess is something is funky with your newly built compilers and
pthreads: I suspect there's some weird incompatibility here. Can you build
a straight up basic pthreads program?

My reasoning is as follows:

1. If you look at the crash location, it appears to be calling into the
constructor of mozilla::detail::MutexImpl():
https://searchfox.org/mozilla-central/rev/61fceb7c0729773f544a9656f474e36cd636e5ea/js/src/threading/Mutex.h#39
2. Looking at the posix implementation of that and we see the mutex
implementation is built on pthreads mutexes. }
https://searchfox.org/mozilla-central/rev/61fceb7c0729773f544a9656f474e36cd636e5ea/mozglue/misc/Mutex_posix.cpp#61

Unfortunately your stack sort of dies there. It's difficult to figure out
where it goes next.

In your position, what I'd suggest is trying to build some basic pthreads
code modelled on Mutex_Posix.cpp, and seeing if it fails.

The reason this fails whenever you link in mozjs is because when you start
the program with mozjs linked in you're running the static constructors, if
I had to guess, this one:
https://searchfox.org/mozilla-central/source/js/src/wasm/WasmProcess.cpp#336



On Tue, May 19, 2020 at 10:25 AM Miles <[email protected]> wrote:

> Hi,
>
> I'm trying to upgrade to mozjs-76 and have slowly being sorting out the
> compile errors so I get a program that can link. I've now done that but
> when I run the executable it crashes instantly on startup. If I look at
> where it is crashing in gdb I see (for a release build)
>
> #0  0x000000393100e02c in _dl_fixup () from /lib64/ld-linux-x86-64.so.2
> #1  0x0000003931014725 in _dl_runtime_resolve () from
> /lib64/ld-linux-x86-64.so.2
> #2  0x00007ffff6e2f170 in ?? () from
> /spidermonkey/js76_release/lib/libmozjs-76.so
> #3  0x00007ffff706e9b2 in ?? () from
> /spidermonkey/js76_release/lib/libmozjs-76.so
>
> If I use a debug build I get
>
> #0  0x000000393100e02c in _dl_fixup () from /lib64/ld-linux-x86-64.so.2
> #1  0x0000003931014725 in _dl_runtime_resolve () from
> /lib64/ld-linux-x86-64.so.2
> #2  0x00007ffff570465e in js::MutexImpl::MutexImpl() ()
>     at /spidermonkey/tmp/mozjs-76.0.0/js/src/threading/Mutex.h:39
> #3  0x00007ffff57046ec in js::Mutex::Mutex(js::MutexId const&) ()
>     at /spidermonkey/tmp/mozjs-76.0.0/js/src/threading/Mutex.h:62
> #4  0x00007ffff670237f in
> _ZN2js13ExclusiveDataI12ReadLockFlagEC2IJEEERKNS_7MutexIdEDpOT_ ()
>     at /spidermonkey/tmp/mozjs-76.0.0/js/src/threading/ExclusiveData.h:110
> #5  0x00007ffff670ea11 in __static_initialization_and_destruction_0 ()
>     at /spidermonkey/tmp/mozjs-76.0.0/js/src/wasm/WasmProcess.cpp:336
> #6  0x00007ffff670eb10 in _GLOBAL__sub_I_Unified_cpp_js_src_wasm2.cpp ()
>     at /spidermonkey/tmp/mozjs-76.0.0/js/src/wasm/WasmStubs.cpp:2823
> #7  0x00007ffff6997a42 in __do_global_ctors_aux () from
> /spidermonkey/js76_debug/lib/libmozjs-76.so
> #8  0x00007fffffffd9a8 in ?? ()
> #9  0x0000000000000001 in ?? ()
> #10 0x00007fffffffd9a8 in ?? ()
> #11 0x00007ffff567f5bb in _init () from
> /spidermonkey/js76_debug/lib/libmozjs-76.so
>
>
> I presumed I was doing something wrong so I went back to trying to run the
> simplest program I could think of using the JS API
>
> #include "jsapi.h"
> #include "js/Initialization.h"
>
> int main(int argc, const char *argv[])
> {
>     JS_Init();
>     JS_ShutDown();
>     exit(0);
> }
>
> and I'm compiling that with something like
>
> g++ -std=gnu++17
> -include=/spidermonkey/js76_release/include/mozjs-76/js/RequiredDefines.h
> -I/spidermonkey/js76_release/include/mozjs-76 -O -pthread test.cpp -o test
> -rdynamic -lm -ldl -lpthread -lrt -lz -L/spidermonkey/js76_release/lib
> -lmozjs-76
>
> and that still crashes in exactly the same way.
>
> So I then commented out the JS_Init() and JS_ShutDown() calls (but still
> link the executable with -lmozjs-76)
>
> and it *still* crashes.
>
> If I remove  -lmozjs-76 from the linker the program runs (but obviously
> then doesn't do anything!)
>
> I'm compiling this on an old CentOS 6 machine so the installed g++
> compilers are ancient. I compiled g++ 9.3 from source and that's what I
> used to build.
>
> I successfully managed to build mozjs-76 and the JS shell and the test
> suite all ran OK and passed so the JS shell clearly works OK using the
> compilers I used.
>
> I've spent the last few days trying to understand why the shell works OK
> but my executable doesn't.
> One difference was that the shell linked to libjs_static.a and libjsrust.a
> instead of libmozjs-76.so so I tried linking statically instead of using
> the shared library but I still get the same crash.
>
> I presume I'm somehow getting some sort of incompatibility when the
> library is being initialised but I'm completely at a loss as to why the JS
> shell works but it crashes for me. There must be *something* that I'm doing
> wrong...
> I hope I'm just being really stupid and missing something.
> Can anybody help?
>
> Many thanks
>
> Miles
> _______________________________________________
> dev-tech-js-engine mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>