Skip to content

Commit

Permalink
Ensure system libraries are built on demand (#19405)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kleisauke authored May 22, 2023
1 parent fea7644 commit b76fdf4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4184,8 +4184,8 @@ def process_libraries(state, linker_inputs):
# let wasm-ld handle that. However, we do want to map to the correct variant.
# For example we map `-lc` to `-lc-mt` if we are building with threading support.
if 'lib' + lib in system_libs_map:
lib = system_libs_map['lib' + lib]
new_flags.append((i, '-l' + strip_prefix(lib.get_base_name(), 'lib')))
lib = system_libs_map['lib' + lib].get_link_flag()
new_flags.append((i, lib))
continue

if building.map_and_apply_to_settings(lib):
Expand Down
2 changes: 0 additions & 2 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -12110,8 +12110,6 @@ def test_offset_convertor_plus_wasm2js(self):

def test_standard_library_mapping(self):
# Test the `-l` flags on the command line get mapped the correct libraries variant
self.run_process([EMBUILDER, 'build', 'libc-mt-debug', 'libcompiler_rt-mt', 'libdlmalloc-mt'])

libs = ['-lc', '-lbulkmemory', '-lcompiler_rt', '-lmalloc']
err = self.run_process([EMCC, test_file('hello_world.c'), '-pthread', '-nodefaultlibs', '-v'] + libs, stderr=PIPE).stderr

Expand Down
2 changes: 1 addition & 1 deletion tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def get_link_flag(self):
This will trigger a build if this library is not in the cache.
"""
fullpath = self.build()
# For non-libaries (e.g. crt1.o) we pass the entire path to the linker
# For non-libraries (e.g. crt1.o) we pass the entire path to the linker
if self.get_ext() != '.a':
return fullpath
# For libraries (.a) files, we pass the abbreviated `-l` form.
Expand Down

0 comments on commit b76fdf4

Please sign in to comment.