Skip to content

Commit b76fdf4

Browse files
authored
Ensure system libraries are built on demand (#19405)
Previously, when explicitly linking against a system library (e.g. `-lc`) that had not been built earlier, wasm-ld would raise an error indicating that the library could not be found. Use the `get_link_flag()` function to ensure that it triggers a build if the system library is not present in the cache.
1 parent fea7644 commit b76fdf4

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

emcc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4184,8 +4184,8 @@ def process_libraries(state, linker_inputs):
41844184
# let wasm-ld handle that. However, we do want to map to the correct variant.
41854185
# For example we map `-lc` to `-lc-mt` if we are building with threading support.
41864186
if 'lib' + lib in system_libs_map:
4187-
lib = system_libs_map['lib' + lib]
4188-
new_flags.append((i, '-l' + strip_prefix(lib.get_base_name(), 'lib')))
4187+
lib = system_libs_map['lib' + lib].get_link_flag()
4188+
new_flags.append((i, lib))
41894189
continue
41904190

41914191
if building.map_and_apply_to_settings(lib):

test/test_other.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12110,8 +12110,6 @@ def test_offset_convertor_plus_wasm2js(self):
1211012110

1211112111
def test_standard_library_mapping(self):
1211212112
# Test the `-l` flags on the command line get mapped the correct libraries variant
12113-
self.run_process([EMBUILDER, 'build', 'libc-mt-debug', 'libcompiler_rt-mt', 'libdlmalloc-mt'])
12114-
1211512113
libs = ['-lc', '-lbulkmemory', '-lcompiler_rt', '-lmalloc']
1211612114
err = self.run_process([EMCC, test_file('hello_world.c'), '-pthread', '-nodefaultlibs', '-v'] + libs, stderr=PIPE).stderr
1211712115

tools/system_libs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def get_link_flag(self):
426426
This will trigger a build if this library is not in the cache.
427427
"""
428428
fullpath = self.build()
429-
# For non-libaries (e.g. crt1.o) we pass the entire path to the linker
429+
# For non-libraries (e.g. crt1.o) we pass the entire path to the linker
430430
if self.get_ext() != '.a':
431431
return fullpath
432432
# For libraries (.a) files, we pass the abbreviated `-l` form.

0 commit comments

Comments
 (0)