Skip to content

Commit e816e8c

Browse files
committed
NFC Factor out common code between updateGOT and reportUndefinedSymbols
Suggested in discussion on emscripten-core#22053
1 parent 82b0d74 commit e816e8c

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

src/library_dylink.js

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,30 @@ var LibraryDylink = {
201201
#endif
202202
;
203203
},
204+
$setGOTEntry__deps: ['$addFunction', '$getFunctionAddress'],
205+
$setGOTEntry: (symName, value) => {
206+
const entry = GOT[symName];
207+
#if DYLINK_DEBUG == 2
208+
dbg(`setGOTEntry: before: ${symName} : ${entry.value}`);
209+
#endif
210+
if (typeof value == 'function') {
211+
entry.value = {{{ to64('addFunction(value, value.sig)') }}};
212+
} else if (typeof value == 'number') {
213+
entry.value = {{{ to64('value') }}};
214+
#if MEMORY64
215+
} else if (typeof value == 'bigint') {
216+
entry.value = value;
217+
#endif
218+
} else {
219+
throw new Error(`bad export type for '${symName}': ${typeof value}`);
220+
}
221+
#if DYLINK_DEBUG == 2
222+
dbg(`setGOTEntry: after: ${symName} ${typeof value}: ${entry.value} (${value})`);
223+
#endif
224+
},
204225

205226
$updateGOT__internal: true,
206-
$updateGOT__deps: ['$GOT', '$isInternalSym', '$addFunction', '$getFunctionAddress'],
227+
$updateGOT__deps: ['$GOT', '$isInternalSym', '$setGOTEntry'],
207228
$updateGOT: (exports, replace) => {
208229
#if DYLINK_DEBUG
209230
dbg("updateGOT: adding " + Object.keys(exports).length + " symbols");
@@ -223,22 +244,7 @@ var LibraryDylink = {
223244

224245
GOT[symName] ||= new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}', 'mutable': true});
225246
if (replace || GOT[symName].value == 0) {
226-
#if DYLINK_DEBUG == 2
227-
dbg(`updateGOT: before: ${symName} : ${GOT[symName].value}`);
228-
#endif
229-
if (typeof value == 'function') {
230-
GOT[symName].value = {{{ to64('addFunction(value)') }}};
231-
#if DYLINK_DEBUG == 2
232-
dbg(`updateGOT: FUNC: ${symName} : ${GOT[symName].value}`);
233-
#endif
234-
} else if (typeof value == {{{ POINTER_JS_TYPE }}}) {
235-
GOT[symName].value = value;
236-
} else {
237-
err(`unhandled export type for '${symName}': ${typeof value}`);
238-
}
239-
#if DYLINK_DEBUG == 2
240-
dbg(`updateGOT: after: ${symName} : ${GOT[symName].value} (${value})`);
241-
#endif
247+
setGOTEntry(symName, value);
242248
}
243249
#if DYLINK_DEBUG
244250
else if (GOT[symName].value != value) {
@@ -303,21 +309,7 @@ var LibraryDylink = {
303309
#if DYLINK_DEBUG == 2
304310
dbg(`assigning dynamic symbol from main module: ${symName} -> ${prettyPrint(value)}`);
305311
#endif
306-
if (typeof value == 'function') {
307-
/** @suppress {checkTypes} */
308-
entry.value = {{{ to64('addFunction(value, value.sig)') }}};
309-
#if DYLINK_DEBUG == 2
310-
dbg(`assigning table entry for : ${symName} -> ${entry.value}`);
311-
#endif
312-
} else if (typeof value == 'number') {
313-
entry.value = {{{ to64('value') }}};
314-
#if MEMORY64
315-
} else if (typeof value == 'bigint') {
316-
entry.value = value;
317-
#endif
318-
} else {
319-
throw new Error(`bad export type for '${symName}': ${typeof value}`);
320-
}
312+
setGOTEntry(symName, value);
321313
}
322314
}
323315
#if DYLINK_DEBUG

0 commit comments

Comments
 (0)