Skip to content

undefined symbol: eglGetProcAddress even with -lEGL flag #14335

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

Closed
kjlubick opened this issue Jun 1, 2021 · 4 comments · Fixed by #14337
Closed

undefined symbol: eglGetProcAddress even with -lEGL flag #14335

kjlubick opened this issue Jun 1, 2021 · 4 comments · Fixed by #14337

Comments

@kjlubick
Copy link
Contributor

kjlubick commented Jun 1, 2021

Here's a small repro case of an issue I'm seeing on a WASM build of Skia.

#include <emscripten.h>
#include <emscripten/bind.h>

#include <string>

#include <EGL/egl.h>

using namespace emscripten;

EMSCRIPTEN_BINDINGS(my_module) {

  function("doTheThing", optional_override([](std::string name)-> void {
    auto p = eglGetProcAddress(name.c_str());
    printf("%s - %p\n", name.c_str(), p);
  }), allow_raw_pointers());
}

When I compile with

source $EMSDK/emsdk_env.sh
EMCXX=`which em++`

EMCC_DEBUG=1 ${EMCXX} \
  --bind \
  --no-entry \
  ./bindings.cpp \
  -lEGL -lGL \
  -s STRICT=1 \
  -s WASM=1 \
  -s USE_WEBGL2=1 \
  -o out.js

I see the following output and error:

