Skip to content

Warn when we map unrecognized library files to -l flags. #14746

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
Jul 23, 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
17 changes: 15 additions & 2 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,17 @@ def get_file_suffix(filename):
return ''


def get_library_basename(filename):
"""Similar to get_file_suffix this strips off all numeric suffixes and then
then final non-numeric one. For example for 'libz.so.1.2.8' returns 'libz'"""
filename = os.path.basename(filename)
while filename:
filename, suffix = os.path.splitext(filename)
# Keep stipping suffixes until we strip a non-numeric one.
if not suffix[1:].isdigit():
return filename


def get_secondary_target(target, ext):
# Depending on the output format emscripten creates zero or more secondary
# output files (e.g. the .wasm file when creating JS output, or the
Expand Down Expand Up @@ -1236,8 +1247,10 @@ def phase_setup(options, state, newargs, settings_map):
# For shared libraries that are neither bitcode nor wasm, assuming its local native
# library and attempt to find a library by the same name in our own library path.
# TODO(sbc): Do we really need this feature? See test_other.py:test_local_link
libname = strip_prefix(unsuffixed_basename(arg), 'lib')
add_link_flag(state, i, '-l' + libname)
libname = strip_prefix(get_library_basename(arg), 'lib')
flag = '-l' + libname
diagnostics.warning('map-unrecognized-libraries', f'unrecognized file type: `{arg}`. Mapping to `{flag}` and hoping for the best')
add_link_flag(state, i, flag)
else:
input_files.append((i, arg))
elif arg.startswith('-L'):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ def test_local_link(self):
''')

ensure_dir('subdir')
create_file('subdir/libfile.so', 'this is not llvm bitcode!')
create_file('subdir/libfile.so.1.2.3', 'this is not llvm bitcode!')

create_file('libfile.cpp', '''
#include <stdio.h>
Expand All @@ -1236,7 +1236,8 @@ def test_local_link(self):
''')

self.run_process([EMXX, 'libfile.cpp', '-shared', '-o', 'libfile.so'], stderr=PIPE)
self.run_process([EMXX, 'main.cpp', Path('subdir/libfile.so'), '-L.'])
err = self.run_process([EMXX, 'main.cpp', Path('subdir/libfile.so.1.2.3'), '-L.'], stderr=PIPE).stderr
self.assertContained('Mapping to `-lfile` and hoping for the best [-Wmap-unrecognized-libraries]', err)
self.assertContained('hello from lib', self.run_js('a.out.js'))

def test_identical_basenames(self):
Expand Down
1 change: 1 addition & 0 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
diagnostics.add_warning('deprecated', shared=True)
diagnostics.add_warning('version-check')
diagnostics.add_warning('export-main')
diagnostics.add_warning('map-unrecognized-libraries')
diagnostics.add_warning('unused-command-line-argument', shared=True)
diagnostics.add_warning('pthreads-mem-growth')

Expand Down