Skip to content

Commit 982138e

Browse files
authored
Improve DYLINK_DEBUG. NFC (emscripten-core#15164)
Debugging improvements split out from a PR I'm working on for dlopen + threads.
1 parent c059ad9 commit 982138e

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ WASM_EXPORTS = set(WASM_EXPORTS);
7070
SIDE_MODULE_EXPORTS = set(SIDE_MODULE_EXPORTS);
7171
INCOMING_MODULE_JS_API = set(INCOMING_MODULE_JS_API);
7272

73-
RUNTIME_DEBUG = LIBRARY_DEBUG || GL_DEBUG;
73+
RUNTIME_DEBUG = LIBRARY_DEBUG || GL_DEBUG || DYLINK_DEBUG;
7474

7575
// Side modules are pure wasm and have no JS
7676
assert(!SIDE_MODULE, "JS compiler should not run on side modules");

src/library_dylink.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ var LibraryDylink = {
5858
'__cpp_exception',
5959
'__wasm_apply_data_relocs',
6060
'__dso_handle',
61-
'__set_stack_limits'
61+
'__tls_size',
62+
'__tls_align',
63+
'__set_stack_limits',
64+
'emscripten_tls_init',
65+
'__wasm_init_tls',
66+
'__wasm_call_ctors',
6267
].includes(symName)
6368
#if SPLIT_MODULE
6469
// Exports synthesized by wasm-split should be prefixed with '%'
@@ -70,7 +75,7 @@ var LibraryDylink = {
7075
$updateGOT__deps: ['$GOT', '$isInternalSym'],
7176
$updateGOT: function(exports, replace) {
7277
#if DYLINK_DEBUG
73-
err("updateGOT: " + Object.keys(exports).length);
78+
err("updateGOT: adding " + Object.keys(exports).length + " symbols");
7479
#endif
7580
for (var symName in exports) {
7681
if (isInternalSym(symName)) {
@@ -92,7 +97,7 @@ var LibraryDylink = {
9297
if (typeof value === 'function') {
9398
GOT[symName].value = addFunctionWasm(value);
9499
#if DYLINK_DEBUG
95-
err("updateGOT FUNC: " + symName + ' : ' + GOT[symName].value);
100+
err("updateGOT: FUNC: " + symName + ' : ' + GOT[symName].value);
96101
#endif
97102
} else if (typeof value === 'number') {
98103
GOT[symName].value = value;
@@ -154,7 +159,7 @@ var LibraryDylink = {
154159
assert(value, 'undefined symbol `' + symName + '`. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment');
155160
#endif
156161
#if DYLINK_DEBUG
157-
err('assigning dynamic symbol from main module: ' + symName + ' -> ' + value);
162+
err('assigning dynamic symbol from main module: ' + symName + ' -> ' + prettyPrint(value));
158163
#endif
159164
if (typeof value === 'function') {
160165
GOT[symName].value = addFunctionWasm(value, value.sig);
@@ -615,6 +620,9 @@ var LibraryDylink = {
615620
// Once a library becomes "global" or "nodelete", it cannot be removed or unloaded.
616621
$loadDynamicLibrary__deps: ['$LDSO', '$loadWebAssemblyModule', '$asmjsMangle', '$isInternalSym', '$mergeLibSymbols'],
617622
$loadDynamicLibrary: function(lib, flags) {
623+
#if DYLINK_DEBUG
624+
err("loadDynamicLibrary: " + lib);
625+
#endif
618626
if (lib == '__main__' && !LDSO.loadedLibNames[lib]) {
619627
LDSO.loadedLibs[-1] = {
620628
refcount: Infinity, // = nodelete
@@ -714,13 +722,19 @@ var LibraryDylink = {
714722
}
715723

716724
if (flags.loadAsync) {
725+
#if DYLINK_DEBUG
726+
err("loadDynamicLibrary: done (async)");
727+
#endif
717728
return getLibModule().then(function(libModule) {
718729
moduleLoaded(libModule);
719730
return handle;
720731
});
721732
}
722733

723734
moduleLoaded(getLibModule());
735+
#if DYLINK_DEBUG
736+
err("loadDynamicLibrary: done");
737+
#endif
724738
return handle;
725739
},
726740

src/library_pthread.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ var LibraryPThread = {
510510
#if DYLINK_DEBUG
511511
err('tlsInit -> ' + __tls_base);
512512
#endif
513+
if (!__tls_base) {
514+
#if ASSERTIONS
515+
// __tls_base should never be zero if there are tls exports
516+
assert(__tls_base || Object.keys(metadata.tlsExports).length == 0);
517+
#endif
518+
return;
519+
}
513520
for (var sym in metadata.tlsExports) {
514521
metadata.tlsExports[sym] = moduleExports[sym];
515522
}

src/runtime_debug.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ function prettyPrint(arg) {
4545
ret += 'f32:' + arr.toString().replace(/,/g, ',') + '}';
4646
return ret;
4747
}
48-
if (typeof arg == 'object') {
48+
if (typeof arg === 'function') {
49+
return '<function>';
50+
} else if (typeof arg === 'object') {
4951
printObjectList.push(arg);
5052
return '<' + arg + '|' + (printObjectList.length-1) + '>';
51-
}
52-
if (typeof arg == 'number') {
53+
} else if (typeof arg === 'number') {
5354
if (arg > 0) return '0x' + arg.toString(16) + ' (' + arg + ')';
5455
}
5556
return arg;

0 commit comments

Comments
 (0)