emcc:WARNING: invocation: /home/user_name/emsdk/upstream/emscripten/em++.py --bind --no-entry ./bindings.cpp -lEGL -lGL -s STRICT=1 -s WASM=1 -s USE_WEBGL2=1 -o out.js  (in /home/user_name/repro-egl)
shared:DEBUG: successfully executed /home/user_name/emsdk/upstream/bin/clang --version
cache:DEBUG: PID 57486 acquiring multiprocess file lock to Emscripten cache at /home/user_name/emsdk/upstream/emscripten/cache
tools.filelock:DEBUG: Attempting to acquire lock 140181672808944 on /home/user_name/emsdk/upstream/emscripten/cache/cache.lock
tools.filelock:DEBUG: Lock 140181672808944 acquired on /home/user_name/emsdk/upstream/emscripten/cache/cache.lock
cache:DEBUG: done
shared:DEBUG: sanity file up-to-date but check forced: /home/user_name/emsdk/upstream/emscripten/cache/sanity.txt
shared:DEBUG: successfully executed /home/user_name/emsdk/node/14.15.5_64bit/bin/node --version
shared:DEBUG: successfully executed /home/user_name/emsdk/upstream/bin/llc --version
shared:INFO: (Emscripten: Running sanity checks)
shared:DEBUG: successfully executed /home/user_name/emsdk/node/14.15.5_64bit/bin/node -e console.log("hello")
profiler:DEBUG: block "sanity compiler_engine" took 0.05 seconds
profiler:DEBUG: block "sanity LLVM" took 0.00 seconds
tools.filelock:DEBUG: Attempting to release lock 140181672808944 on /home/user_name/emsdk/upstream/emscripten/cache/cache.lock
tools.filelock:DEBUG: Lock 140181672808944 released on /home/user_name/emsdk/upstream/emscripten/cache/cache.lock
cache:DEBUG: PID 57486 released multiprocess file lock to Emscripten cache at /home/user_name/emsdk/upstream/emscripten/cache
profiler:DEBUG: block "sanity" took 0.11 seconds
profiler:DEBUG: block "parse arguments and setup" took 0.00 seconds
profiler:DEBUG: block "ensure_sysroot" took 0.00 seconds
emcc:DEBUG: compiling source file: ./bindings.cpp
shared:DEBUG: successfully executed /home/user_name/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=20 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/home/user_name/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat ./bindings.cpp -c -o /tmp/emscripten_temp/bindings_0.o
profiler:DEBUG: block "compile inputs" took 0.72 seconds
emcc:DEBUG: looking for library "EGL"
building:DEBUG: Mapping library `EGL` to JS libraries: ['library_egl.js']
emcc:DEBUG: looking for library "GL"
building:DEBUG: Mapping library `GL` to JS libraries: ['library_webgl.js', 'library_html5_webgl.js']
profiler:DEBUG: block "calc linker inputs" took 0.00 seconds
shared:DEBUG: executed /home/user_name/emsdk/upstream/bin/llvm-nm /tmp/emscripten_temp/bindings_0.o
profiler:DEBUG: block "llvm_nm_multiple" took 0.02 seconds
system_libs:DEBUG: adding dependency on free due to deps-info on _embind_register_function
system_libs:DEBUG: adding dependency on malloc due to deps-info on eglGetProcAddress
system_libs:DEBUG: forcing stdlibs: {'libembind'}
system_libs:DEBUG: including libembind (libembind-rtti.a)
system_libs:DEBUG: including libc (libc.a)
system_libs:DEBUG: including libcompiler_rt (libcompiler_rt.a)
system_libs:DEBUG: including libc++ (libc++-noexcept.a)
system_libs:DEBUG: including libc++abi (libc++abi-noexcept.a)
system_libs:DEBUG: including libmalloc (libdlmalloc.a)
system_libs:DEBUG: including libc_rt_wasm (libc_rt_wasm.a)
system_libs:DEBUG: including libsockets (libsockets.a)
profiler:DEBUG: block "calculate system libraries" took 0.02 seconds
emcc:DEBUG: linking: ['/tmp/emscripten_temp/bindings_0.o', '-L/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten', '--whole-archive', '/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libembind-rtti.a', '--no-whole-archive', '/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc.a', '/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libcompiler_rt.a', '/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc++-noexcept.a', '/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc++abi-noexcept.a', '/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libdlmalloc.a', '/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc_rt_wasm.a', '/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libsockets.a']
shared:DEBUG: successfully executed /home/user_name/emsdk/upstream/bin/wasm-ld -o out.wasm /tmp/emscripten_temp/bindings_0.o -L/home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten --whole-archive /home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libembind-rtti.a --no-whole-archive /home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc.a /home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libcompiler_rt.a /home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc++-noexcept.a /home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc++abi-noexcept.a /home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libdlmalloc.a /home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libc_rt_wasm.a /home/user_name/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libsockets.a --fatal-warnings -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --strip-debug --export emscripten_stack_get_end --export emscripten_stack_get_free --export emscripten_stack_init --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export fflush --export __errno_location --export malloc --export free --export-table --export-if-defined __start_em_asm --export-if-defined __stop_em_asm -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024
profiler:DEBUG: block "link" took 0.03 seconds
emcc:DEBUG: emscript
building:DEBUG: saving debug copy /tmp/emscripten_temp/emcc-0-base.wasm
shared:DEBUG: successfully executed /home/user_name/emsdk/upstream/bin/wasm-opt --version
shared:DEBUG: successfully executed /home/user_name/emsdk/upstream/bin/wasm-emscripten-finalize --minimize-wasm-changes --dyncalls-i64 out.wasm -o out.wasm --detect-features
building:DEBUG: saving debug copy /tmp/emscripten_temp/emcc-1-wasm-emscripten-finalize.wasm
building:DEBUG: saving debug copy /tmp/emscripten_temp/emcc-2-post_finalize.wasm
emscripten:DEBUG: Metadata parsed: {'asmConsts': {},
'declares': ['_embind_register_function',
            'eglGetProcAddress',
            '_embind_register_void',
            '_embind_register_bool',
            '_embind_register_std_string',
            '_embind_register_std_wstring',
            '_embind_register_emval',
            '_embind_register_integer',
            '_embind_register_float',
            '_embind_register_memory_view',
            'abort',
            'fd_write',
            'emscripten_resize_heap',
            'emscripten_memcpy_big',
            'setTempRet0',
            '_embind_register_bigint'],
'emJsFuncs': {},
'exports': ['__wasm_call_ctors',
           '__getTypeName',
           '__embind_register_native_and_builtin_types',
           '__errno_location',
           'malloc',
           'fflush',
           'stackSave',
           'stackRestore',
           'stackAlloc',
           'emscripten_stack_init',
           'emscripten_stack_get_free',
           'emscripten_stack_get_end',
           'free',
           'dynCall_jiji'],
'features': [],
'globalImports': [],
'invokeFuncs': [],
'mainReadsParams': 0,
'namedGlobals': {},
'staticBump': 0,
'tableSize': 28}
emscripten:DEBUG: very limited syscalls (fd_write) so disabling full filesystem support
emscripten:DEBUG: emscript: js compiler glue
error: undefined symbol: eglGetProcAddress (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _eglGetProcAddress may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/home/user_name/emsdk/node/14.15.5_64bit/bin/node /home/user_name/emsdk/upstream/emscripten/src/compiler.js /tmp/emscripten_temp/tmpvp_okyyt.txt' failed (1)
profiler:DEBUG: block "emscript" took 0.28 seconds
profiler:DEBUG: block "post_link" took 0.28 seconds
not cleaning up temp files since in debug-save mode, see them in /tmp/emscripten_temp
not cleaning up temp files since in debug-save mode, see them in /tmp/emscripten_temp
tools.filelock:DEBUG: Attempting to release lock 140181672812496 on /tmp/emscripten_temp/emscripten.lock
tools.filelock:DEBUG: Lock 140181672812496 released on /tmp/emscripten_temp/emscripten.lock

This had previously been working in emsdk 2.0.10 and I noticed it when updating to 2.0.20

Interesting note from the logs: system_libs:DEBUG: adding dependency on malloc due to deps-info on eglGetProcAddress. I don't see any addition of system/lib/gl/libprocaddr.c which now has the implementation after #13524 right?

@kjlubick
Copy link
Contributor Author

kjlubick commented Jun 1, 2021

The issue persists even after running emcc --clear-cache

@sbc100
Copy link
Collaborator

sbc100 commented Jun 1, 2021

Smaller test case:

$ cat test.cc 
#include <EGL/egl.h>

int main() {
    return (int)eglGetProcAddress("foo");
}
$ em++ test.cc -lEGL -lGL -s STRICT=1 
error: undefined symbol: eglGetProcAddress (referenced by top-level compiled C/C++ code)

Problem goes away without -s STRICT.. so is somehow related to strict mode.

@sbc100
Copy link
Collaborator

sbc100 commented Jun 1, 2021

strict mode defaults a bunch of settings and the one that causes this issue is -s AUTO_NATIVE_LIBRARIES=0. This is because our GL library is called libgl.a (lowercase) so, while we work on a fix there are two workarounds you can try:

  1. Add -s AUTO_NATIVE_LIBRARIES (which will prevent strict mode from turning it off)
  2. Add -lgl (as opposed to -lGL) to pick up our actual gl library

sbc100 added a commit that referenced this issue Jun 1, 2021
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
@sbc100
Copy link
Collaborator

sbc100 commented Jun 1, 2021

Fix is in #14337. Workarounds above should help until that change rolls into a release.

sbc100 added a commit that referenced this issue Jun 1, 2021
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 normally 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
sbc100 added a commit that referenced this issue Jun 1, 2021
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 normally 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
sbc100 added a commit that referenced this issue Jun 1, 2021
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 normally 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
sbc100 added a commit that referenced this issue Jun 2, 2021
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 normally 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
sbc100 added a commit that referenced this issue Jun 2, 2021
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 normally 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
sbc100 added a commit that referenced this issue Jun 2, 2021
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 normally 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
sbc100 added a commit that referenced this issue Jun 2, 2021
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 normally 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
sbc100 added a commit that referenced this issue Jun 3, 2021
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 normally 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
sbc100 added a commit that referenced this issue Jun 3, 2021
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 normally 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
sbc100 added a commit that referenced this issue Jun 3, 2021
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
sbc100 added a commit that referenced this issue Jun 3, 2021
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
sbc100 added a commit that referenced this issue Jun 4, 2021
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
sbc100 added a commit that referenced this issue Jun 4, 2021
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
sbc100 added a commit that referenced this issue Jun 4, 2021
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
sbc100 added a commit that referenced this issue Jun 4, 2021
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
sbc100 added a commit that referenced this issue Jun 4, 2021
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
sbc100 added a commit that referenced this issue Jun 4, 2021
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
sbc100 added a commit that referenced this issue Jun 4, 2021
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
sbc100 added a commit that referenced this issue Jun 5, 2021
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
sbc100 added a commit that referenced this issue Jun 7, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants