Skip to content

Use -lxxx internally rather than full library path #14342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ See docs/process.md for more on how version tagging works.
2.0.24
------
- Support `--preload-file` in Node.js. (#11785)
- System libraries are now passed to the linker internally via `-lfoo` rather
than using their full path. This is in line with how gcc and clang pass system
libraries to the linker. This should not effect any builds unless a project a
happens to have, for example, a file called `libc.a` in one of its library
paths. This would have the effect of overriding the system library (as it
would with gcc or clang) (#14342).
- CMake projects (those that either use emcmake or use Emscripten.cmake
directly) are new configured to install (by default) directly into the
emscripten sysroot. This means that running `cmake --install` (or running the
Expand Down
16 changes: 15 additions & 1 deletion tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,20 @@ def get_path(self):
"""
return shared.Cache.get_lib(self.get_filename(), self.build)

def get_link_flag(self):
"""
Gets the link flags needed to use the library.

This will trigger a build if this library is not in the cache.
"""
fullpath = self.get_path()
# For non-libaries (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.
base = shared.unsuffixed_basename(fullpath)
return '-l' + shared.strip_prefix(base, 'lib')

def get_files(self):
"""
Gets a list of source files for this library.
Expand Down Expand Up @@ -1487,7 +1501,7 @@ def add_library(libname):
logger.debug('including %s (%s)' % (lib.name, lib.get_filename()))

need_whole_archive = lib.name in force_include and lib.get_ext() == '.a'
libs_to_link.append((lib.get_path(), need_whole_archive))
libs_to_link.append((lib.get_link_flag(), need_whole_archive))

if settings.USE_PTHREADS:
add_library('crtbegin')
Expand Down