Skip to content

Commit 51281a3

Browse files
authored
Fix -Oz + -sLINKABLE (#17194)
This was broken by the recent change to the way we include libc_optz. See #17179.
1 parent b86798a commit 51281a3

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ mergeInto(LibraryManager.library, {
368368
// end up adding code that refers to this.)
369369
// In STANDALONE_WASM we avoid the emscripten_memcpy_big dependency so keep
370370
// the wasm file standalone.
371-
#if (SHRINK_LEVEL < 2 || MAIN_MODULE == 1) && !STANDALONE_WASM
371+
#if (SHRINK_LEVEL < 2 || LINKABLE) && !STANDALONE_WASM
372372

373373
emscripten_memcpy_big__sig: 'vppp',
374374
#if MIN_CHROME_VERSION < 45 || MIN_EDGE_VERSION < 14 || MIN_FIREFOX_VERSION < 34 || MIN_IE_VERSION != TARGET_NOT_SUPPORTED || MIN_SAFARI_VERSION < 100101

tests/test_other.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,9 @@ def test_export_all(self):
12491249
};
12501250
''')
12511251

1252-
self.emcc('lib.c', ['-sEXPORT_ALL', '-sLINKABLE', '--pre-js', 'main.js'], output_filename='a.out.js')
1252+
# Explicitly test with -Oz to ensure libc_optz is included alongside
1253+
# libc when `--whole-archive` is used.
1254+
self.emcc('lib.c', ['-Oz', '-sEXPORT_ALL', '-sLINKABLE', '--pre-js', 'main.js'], output_filename='a.out.js')
12531255
self.assertContained('libf1\nlibf2\n', self.run_js('a.out.js'))
12541256

12551257
def test_export_all_and_exported_functions(self):

tools/system_libs.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,12 +1861,13 @@ def add_library(libname):
18611861
# C libraries that override libc must come before it
18621862
if settings.PRINTF_LONG_DOUBLE:
18631863
add_library('libprintf_long_double')
1864-
# libc_optz is a size optimization, and therefore not really important when
1865-
# MAIN_MODULE=1 (which links in all system libraries, leading to a large
1866-
# size far bigger than any savings from libc_optz). Also, libc_optz overrides
1867-
# parts of libc, which will not link due to --whole-archive in MAIN_MODULE=1
1868-
# currently.
1869-
if settings.SHRINK_LEVEL >= 2 and settings.MAIN_MODULE != 1:
1864+
# Becuase libc_optz overrides parts of libc, it is not compatible with `LINKABLE`
1865+
# (used in `MAIN_MODULE=1`) because with that setting we use `--whole-archive` to
1866+
# include all system libraries.
1867+
# However, because libc_optz is a size optimization it is not really important
1868+
# when used with `MAIN_MODULE=1` (which links in all system libraries, leading
1869+
# to overheads far bigger than any savings from libc_optz)
1870+
if settings.SHRINK_LEVEL >= 2 and not settings.LINKABLE:
18701871
add_library('libc_optz')
18711872

18721873
if settings.STANDALONE_WASM:

0 commit comments

Comments
 (0)