Skip to content

Commit 508bcb0

Browse files
authored
Use createNamedFunction in the dynamic linker (#25411)
This helps with debugging since the runtime-generated functions show up in backtraces with meaningful names.
1 parent 16ce719 commit 508bcb0

10 files changed

+29
-27
lines changed

src/lib/libcore.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ addToLibrary({
4141
setTempRet0: '$setTempRet0',
4242
getTempRet0: '$getTempRet0',
4343

44+
// Assign a name to a given function. This is mostly useful for debugging
45+
// purposes in cases where new functions are created at runtime.
46+
$createNamedFunction: (name, func) => Object.defineProperty(func, 'name', { value: name }),
47+
4448
$ptrToString: (ptr) => {
4549
#if ASSERTIONS
4650
assert(typeof ptr === 'number', `ptrToString expects a number, got ${typeof ptr}`);

src/lib/libdylink.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ var LibraryDylink = {
116116
// the canonical name of the symbol (in some cases is modify the symbol as
117117
// part of the loop process, so that actual symbol looked up has a different
118118
// name).
119-
$resolveGlobalSymbol__deps: ['$isSymbolDefined',
119+
$resolveGlobalSymbol__deps: ['$isSymbolDefined', '$createNamedFunction',
120120
#if !DISABLE_EXCEPTION_CATCHING || SUPPORT_LONGJMP == 'emscripten'
121121
'$createInvokeFunction',
122122
#endif
@@ -138,7 +138,7 @@ var LibraryDylink = {
138138
// Asm.js-style exception handling: invoke wrapper generation
139139
else if (symName.startsWith('invoke_')) {
140140
// Create (and cache) new invoke_ functions on demand.
141-
sym = wasmImports[symName] = createInvokeFunction(symName.split('_')[1]);
141+
sym = wasmImports[symName] = createNamedFunction(symName, createInvokeFunction(symName.split('_')[1]));
142142
}
143143
#endif
144144
#if !DISABLE_EXCEPTION_CATCHING
@@ -147,13 +147,13 @@ var LibraryDylink = {
147147
// `__cxa_find_matching_catch_` (see jsifier.js) that we know are needed,
148148
// but a side module loaded at runtime might need different/additional
149149
// variants so we create those dynamically.
150-
sym = wasmImports[symName] = (...args) => {
150+
sym = wasmImports[symName] = createNamedFunction(symName, (...args) => {
151151
#if MEMORY64
152152
args = args.map(Number);
153153
#endif
154154
var rtn = findMatchingCatch(args);
155155
return {{{ to64('rtn') }}};
156-
}
156+
});
157157
}
158158
#endif
159159
return {sym, name: symName};

src/lib/libembind.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ var LibraryEmbind = {
122122
}
123123
},
124124

125-
$createNamedFunction: (name, func) => Object.defineProperty(func, 'name', { value: name }),
126-
127125
$embindRepr: (v) => {
128126
if (v === null) {
129127
return 'null';

src/lib/libembind_gen.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ var LibraryEmbind = {
870870
// Stub functions used by eval, but not needed for TS generation:
871871
$makeLegalFunctionName: () => { throw new Error('stub function should not be called'); },
872872
$runDestructors: () => { throw new Error('stub function should not be called'); },
873-
$createNamedFunction: () => { throw new Error('stub function should not be called'); },
874873
$flushPendingDeletes: () => { throw new Error('stub function should not be called'); },
875874
$setDelayFunction: () => { throw new Error('stub function should not be called'); },
876875
$PureVirtualError: () => { throw new Error('stub function should not be called'); },

test/codesize/test_codesize_hello_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 22458,
3-
"a.out.js.gz": 8308,
2+
"a.out.js": 22478,
3+
"a.out.js.gz": 8314,
44
"a.out.nodebug.wasm": 15127,
55
"a.out.nodebug.wasm.gz": 7450,
6-
"total": 37585,
7-
"total_gz": 15758,
6+
"total": 37605,
7+
"total_gz": 15764,
88
"sent": [
99
"fd_write"
1010
],

test/codesize/test_codesize_hello_dylink.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 26946,
3-
"a.out.js.gz": 11478,
2+
"a.out.js": 26985,
3+
"a.out.js.gz": 11495,
44
"a.out.nodebug.wasm": 18567,
55
"a.out.nodebug.wasm.gz": 9199,
6-
"total": 45513,
7-
"total_gz": 20677,
6+
"total": 45552,
7+
"total_gz": 20694,
88
"sent": [
99
"__heap_base",
1010
"__indirect_function_table",

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 245989,
2+
"a.out.js": 246028,
33
"a.out.nodebug.wasm": 597755,
4-
"total": 843744,
4+
"total": 843783,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

test/codesize/test_codesize_minimal_O0.expected.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
877877
'stackAlloc',
878878
'getTempRet0',
879879
'setTempRet0',
880+
'createNamedFunction',
880881
'zeroMemory',
881882
'exitJS',
882883
'getHeapMax',

test/codesize/test_codesize_minimal_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 17734,
3-
"a.out.js.gz": 6610,
2+
"a.out.js": 17754,
3+
"a.out.js.gz": 6617,
44
"a.out.nodebug.wasm": 1136,
55
"a.out.nodebug.wasm.gz": 659,
6-
"total": 18870,
7-
"total_gz": 7269,
6+
"total": 18890,
7+
"total_gz": 7276,
88
"sent": [],
99
"imports": [],
1010
"exports": [
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"hello_world.js": 54108,
3-
"hello_world.js.gz": 17086,
2+
"hello_world.js": 54133,
3+
"hello_world.js.gz": 17091,
44
"hello_world.wasm": 15127,
55
"hello_world.wasm.gz": 7450,
66
"no_asserts.js": 26513,
77
"no_asserts.js.gz": 8864,
88
"no_asserts.wasm": 12227,
99
"no_asserts.wasm.gz": 6010,
10-
"strict.js": 52146,
11-
"strict.js.gz": 16420,
10+
"strict.js": 52171,
11+
"strict.js.gz": 16426,
1212
"strict.wasm": 15127,
1313
"strict.wasm.gz": 7447,
14-
"total": 175248,
15-
"total_gz": 63277
14+
"total": 175298,
15+
"total_gz": 63288
1616
}

0 commit comments

Comments
 (0)