Repository navigation
Conversation
Main modules and side modules share the `pic` library directory, but `dynlink.c` was added to libc only under `-sMAIN_MODULE`. A side module linked with an explicit `-lc` builds libc too, so when such a link was the first one to populate the cache, `pic/libc.a` was cached without `dlopen`, `__dlsym` and `_emscripten_find_dylib`, and every later `-sMAIN_MODULE` link failed with undefined symbols until the cache was cleared. This happens in the test suite on a clean cache when a failing `core0.test_dylink_zlib_configure` is retried: zlib's Makefile links `libz.so` with `-lc`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
I think this should be avoided. See e.g. #16680 (comment) and PR rust-lang/libc#4002. |
|
Thanks, that's interesting comment. This issue happens in the existing core test suite. Depending on the order of the test run, the dynlink.c function would end up being missing. Even if that use case is not intended, what do you think of the fix itself? |
|
E.g. |
|
With commit madler/zlib@8dcc311, I think you could do: --- a/test/common.py
+++ b/test/common.py
@@ -1606,7 +1606,9 @@ class RunnerCore(RetryableTestCase, metaclass=RunnerMeta):
make=['cmake', '--build', '.', '--'],
make_args=[])
else:
- rtn = self.get_library(os.path.join('third_party', 'zlib'), target, make_args=['libz.a', target])
+ rtn = self.get_library(os.path.join('third_party', 'zlib'), target,
+ configure_args=['LDSHAREDLIBC='],
+ make_args=['libz.a', target])
self.cflags = old_args
return rtn
(untested) But perhaps |
|
That said, zlib's configure script is a bit basic, so I usually build it with CMake instead (or just use zlib-ng if Wasm SIMD is the baseline). |
|
This should fix the issue: --- a/test/common.py
+++ b/test/common.py
@@ -1606,7 +1606,18 @@ class RunnerCore(RetryableTestCase, metaclass=RunnerMeta):
make=['cmake', '--build', '.', '--'],
make_args=[])
else:
- rtn = self.get_library(os.path.join('third_party', 'zlib'), target, make_args=['libz.a', target])
+ if target == 'libz.a':
+ env_init = {}
+ else:
+ env_init = {
+ # Avoid linking with -lc in side modules.
+ # https://github.com/emscripten-core/emscripten/issues/16680#issuecomment-1558015445
+ 'LDSHAREDLIBC': '',
+ }
+
+ rtn = self.get_library(os.path.join('third_party', 'zlib'), target,
+ env_init=env_init,
+ make_args=['libz.a', target])
self.cflags = old_args
return rtnBut only if the system libraries are already cached. For example, if you do: $ ./emcc --clear-cache
$ ./test/runner core0.test_dylink_zlib_configureit fails with: due to this output check: emscripten/test/third_party/zlib/configure Lines 233 to 236 in 26fa03e which was fixed upstream with commit madler/zlib@2d55657. |
|
... perhaps we could just use the zlib sources from the port (instead of |
Main modules and side modules share the
piclibrary directory, butdynlink.cwas added to libc only under-sMAIN_MODULE. A side module linked with an explicit-lcbuilds libc too, so when such a link was the first one to populate the cache,pic/libc.awas cached withoutdlopen,__dlsymand_emscripten_find_dylib, and every later-sMAIN_MODULElink failed with undefined symbols until the cache was cleared.This happens in the test suite on a clean cache when a failing
core0.test_dylink_zlib_configureis retried: zlib's Makefile linkslibz.sowith-lc.