Skip to content
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

How to use system library source code files provided by emscripten ? #17638

Closed
geonoon opened this issue Aug 13, 2022 · 6 comments
Closed

How to use system library source code files provided by emscripten ? #17638

geonoon opened this issue Aug 13, 2022 · 6 comments

Comments

@geonoon
Copy link

geonoon commented Aug 13, 2022

The question is: How to use system library source code files provided by emscripten, for example: https://github.com/emscripten-core/emscripten/blob/main/system/lib/libc/musl/src/linux/epoll.c ?

When I compile a c/c++ project (i.e. an example code at https://github.com/uNetworking/uSockets) to WASM, erros occured as following:

......
[ 85%] Built target uSockets
[ 92%] Building C object CMakeFiles/httpServer.dir/http_server.c.o
[100%] Linking C executable httpServer.js
error: undefined symbol: epoll_create1 (referenced by top-level compiled C/C++ code)
warning: Link with -sLLD_REPORT_UNDEFINED to get more information on undefined symbols
warning: To disable errors for undefined symbols use -sERROR_ON_UNDEFINED_SYMBOLS=0
warning: _epoll_create1 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: epoll_ctl (referenced by top-level compiled C/C++ code)
warning: _epoll_ctl may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: epoll_wait (referenced by top-level compiled C/C++ code)
warning: _epoll_wait may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: eventfd (referenced by top-level compiled C/C++ code)
warning: _eventfd may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: timerfd_create (referenced by top-level compiled C/C++ code)
warning: _timerfd_create may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: timerfd_settime (referenced by top-level compiled C/C++ code)
warning: _timerfd_settime may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc: error: '/home/dev_tools/emsdk/node/14.18.2_64bit/bin/node /home/dev_tools/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpqx7zx6d7.json' failed (returned 1)
make[2]: *** [CMakeFiles/httpServer.dir/build.make:101: httpServer.js] Error 1
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/httpServer.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
emmake: error: 'make' failed (returned 2)

I searched the undefined symbols, such as epoll_create1, epoll_wait, epoll_ctl, etc., and found that they are in the file epoll.h, which is located at : /home/dev_tools/emsdk/upstream/emscripten/cache/sysroot/include/sys/epoll.h,
whose functions are defined in: /home/dev_tools/emsdk/upstream/emscripten/system/lib/libc/musl/src/linux/epoll.c. This code file belongs to a system library libc provided by emscripten.

Even I add these function names into EXPORTED_FUNCTIONS by target_link_options(httpServer PRIVATE -sLINKABLE=1) in CMakeLists, the erros are the same.

The guidance "How do I link against system libraries ..." (https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-link-against-system-libraries-like-sdl-boost-etc) says : System libraries that are included with Emscripten are automatically linked when you compile (just the necessary parts). This includes libc, libc++ (C++ standard library) and SDL.

So, why do the errors occur with undefined symbols,. e.g. epoll_create1, epoll_wait, epoll_ctl, etc. ?

Do I need to explicitly and manually add all source code files provided by emscripten ( e.g. in the libc library) when I build a c/c++ program/library into WASM ?

How can I fix this issue ?

I appreciate an early reply and comments. Thanks.

@geonoon
Copy link
Author

geonoon commented Aug 16, 2022

Is this a emscripten bug?
Obviously the errors occur with undefined symbols,. e.g. epoll_create1, epoll_wait, epoll_ctl, etc. , all these functions are defined in an emscripten system file, i.e. /home/dev_tools/emsdk/upstream/emscripten/system/lib/libc/musl/src/linux/epoll.c. Does this file belong to the musl libc library? "System libraries that are included with Emscripten are automatically linked", but now why have not it happened?
I check the pre-compiled libraries cached in emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten directory, there are some files such as libc++-noexcept.a, etc., Does the epoll.c functions reside in these pre-compiled libraries?

Anyone can help?

@sbc100
Copy link
Collaborator

sbc100 commented Aug 23, 2022

Emscripten doesn't support any of those system calls. We should probably remove that header completely from our system.

The networking support in emscripten has some fairly significant limitations due to the way the web platform is designed. See https://emscripten.org/docs/porting/networking.html for more on this

sbc100 added a commit that referenced this issue Aug 23, 2022
We don't implement any of the functions declared in these headers, so
there is not real use them, and I think it can be misleading to allow
them to be included at compile time.

See #17638
sbc100 added a commit that referenced this issue Aug 23, 2022
We don't implement any of the functions declared in these headers, so
there is not real use them, and I think it can be misleading to allow
them to be included at compile time.

See #17638
sbc100 added a commit that referenced this issue Aug 23, 2022
We don't implement any of the functions declared in these headers, so
there is not real use them, and I think it can be misleading to allow
them to be included at compile time.

See #17638
sbc100 added a commit that referenced this issue Aug 23, 2022
We don't implement any of the functions declared in these headers, so
there is not real use them, and I think it can be misleading to allow
them to be included at compile time.

See #17638
sbc100 added a commit that referenced this issue Aug 24, 2022
We don't implement any of the functions declared in these headers, so
there is not real use them, and I think it can be misleading to allow
them to be included at compile time.

See #17638
@geonoon
Copy link
Author

geonoon commented Aug 25, 2022

Do you only remove some linux-specific musl headers #17704 ?
Actually, there are those functions' implemented source files in the directory : emsdk/upstream/emscripten/system/lib/libc/musl/src/
Will you remove both the header files and their source files?

@sbc100
Copy link
Collaborator

sbc100 commented Aug 25, 2022

Right now for linux-specific source files we just exclude from the build. So they should not effect any users. Unless I'm missing something?

@sbc100
Copy link
Collaborator

sbc100 commented Aug 30, 2022

Hopefully this issue can now be closed? If you ./emsdk install tot you should not see the epoll header anymore so it should be clear that epoll is not available under emscripten.

@NorrinRadd
Copy link

It seems like this can be closed

@sbc100 sbc100 closed this as completed Apr 21, 2024
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

No branches or pull requests

3 participants