Skip to content

Commit c38391a

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 e6cc0b2 commit c38391a

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/jsifier.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ function ${name}(${args}) {
325325
// foo: '=[value]'
326326
// emits
327327
// 'var foo = [value];'
328-
if (typeof snippet == 'string' && snippet[0] == '=') snippet = snippet.substr(1);
328+
if (typeof snippet == 'string' && snippet[0] == '=') {
329+
snippet = snippet.substr(1);
330+
}
329331
contentText = `var ${finalName} = ${snippet};`;
330332
}
331333
const 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,
@@ -199,14 +201,24 @@ var LibraryDylink = {
199201
#endif
200202

201203
#if !MAIN_MODULE
204+
#if !ALLOW_UNIMPLEMENTED_SYSCALLS
205+
_dlopen_js__deps: [function() { error(dlopenMissingError); }],
206+
_emscripten_dlopen_js__deps: [function() { error(dlopenMissingError); }],
207+
_dlsym_js__deps: [function() { error(dlopenMissingError); }],
208+
#else
209+
$dlopenMissingError: `= ${dlopenMissingError}`,
210+
_dlopen_js__deps: ['$dlopenMissingError'],
211+
_emscripten_dlopen_js__deps: ['$dlopenMissingError'],
212+
_dlsym_js__deps: ['$dlopenMissingError'],
213+
#endif
202214
_dlopen_js: function(filename, flag) {
203-
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking");
215+
abort(dlopenMissingError);
204216
},
205217
_emscripten_dlopen_js: function(filename, flags, user_data, onsuccess, onerror) {
206-
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking");
218+
abort(dlopenMissingError);
207219
},
208220
_dlsym_js: function(handle, symbol) {
209-
abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking");
221+
abort(dlopenMissingError);
210222
},
211223
_dlinit: function() {},
212224
#else // MAIN_MODULE != 0

tests/test_other.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11351,6 +11351,18 @@ def test_unimplemented_syscalls(self, args):
1135111351
err = self.run_js('a.out.js')
1135211352
self.assertNotContained('warning: unsupported syscall', err)
1135311353

11354+
def test_unimplemented_syscalls_dlopen(self):
11355+
cmd = [EMCC, test_file('other/test_dlopen_blocking.c'), '-sASSERTIONS']
11356+
self.run_process(cmd)
11357+
err = self.run_js('a.out.js', assert_returncode=NON_ZERO)
11358+
self.assertContained('Aborted(To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking)', err)
11359+
11360+
# If we build the same thing with ALLOW_UNIMPLEMENTED_SYSCALLS we
11361+
# expect a link-time failure rather than a runtime one.
11362+
cmd += ['-sALLOW_UNIMPLEMENTED_SYSCALLS=0']
11363+
err = self.expect_fail(cmd)
11364+
self.assertContained('To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking', err)
11365+
1135411366
@require_v8
1135511367
def test_missing_shell_support(self):
1135611368
# By default shell support is not included

0 commit comments

Comments
 (0)