From e59abc05a9903f35a08391ae58b545cf89e98544 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 29 May 2024 15:14:55 -0700 Subject: [PATCH] Re-enable extern-pre-js and extern-post-js under pthreads In #21701 the running of extern-pre/post-js in pthreads was disabled. The reason was that we had a couple of tests that seemed to be assuming this. However, it turns out that there are important use cases that depend on this code running in threads. Instead, fix the two test cases by adding an extra condition. Fixes: #22012 --- test/test_core.py | 2 +- test/test_other.py | 2 +- tools/link.py | 12 +----------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/test/test_core.py b/test/test_core.py index bc4bff60bdea8..c6935343ca016 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -9268,7 +9268,7 @@ def test_pthread_offset_converter_modularize(self): self.set_setting('USE_OFFSET_CONVERTER') self.set_setting('MODULARIZE') self.set_setting('EXPORT_NAME', 'foo') - create_file('post.js', 'foo();') + create_file('post.js', 'if (!isPthread) foo();') self.emcc_args += ['--extern-post-js', 'post.js'] if '-g' in self.emcc_args: self.emcc_args += ['-DDEBUG'] diff --git a/test/test_other.py b/test/test_other.py index 242ce132b3fe4..22099949437de 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -366,7 +366,7 @@ def test_emcc_output_mjs(self, args): }) @node_pthreads def test_emcc_output_worker_mjs(self, args): - create_file('extern-post.js', 'await Module();') + create_file('extern-post.js', 'if (!isPthread) await Module();') os.mkdir('subdir') self.run_process([EMCC, '-o', 'subdir/hello_world.mjs', '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '-O1', diff --git a/tools/link.py b/tools/link.py index 09d1496910585..cbaf1f4d30461 100644 --- a/tools/link.py +++ b/tools/link.py @@ -677,13 +677,6 @@ def phase_linker_setup(options, state, newargs): options.extern_pre_js = read_js_files(options.extern_pre_js) options.extern_post_js = read_js_files(options.extern_post_js) - if settings.PTHREADS: - # Don't run extern pre/post code on pthreads. - if options.extern_pre_js: - options.extern_pre_js = 'if (!isPthread) {' + options.extern_pre_js + '}' - if options.extern_post_js: - options.extern_post_js = 'if (!isPthread) {' + options.extern_post_js + '}' - # TODO: support source maps with js_transform if options.js_transform and settings.GENERATE_SOURCE_MAP: logger.warning('disabling source maps because a js transform is being done') @@ -2109,8 +2102,6 @@ def phase_final_emitting(options, state, target, wasm_target): src = read_file(final_js) final_js += '.epp.js' with open(final_js, 'w', encoding='utf-8') as f: - if settings.PTHREADS and (options.extern_pre_js or options.extern_post_js): - f.write(make_pthread_detection()) f.write(options.extern_pre_js) f.write(src) f.write(options.extern_post_js) @@ -2461,8 +2452,7 @@ def modularize(options): ''' % {'EXPORT_NAME': settings.EXPORT_NAME} if settings.PTHREADS: - if not options.extern_pre_js and not options.extern_post_js: - src += make_pthread_detection() + src += make_pthread_detection() src += '// When running as a pthread, construct a new instance on startup\n' src += 'isPthread && %s();\n' % settings.EXPORT_NAME