Skip to content

Fix for -lGL + AUTO_NATIVE_LIBRARIES=0 #14337

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 7, 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
18 changes: 13 additions & 5 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3523,6 +3523,17 @@ def process_libraries(state, linker_inputs):
continue

logger.debug('looking for library "%s"', lib)
js_libs, native_lib = building.map_to_js_libs(lib)
if js_libs is not None:
libraries += [(i, js_lib) for js_lib in js_libs]
# If native_lib is returned then include it in the link
# via forced_stdlibs.
if native_lib:
state.forced_stdlibs.append(native_lib)
continue

if building.map_and_apply_to_settings(lib):
continue

path = None
for suff in suffixes:
Expand All @@ -3534,11 +3545,8 @@ def process_libraries(state, linker_inputs):
if path:
linker_inputs.append((i, path))
continue
jslibs = building.map_to_js_libs(lib)
if jslibs is not None:
libraries += [(i, jslib) for jslib in jslibs]
elif not building.map_and_apply_to_settings(lib):
new_flags.append((i, flag))

new_flags.append((i, flag))

settings.SYSTEM_JS_LIBRARIES += libraries

Expand Down
5 changes: 5 additions & 0 deletions tests/other/test_explict_gl_linking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <EGL/egl.h>

int main() {
return (int)eglGetProcAddress("foo");
}
6 changes: 6 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -10645,3 +10645,9 @@ def test_standard_library_mapping(self):
self.assertContained(' -lc-mt ', err)
self.assertContained(' -ldlmalloc-mt ', err)
self.assertContained(' -lcompiler_rt-mt ', err)

def test_explict_gl_linking(self):
# Test that libGL can be linked explictly via `-lGL` rather than implictly.
# Here we use NO_AUTO_NATIVE_LIBRARIES to disable the implictly linking that normally
# includes the native GL library.
self.run_process([EMCC, test_file('other/test_explict_gl_linking.c'), '-sNO_AUTO_NATIVE_LIBRARIES', '-lGL'])
26 changes: 14 additions & 12 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,10 +1333,14 @@ def is_wasm_dylib(filename):
return False


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

if library_name in library_map:
libs = library_map[library_name]
logger.debug('Mapping library `%s` to JS libraries: %s' % (library_name, libs))
return libs
return (libs, native_library_map.get(library_name))

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

return None
return (None, None)


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