Skip to content

Commit

Permalink
Preserve system library ordering even under EMCC_FORCE_STDLIBS=1
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: emscripten-core#22161
  • Loading branch information
sbc100 committed Jul 1, 2024
1 parent 35be995 commit df67369
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -5876,6 +5876,11 @@ 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')
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,14 @@ 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)
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 All @@ -2323,6 +2325,7 @@ def add_sanitizer_libs():
add_library('libsanitizer_common_rt')

if only_forced:
add_forced_libs()
add_library('libcompiler_rt')
add_sanitizer_libs()
return libs_to_link
Expand Down Expand Up @@ -2390,6 +2393,10 @@ def add_sanitizer_libs():
add_library('libwasmfs')

add_sanitizer_libs()

# Add forced stdlibs at the end so that the order of system libraries is
# still preserved above, even when EMCC_FORCE_STDLIBS=1 is used.
add_forced_libs()
return libs_to_link


Expand Down

0 comments on commit df67369

Please sign in to comment.