Skip to content

Commit

Permalink
Preserve system library ordering even under EMCC_FORCE_STDLIBS=1 (#22171
Browse files Browse the repository at this point in the history
)

In particular `EMCC_FORCE_STDLIBS=1` would previously place libc before
libbulkmemory which don't work. libbulkmemory always needs to come first
on the link line.

Fixes: #22161
  • Loading branch information
sbc100 authored Jul 1, 2024
1 parent 658a95d commit 6ea5dd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -5876,6 +5876,12 @@ def test_only_force_stdlibs_2(self):
self.run_process([EMXX, 'src.cpp', '-sDISABLE_EXCEPTION_CATCHING=0'])
self.assertContained('Caught exception: std::exception', self.run_js('a.out.js'))

@with_env_modify({'EMCC_FORCE_STDLIBS': '1'})
def test_force_stdlibs(self):
self.do_runf('hello_world.c')
# See https://github.com/emscripten-core/emscripten/issues/22161
self.do_runf('hello_world.c', emcc_args=['-sWASM_BIGINT'])

@crossplatform
@also_with_env_modify({'gb_locale': {'LC_ALL': 'en_GB'}, 'long_tz': {'TZ': 'Asia/Kathmandu'}})
def test_strftime_zZ(self):
Expand Down
15 changes: 11 additions & 4 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2292,12 +2292,17 @@ def add_library(libname):
if settings.SIDE_MODULE:
return libs_to_link

for forced in force_include:
if forced not in system_libs_map:
shared.exit_with_error('invalid forced library: %s', forced)
add_library(forced)
# We add the forced libs last so that any libraries that are added in the normal
# sequence below are added in the correct order even when they are also part of
# EMCC_FORCE_STDLIBS.
def add_forced_libs():
for forced in force_include:
if forced not in system_libs_map:
shared.exit_with_error('invalid forced library: %s', forced)
add_library(forced)

if '-nodefaultlibs' in args:
add_forced_libs()
return libs_to_link

sanitize = settings.USE_LSAN or settings.USE_ASAN or settings.UBSAN_RUNTIME
Expand Down Expand Up @@ -2325,6 +2330,7 @@ def add_sanitizer_libs():
if only_forced:
add_library('libcompiler_rt')
add_sanitizer_libs()
add_forced_libs()
return libs_to_link

if settings.AUTO_NATIVE_LIBRARIES:
Expand Down Expand Up @@ -2390,6 +2396,7 @@ def add_sanitizer_libs():
add_library('libwasmfs')

add_sanitizer_libs()
add_forced_libs()
return libs_to_link


Expand Down

0 comments on commit 6ea5dd1

Please sign in to comment.