Skip to content

Commit c104836

Browse files
committed
Fix for -lGL + AUTO_NATIVE_LIBRARIES=0
When calling `map_to_js_libs('GL')` we were mapping this to the JS libraries, and not also including the native `libgl` library. Normally this doesn't matter since `libgl` is included by default, but not when `AUTO_NATIVE_LIBRARIES=0` is used. This also happens to fix an old bug (#10171) where we would look on the file system for `libGL.a` before looking in `map_to_js_libs`. Fixes: #10171 Fixes: #14335
1 parent 916a7a6 commit c104836

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

emcc.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,6 +3523,17 @@ def process_libraries(state, linker_inputs):
35233523
continue
35243524

35253525
logger.debug('looking for library "%s"', lib)
3526+
js_libs, native_lib = building.map_to_js_libs(lib)
3527+
if js_libs is not None:
3528+
libraries += [(i, js_lib) for js_lib in js_libs]
3529+
# If native_lib is returned then include it in the link
3530+
# via forced_stdlibs.
3531+
if native_lib:
3532+
state.forced_stdlibs.append(native_lib)
3533+
continue
3534+
3535+
if building.map_and_apply_to_settings(lib):
3536+
continue
35263537

35273538
path = None
35283539
for suff in suffixes:
@@ -3534,11 +3545,8 @@ def process_libraries(state, linker_inputs):
35343545
if path:
35353546
linker_inputs.append((i, path))
35363547
continue
3537-
jslibs = building.map_to_js_libs(lib)
3538-
if jslibs is not None:
3539-
libraries += [(i, jslib) for jslib in jslibs]
3540-
elif not building.map_and_apply_to_settings(lib):
3541-
new_flags.append((i, flag))
3548+
3549+
new_flags.append((i, flag))
35423550

35433551
settings.SYSTEM_JS_LIBRARIES += libraries
35443552

tests/other/test_explict_gl_linking.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <EGL/egl.h>
2+
3+
int main() {
4+
return (int)eglGetProcAddress("foo");
5+
}

tests/test_other.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10645,3 +10645,6 @@ def test_standard_library_mapping(self):
1064510645
self.assertContained(' -lc-mt ', err)
1064610646
self.assertContained(' -ldlmalloc-mt ', err)
1064710647
self.assertContained(' -lcompiler_rt-mt ', err)
10648+
10649+
def test_explict_gl_linking(self):
10650+
self.run_process([EMCC, test_file('other/test_explict_gl_linking.c'), '-sNO_AUTO_NATIVE_LIBRARIES', '-lGL'])

tools/building.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,10 +1333,14 @@ def is_wasm_dylib(filename):
13331333
return False
13341334

13351335

1336-
# Given the name of a special Emscripten-implemented system library, returns an
1337-
# array of absolute paths to JS library files inside emscripten/src/ that
1338-
# corresponds to the library name.
13391336
def map_to_js_libs(library_name):
1337+
"""Given the name of a special Emscripten-implemented system library, returns an
1338+
pair containing
1339+
1. Array of absolute paths to JS library files, inside emscripten/src/ that corresponds to the
1340+
library name. `None` means there is no mapping and the library will be processed by the linker
1341+
as a require for normal native library.
1342+
2. Optional name of a corresponding native library to link in.
1343+
"""
13401344
# Some native libraries are implemented in Emscripten as system side JS libraries
13411345
library_map = {
13421346
'EGL': ['library_egl.js'],
@@ -1364,23 +1368,21 @@ def map_to_js_libs(library_name):
13641368
# This is the name of GNU's C++ standard library. We ignore it here
13651369
# for compatability with GNU toolchains.
13661370
'stdc++': [],
1367-
# This means that linking against libc with `-lc` is ignored when the
1368-
# library is not found (It does work if library already exists in the
1369-
# sysroot because that case is handled before we call (map_to_js_libs).
1370-
# TODO(sbc): We should probably remove this and allow `-lc` to make it all
1371-
# the way to the linker.
1372-
'c': [],
1371+
}
1372+
# And some are hybrid and require JS and native libraries to be included
1373+
native_library_map = {
1374+
'GL': 'libgl',
13731375
}
13741376

13751377
if library_name in library_map:
13761378
libs = library_map[library_name]
13771379
logger.debug('Mapping library `%s` to JS libraries: %s' % (library_name, libs))
1378-
return libs
1380+
return (libs, native_library_map.get(library_name))
13791381

13801382
if library_name.endswith('.js') and os.path.isfile(path_from_root('src', 'library_' + library_name)):
1381-
return ['library_' + library_name]
1383+
return (['library_' + library_name], None)
13821384

1383-
return None
1385+
return (None, None)
13841386

13851387

13861388
# Map a linker flag to a settings. This lets a user write -lSDL2 and it will have the same effect as

0 commit comments

Comments
 (0)