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

--llvm-lto 3 -s USE_PTHREADS -s FETCH=1 broken in 1.38.28 #8242

Closed
VirtualTim opened this issue Mar 6, 2019 · 7 comments
Closed

--llvm-lto 3 -s USE_PTHREADS -s FETCH=1 broken in 1.38.28 #8242

VirtualTim opened this issue Mar 6, 2019 · 7 comments

Comments

@VirtualTim
Copy link
Collaborator

VirtualTim commented Mar 6, 2019

Compiling something simple like:

#include <iostream>
int main(int argc, char** argv) {
	std::cout << "test" << std::endl;
}

Using: emcc test.cpp --llvm-lto 3 -s USE_PTHREADS -s FETCH=1 -o test.html Will result in the error
shared:ERROR: failed to find function _pthread_mutexattr_init!

This worked in 1.38.27. Compiling with -s WASM=0 doesn't change the error.
--llvm-lto 2 works for the above example, but the actual code I'm working on requires --llvm-lto 0 to compile.

@kripken
Copy link
Member

kripken commented Mar 6, 2019

Possibly a bug where we assume that function exists without adding an explicit export for it, and LTO manages to optimize it out in this case.

@VirtualTim
Copy link
Collaborator Author

_pthread_mutex_init also needs to be exported.

I thought I could add something like this shared.Settings.EXPORTED_RUNTIME_METHODS += ['_pthread_mutexattr_init', '_pthread_mutex_init']
around here: https://github.com/emscripten-core/emscripten/blob/incoming/emcc.py#L2067, but that didn't seem to change anything.
Adding '_pthread_mutexattr_init', '_pthread_mutex_init' to -s EXPORTED_FUNCTIONS fixes this.

@kripken
Copy link
Member

kripken commented Apr 11, 2019

What code calls those pthread mutex functions? If it was in the JS, then exporting would be the natural solution. I don't see that though. So we should find out where it's called, and understand why normal linking didn't bring those in.

@VirtualTim
Copy link
Collaborator Author

Not really sure how this all works, but these functions are called in the generated fetch.js, and looks like they should be imported here?
So I'm sure really sure how those get removed.

@kripken
Copy link
Member

kripken commented Apr 15, 2019

Ah, this might be related to the special fetch-worker stuff then. I think only @juj understands that code well. It would be good to rewrite that as a simple/normal pthread at some point.

@VirtualTim VirtualTim changed the title --llvm-lto 3 -s US E_PTHREADS -s FETCH=1 broken in 1.38.28 --llvm-lto 3 -s USE_PTHREADS -s FETCH=1 broken in 1.38.28 Jul 30, 2019
@VirtualTim
Copy link
Collaborator Author

I think the fix is to add these to library_fetch.js, in a similar manner to #9202.
I don't have time right now to work on a PR, but I'll look at this in the future.

@stale
Copy link

stale bot commented Oct 2, 2020

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Oct 2, 2020
@stale stale bot closed this as completed Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants