Skip to content
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
10 changes: 7 additions & 3 deletions src/lib/libwebgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4228,10 +4228,14 @@ function recordGLProcAddressGet(lib) {
}
}
// Also update any alias targets to point to the emscripten_-prefixed
// versions. e.g. both the name of the symbol *and* it's target need updating
// in cases such as `glMultiDrawElements: 'glMultiDrawElementsWEBGL'`
// versions. e.g. both the name of the symbol *and* its target need updating
// in cases such as `glMultiDrawElements: 'glMultiDrawElementsWEBGL'`.
// Cross-library targets (such as glGenFramebuffers in LibraryGLEmulation)
// are looked up in LibraryManager.library as well.
for (const [sym, target] of Object.entries(lib)) {
if (sym.startsWith('emscripten_gl') && typeof target === 'string' && lib.hasOwnProperty('emscripten_' + target)) {
if (sym.startsWith('emscripten_gl') && typeof target === 'string' &&
(lib.hasOwnProperty('emscripten_' + target) ||
LibraryManager.library.hasOwnProperty('emscripten_' + target))) {
Comment thread
sbc100 marked this conversation as resolved.
Resolved
lib[sym] = 'emscripten_' + target;
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,32 @@ def test_dylink_webgl_alias(self):
'-Wno-experimental',
])

def test_dylink_glemu_alias(self):
# In libglemu.js, `glGenFramebuffersOES` is an alias for `glGenFramebuffers` (defined
# in libwebgl.js). `recordGLProcAddressGet` renames both to `emscripten_gl*` so that
# `glGenFramebuffersOES` -> `emscripten_glGenFramebuffersOES` -> `emscripten_glGenFramebuffers`.
# If the cross-library target of `emscripten_glGenFramebuffersOES` is not updated to
# `emscripten_glGenFramebuffers` and `glGenFramebuffers` is exported from Wasm, jsifier
# mistakes `emscripten_glGenFramebuffersOES` for a native alias and fails to define it
# in JS before `_glGenFramebuffersOES = _emscripten_glGenFramebuffersOES` is evaluated.
create_file('test.c', r'''
#define GL_GLEXT_PROTOTYPES 1
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <stdio.h>

// Export a native `glGenFramebuffers` from Wasm (simulating the native GL wrappers in
// libgl when exported via MAIN_MODULE or EXPORT_ALL) so that an un-prefixed alias target
// of `'glGenFramebuffers'` would be treated by jsifier as a native Wasm export.
__attribute__((used)) void glGenFramebuffers(GLsizei n, GLuint* ids) {}

int main() {
printf("glGenFramebuffersOES: %p\n", &glGenFramebuffersOES);
printf("done\n");
return 0;
}''')
self.do_runf('test.c', 'done\n', cflags=['-sMAIN_MODULE=2', '-sLEGACY_GL_EMULATION'])

def test_dylink_library_search(self):
# Test library resolution in the case when both static and dynamic library are present.
create_file('side_dyn.c', r'''
Expand Down
Loading