Skip to content

Commit ac63194

Browse files
committed
Error at link time if dlfcn functions are used without MAIN_MODULE
Only if ALLOW_UNIMPLEMENTED_SYSCALLS (which is also set by STRICT) is used. This was previously only ever a runtime error. Should help with #15276 (comment)
1 parent 44bbc35 commit ac63194

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/jsifier.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ function ${name}(${args}) {
322322
// foo: '=[value]'
323323
// emits
324324
// 'var foo = [value];'
325-
if (typeof snippet === 'string' && snippet[0] == '=') snippet = snippet.substr(1);
325+
if (typeof snippet === 'string' && snippet[0] == '=') {
326+
snippet = snippet.substr(1);
327+
}
326328
contentText = `var ${finalName} = ${snippet};`;
327329
}
328330
var sig = LibraryManager.library[ident + '__sig'];

src/library_dylink.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//
44
// ==========================================================================
55

6+
var dlopenMissingError = "'To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking'"
7+
68
var LibraryDylink = {
79
#if RELOCATABLE
810
$resolveGlobalSymbol__internal: true,
@@ -188,14 +190,24 @@ var LibraryDylink = {
188190
#endif
189191

190192
#if MAIN_MODULE == 0
193+
#if !ALLOW_UNIMPLEMENTED_SYSCALLS
194+
_dlopen_js__deps: [function() { error(dlopenMissingError); }],
195+
_emscripten_dlopen_js__deps: [function() { error(dlopenMissingError); }],
196+
_dlsym_js__deps: [function() { error(dlopenMissingError); }],
197+
#else
198+
$dlopenMissingError: `= ${dlopenMissingError}`,
199+
_dlopen_js__deps: ['$dlopenMissingError'],
200+
_emscripten_dlopen_js__deps: ['$dlopenMissingError'],
201+
_dlsym_js__deps: ['$dlopenMissingError'],
202+
#endif
191203
_dlopen_js: function(filename, flag) {
192-
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking");
204+
abort(dlopenMissingError);
193205
},
194206
_emscripten_dlopen_js: function(filename, flags, user_data, onsuccess, onerror) {
195-
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking");
207+
abort(dlopenMissingError);
196208
},
197209
_dlsym_js: function(handle, symbol) {
198-
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking");
210+
abort(dlopenMissingError);
199211
},
200212
#else // MAIN_MODULE != 0
201213
// dynamic linker/loader (a-la ld.so on ELF systems)

0 commit comments

Comments
 (0)