Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Segfault with 1.70 or svn and thread safe libjs

For discussion of ports to POSIX based systems, especially using GNUStep.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
wstephenson
Poor
Poor
Posts: 4
Joined: Wed Feb 13, 2008 10:08 am

Segfault with 1.70 or svn and thread safe libjs

Post by wstephenson »

Hi all

In case anyone else tries to build recent oolite against their own libjs and sees a segfault on startup, here's my diagnosis.

This might be due to libjs being built with JS_THREADSAFE, which adds a JSContext * arg to the JS_GetClass function - and oolite doesn't supply this. The remedy is to build libjs without JS_THREADSAFE. The packman libjs1, libjs-devel rpms available for openSUSE do define JS_THREADSAFE.

Sample stderr:

Code: Select all

2008-02-13 10:35:19.191 oolite.debug[10401] [dataCache.notFound]: No data cache found, starting from scratch.
2008-02-13 10:35:19.192 oolite.debug[10401] Failed to recurse into directory 'AddOns' - No such file or directory
2008-02-13 10:35:19.193 oolite.debug[10401] Failed to recurse into directory '/home/will/.Oolite/AddOns' - No such file or directory
2008-02-13 10:35:19.193 oolite.debug[10401] [searchPaths.dumpAll]: ---> OXP search paths:
("/home/will/code/oolite-dev-source-1.70/oolite.debug.app/Resources", AddOns, "/home/will/.Oolite/AddOns")
[New Thread 0x4108a950 (LWP 10405)]

Program received signal SIGSEGV, Segmentation fault.
Backtrace:

Code: Select all

[Switching to Thread 0x2ba8fbedcf70 (LWP 10401)]
JS_GetClass (cx=0x1678ee0, obj=0x36c) at jsapi.c:2251
2251        return (JSClass *)
Current language:  auto; currently c
(gdb) bt
#0  JS_GetClass (cx=0x1678ee0, obj=0x36c) at jsapi.c:2251
#1  0x000000000057b678 in RegisterStandardObjectConverters (context=0x1673780)
    at src/Core/Scripting/OOJavaScriptEngine.m:1201
#2  0x0000000000578458 in -[OOJavaScriptEngine init] (self=0x166a400, _cmd=0x87c0e0)
    at src/Core/Scripting/OOJavaScriptEngine.m:200
#3  0x0000000000578223 in +[OOJavaScriptEngine sharedEngine] (self=0x87bfc0, _cmd=0x879f30)
    at src/Core/Scripting/OOJavaScriptEngine.m:140
#4  0x0000000000575e23 in -[OOJSScript initWithPath:properties:] (self=0x16690e0, _cmd=0x879f00,
    path=0x16686c0, properties=0x0) at src/Core/Scripting/OOJSScript.m:126
#5  0x0000000000575d15 in +[OOJSScript scriptWithPath:properties:] (self=0x879e60, _cmd=0x8788d0,
    path=0x16686c0, properties=0x0) at src/Core/Scripting/OOJSScript.m:108
#6  0x000000000057535f in +[OOScript scriptsFromFileAtPath:] (self=0x878800, _cmd=0x878930,
    filePath=0x16686c0) at src/Core/Scripting/OOScript.m:173
#7  0x0000000000574fb3 in +[OOScript scriptsFromFileNamed:] (self=0x878800, _cmd=0x878960,
    fileName=0x15b6770) at src/Core/Scripting/OOScript.m:135
#8  0x000000000057514f in +[OOScript scriptsFromList:] (self=0x878800, _cmd=0x8788b0, fileNames=0x15b6650)
    at src/Core/Scripting/OOScript.m:155
#9  0x0000000000574a02 in +[OOScript worldScriptsAtPath:] (self=0x878800, _cmd=0x843fd0, path=0x15b65a0)
    at src/Core/Scripting/OOScript.m:65
#10 0x00000000004b2e5e in +[ResourceManager loadScripts] (self=0x843b00, _cmd=0x840ee0)
    at src/Core/ResourceManager.m:704
#11 0x000000000048bbcf in -[PlayerEntity init] (self=0xf30230, _cmd=0x85ffc0)
    at src/Core/Entities/PlayerEntity.m:805
#12 0x0000000000503bb3 in -[Universe initWithGameView:] (self=0xc79bd0, _cmd=0x81ba60, inGameView=0xa3e640)
    at src/Core/Universe.m:237
#13 0x000000000041f303 in -[GameController applicationDidFinishLaunching:] (self=0xa51ce0, _cmd=0x820b90,
    notification=0x0) at src/Core/GameController.m:227
#14 0x0000000000438bba in main (argc=1, argv=0x7fffb522aef8) at src/SDL/main.m:88
Crash at

Code: Select all

(gdb) l
2246
2247    #ifdef JS_THREADSAFE
2248    JS_PUBLIC_API(JSClass *)
2249    JS_GetClass(JSContext *cx, JSObject *obj)
2250    {
2251        return (JSClass *)
2252            JSVAL_TO_PRIVATE(GC_AWARE_GET_SLOT(cx, obj, JSSLOT_CLASS));
2253    }
2254    #else
2255    JS_PUBLIC_API(JSClass *)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Correct. There is a similar issue with MOZILLA_1_8_BRANCH, which must either be defined or undefined for both the library and Oolite, because it changes struct layouts.

Additionally, SpiderMonkey must be built with JS_C_STRINGS_ARE_UTF8 defined. Oolite checks for this at runtime (unless NDEBUG is defined), but the others can’t be tested for in an obvious way.
User avatar
wstephenson
Poor
Poor
Posts: 4
Joined: Wed Feb 13, 2008 10:08 am

Post by wstephenson »

Yeah, I read about both these issues on the forums and spent a good while ensuring that these weren't involved. SVN runs nicely now, I haven't rebuilt 1.70 yet.

It would be worth including the local copy of libjs in the _build_ so a correctly configured libjs is always available on all platforms. FWIW, both the separate libjs provided by Packman, and the various mozilla packages on openSUSE configure their *js with JS_THREADSAFE and without JS_C_STRINGS_ARE_UTF8.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

The source for SpiderMonkey/libjs is included in the repository at deps/Cross-platform-deps/SpiderMonkey, because at the time there was no up-to-date tarball available (and I didn’t realize just how big it was; libjs is about half of Oolite’s code base). However, building it requires using its own makefile so that platform-specific things are set up properly.

Driving this build from the Oolite GNUmakefile would be nice, but I can’t do it because I’m not familiar with GNUmake and don’t use it to build on the Mac. A patch would be welcome…
User avatar
wstephenson
Poor
Poor
Posts: 4
Joined: Wed Feb 13, 2008 10:08 am

Post by wstephenson »

Am I right in thinking the GNUmakefile is used on *nix but not OS X or Windows?
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

It’s used for Windows.
Post Reply