Skip to content

Commit 123375a

Browse files
committed
Warn when we map unrecognized library files to -l flags.
This is rather an odd feature and I think we should notify users if they are relying on it. Honestly I doubt many are. See #14689 for an example of how confusing it can be when it goes wrong. Also, make sure we strip off the full suffix in the case of `.so.1.2.3` suffixes.
1 parent a3b27c4 commit 123375a

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

emcc.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,17 @@ def get_file_suffix(filename):
892892
return ''
893893

894894

895+
def get_library_basename(filename):
896+
"""Similar to get_file_suffix this strips of all numeric suffixes and then
897+
then final non-numeric one. For example for 'libz.so.1.2.8' returns 'libz'"""
898+
filename = os.path.basename(filename)
899+
while filename:
900+
filename, suffix = os.path.splitext(filename)
901+
# Keep stipping suffixes until we strip a non-numeric one.
902+
if not suffix[1:].isdigit():
903+
return filename
904+
905+
895906
def get_secondary_target(target, ext):
896907
# Depending on the output format emscripten creates zero or more secondary
897908
# output files (e.g. the .wasm file when creating JS output, or the
@@ -1236,8 +1247,10 @@ def phase_setup(options, state, newargs, settings_map):
12361247
# For shared libraries that are neither bitcode nor wasm, assuming its local native
12371248
# library and attempt to find a library by the same name in our own library path.
12381249
# TODO(sbc): Do we really need this feature? See test_other.py:test_local_link
1239-
libname = strip_prefix(unsuffixed_basename(arg), 'lib')
1240-
add_link_flag(state, i, '-l' + libname)
1250+
libname = strip_prefix(get_library_basename(arg), 'lib')
1251+
flag = '-l' + libname
1252+
diagnostics.warning('map-unrecognized-libraries', f'unrecognized file type: `{arg}`. Mapping to `{flag}` and hoping for the best')
1253+
add_link_flag(state, i, flag)
12411254
else:
12421255
input_files.append((i, arg))
12431256
elif arg.startswith('-L'):

tests/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ def test_local_link(self):
12261226
''')
12271227

12281228
ensure_dir('subdir')
1229-
create_file('subdir/libfile.so', 'this is not llvm bitcode!')
1229+
create_file('subdir/libfile.so.1.2.3', 'this is not llvm bitcode!')
12301230

12311231
create_file('libfile.cpp', '''
12321232
#include <stdio.h>
@@ -1236,7 +1236,7 @@ def test_local_link(self):
12361236
''')
12371237

12381238
self.run_process([EMXX, 'libfile.cpp', '-shared', '-o', 'libfile.so'], stderr=PIPE)
1239-
self.run_process([EMXX, 'main.cpp', Path('subdir/libfile.so'), '-L.'])
1239+
self.run_process([EMXX, 'main.cpp', Path('subdir/libfile.so.1.2.3'), '-L.'])
12401240
self.assertContained('hello from lib', self.run_js('a.out.js'))
12411241

12421242
def test_identical_basenames(self):

tools/shared.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
diagnostics.add_warning('deprecated', shared=True)
6666
diagnostics.add_warning('version-check')
6767
diagnostics.add_warning('export-main')
68+
diagnostics.add_warning('map-unrecognized-libraries')
6869
diagnostics.add_warning('unused-command-line-argument', shared=True)
6970
diagnostics.add_warning('pthreads-mem-growth')
7071

0 commit comments

Comments
 (0)