Skip to content

Commit

Permalink
Split the pthread library out of libc
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Oct 15, 2024
1 parent 2559ddc commit 086be0b
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 115 deletions.
3 changes: 2 additions & 1 deletion embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
'crtbegin',
'libsanitizer_common_rt',
'libubsan_rt',
'libwasm_workers_stub-debug',
'libwasm_workers-debug-stub',
'libpthread-debug-stub',
'libfetch',
'libfetch-mt',
'libwasmfs',
Expand Down
4 changes: 2 additions & 2 deletions test/other/codesize/test_codesize_minimal_pthreads.funcs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$__emscripten_stdout_close
$__emscripten_stdout_seek
$__errno_location
$__memcpy
$__memset
$__pthread_getspecific
Expand Down Expand Up @@ -67,6 +67,7 @@ $em_task_queue_free
$em_task_queue_is_empty
$emscripten_builtin_free
$emscripten_builtin_malloc
$emscripten_builtin_memalign
$emscripten_current_thread_process_queued_calls
$emscripten_futex_wait
$emscripten_futex_wake
Expand All @@ -80,7 +81,6 @@ $init_mparams
$lock
$main
$nodtor
$pthread_attr_destroy
$pthread_cond_signal
$pthread_mutex_destroy
$pthread_setspecific
Expand Down
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_pthreads.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19480
19950
6 changes: 3 additions & 3 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4625,10 +4625,10 @@ def test_dylink_postsets_chunking(self):

@with_dylink_reversed
@parameterized({
'libcxx': ('libc,libc++,libmalloc,libc++abi',),
'libcxx': ('libc,libpthread,libc++,libmalloc,libc++abi',),
'all': ('1',),
'missing': ('libc,libmalloc,libc++abi', False, False, False),
'missing_assertions': ('libc,libmalloc,libc++abi', False, False, True),
'missing': ('libc,libpthread,libmalloc,libc++abi', False, False, False),
'missing_assertions': ('libc,libpthread,libmalloc,libc++abi', False, False, True),
})
def test_dylink_syslibs(self, syslibs, expect_pass=True, with_reversed=True, assertions=True):
# one module uses libcxx, need to force its inclusion when it isn't the main
Expand Down
13 changes: 7 additions & 6 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -6007,9 +6007,9 @@ def test_bad_lookup(self):
# partial list, but ok since we grab them as needed
'parial': [{'EMCC_FORCE_STDLIBS': 'libc++'}, False],
# fail! not enough stdlibs
'partial_only': [{'EMCC_FORCE_STDLIBS': 'libc++,libc,libc++abi', 'EMCC_ONLY_FORCED_STDLIBS': '1'}, True],
'partial_only': [{'EMCC_FORCE_STDLIBS': 'libc++,libc,libpthread,libc++abi', 'EMCC_ONLY_FORCED_STDLIBS': '1'}, True],
# force all the needed stdlibs, so this works even though we ignore the input file
'full_only': [{'EMCC_FORCE_STDLIBS': 'libc,libc++abi,libc++,libmalloc', 'EMCC_ONLY_FORCED_STDLIBS': '1'}, False],
'full_only': [{'EMCC_FORCE_STDLIBS': 'libc,libpthread,libc++abi,libc++,libmalloc', 'EMCC_ONLY_FORCED_STDLIBS': '1'}, False],
})
def test_only_force_stdlibs(self, env, fail):
cmd = [EMXX, test_file('hello_libcxx.cpp')]
Expand Down Expand Up @@ -6040,7 +6040,7 @@ def test_only_force_stdlibs_2(self):
}
}
''')
with env_modify({'EMCC_FORCE_STDLIBS': 'libc,libc++abi,libc++,libmalloc', 'EMCC_ONLY_FORCED_STDLIBS': '1'}):
with env_modify({'EMCC_FORCE_STDLIBS': 'libc,libpthread,libc++abi,libc++,libmalloc', 'EMCC_ONLY_FORCED_STDLIBS': '1'}):
self.run_process([EMXX, 'src.cpp', '-sDISABLE_EXCEPTION_CATCHING=0'])
self.assertContained('Caught exception: std::exception', self.run_js('a.out.js'))

Expand Down Expand Up @@ -12286,10 +12286,10 @@ def test_nostdlib(self):
self.assertContained(err, self.expect_fail([EMCC, test_file('unistd/close.c'), '-nodefaultlibs']))

# Build again but with explit system libraries
libs = ['-lc', '-lcompiler_rt']
libs = ['-lc', '-lpthread', '-lcompiler_rt']
self.run_process([EMCC, test_file('unistd/close.c'), '-nostdlib'] + libs)
self.run_process([EMCC, test_file('unistd/close.c'), '-nodefaultlibs'] + libs)
self.run_process([EMCC, test_file('unistd/close.c'), '-nolibc', '-lc'])
self.run_process([EMCC, test_file('unistd/close.c'), '-nolibc', '-lc', '-lpthread'])
self.run_process([EMCC, test_file('unistd/close.c'), '-nostartfiles'])

def test_argument_match(self):
Expand Down Expand Up @@ -13183,12 +13183,13 @@ def test_offset_convertor_plus_wasm2js(self):

def test_standard_library_mapping(self):
# Test the `-l` flags on the command line get mapped the correct libraries variant
libs = ['-lc', '-lbulkmemory', '-lcompiler_rt', '-lmalloc']
libs = ['-lc', '-lpthread', '-lbulkmemory', '-lcompiler_rt', '-lmalloc']
err = self.run_process([EMCC, test_file('hello_world.c'), '-pthread', '-nodefaultlibs', '-v'] + libs, stderr=PIPE).stderr

# Check that the linker was run with `-mt` variants because `-pthread` was passed.
self.assertContained(' -lc-mt-debug ', err)
self.assertContained(' -ldlmalloc-mt ', err)
self.assertContained(' -lpthread-debug ', err)
self.assertContained(' -lcompiler_rt-mt ', err)

def test_explicit_gl_linking(self):
Expand Down
1 change: 0 additions & 1 deletion tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -2721,7 +2721,6 @@ def map_to_js_libs(library_name):
'dl': [],
'm': [],
'rt': [],
'pthread': [],
# This is the name of GNU's C++ standard library. We ignore it here
# for compatibility with GNU toolchains.
'stdc++': [],
Expand Down
Loading

0 comments on commit 086be0b

Please sign in to comment.