Skip to content

Commit 016265c

Browse files
authored
Fix libc_optz in EMCC_FORCE_STDLIBS builds (#17240)
Aside from MAIN_MODULE=1, if the user uses EMCC_FORCE_STDLIBS then all system libraries will be linked in, and potentially cause problems. Fixes corez.test_dylink_syslibs_all as well as ltoz and thinltoz, see #17179 (comment)
1 parent a0d4a56 commit 016265c

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

.circleci/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ jobs:
372372
steps:
373373
- run-tests-linux:
374374
# also add a few asan tests and a single test of EMTEST_BROWSER=node
375+
# also add a corez test of dynamic linking + forced syslibs
375376
test_targets: "
376377
core2
377378
asan.test_stat
@@ -384,7 +385,8 @@ jobs:
384385
asan.test_async_hello
385386
lsan.test_stdio_locking
386387
lsan.test_pthread_create
387-
browser.test_pthread_join"
388+
browser.test_pthread_join
389+
corez.test_dylink_syslibs_all"
388390
test-core3:
389391
executor: bionic
390392
steps:

tools/system_libs.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,13 @@ def customize_build_cmd(self, cmd, filename):
10591059
return cmd
10601060

10611061
def can_use(self):
1062-
return super(libc_optz, self).can_use() and settings.SHRINK_LEVEL >= 2
1062+
# Because libc_optz overrides parts of libc, it is not compatible with
1063+
# dynamic linking which uses --whole-archive. In addition,
1064+
# EMCC_FORCE_STDLIBS can have a similar effect of forcing all libraries.
1065+
# In both cases, the build is not one that is hyper-focused on code size,
1066+
# and so optz is not that important.
1067+
return super(libc_optz, self).can_use() and settings.SHRINK_LEVEL >= 2 and \
1068+
not settings.LINKABLE and not os.environ.get('EMCC_FORCE_STDLIBS')
10631069

10641070

10651071
class libprintf_long_double(libc):
@@ -1877,13 +1883,9 @@ def add_library(libname):
18771883
# C libraries that override libc must come before it
18781884
if settings.PRINTF_LONG_DOUBLE:
18791885
add_library('libprintf_long_double')
1880-
# Becuase libc_optz overrides parts of libc, it is not compatible with `LINKABLE`
1881-
# (used in `MAIN_MODULE=1`) because with that setting we use `--whole-archive` to
1882-
# include all system libraries.
1883-
# However, because libc_optz is a size optimization it is not really important
1884-
# when used with `MAIN_MODULE=1` (which links in all system libraries, leading
1885-
# to overheads far bigger than any savings from libc_optz)
1886-
if settings.SHRINK_LEVEL >= 2 and not settings.LINKABLE:
1886+
# See comment in libc_optz itself
1887+
if settings.SHRINK_LEVEL >= 2 and not settings.LINKABLE and \
1888+
not os.environ.get('EMCC_FORCE_STDLIBS'):
18871889
add_library('libc_optz')
18881890

18891891
if settings.STANDALONE_WASM:

0 commit comments

Comments
 (0)