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

Miles <[email protected]> Tue, 19 May 2020 09:24:51 -0700 (PDT)
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
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