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

[emscripten-finalize] longjmp rewriter fails to update GOT #2180

Closed
Keno opened this issue Jun 24, 2019 · 5 comments · Fixed by #2382
Closed

[emscripten-finalize] longjmp rewriter fails to update GOT #2180

Keno opened this issue Jun 24, 2019 · 5 comments · Fixed by #2382

Comments

@Keno
Copy link

Keno commented Jun 24, 2019

The fixInvokeFunctionNames pass in emscripten-finalize rewrites the function and import for emscripten_longjmp_jmpbuf to emscripten_longjmp, but doesn't do anything to any potential GOT entries that may be present in the module. This causes a fatal error later in the same utility:

Fatal: GOT.func entry with no import/export: $emscripten_longjmp_jmpbuf
@kripken
Copy link
Member

kripken commented Jun 25, 2019

@sbc100 do you have time to look at this? if not I can, but I could use some direction (testcase would be good)

@sbc100
Copy link
Member

sbc100 commented Jun 25, 2019

Ah yes, it should re-write them both. I'll take a look. Do you know why we haven't seen this is test code? What are we missing that we need to add that will tickle this?

@Keno
Copy link
Author

Keno commented Jun 25, 2019

Presumably this should just trigger on any code compiled with -fPIC that also uses longjmp.

@sbc100
Copy link
Member

sbc100 commented Jun 25, 2019

Or -fPIC and exceptions? I'm surprised we don't have any that in out test suite. I'll be sure to add some if that is needed all thats needed.

@jeromelaban
Copy link

@sbc100 @kripken Here's a repro (extracted from this test) with emscripten 1.38.48-upstream:

#include <setjmp.h>
#include <stdio.h>

typedef struct {
  jmp_buf* jmp;
} jmp_state;

void setjmp_func(jmp_state* s, int level) {
  jmp_buf* prev_jmp = s->jmp;
  jmp_buf c_jmp;

  if (level == 2) {
    longjmp(*(s->jmp), 1);
  }

  if (setjmp(c_jmp) == 0) {
    setjmp_func(s, level + 1);
  }
}

int main() { return 0; }

Note the code in itself does not make sense, I removed everything I could up to the breaking point.

It's built with:

emcc \
   test.cpp \
   -o test.wasm \
   -s SIDE_MODULE=1

I cannot build Skia (canvaskit) as a side module as result of this issue, hope this will help!

sbc100 added a commit to emscripten-core/emscripten that referenced this issue Jan 29, 2020
Now that we have landed (for the third time) the binaryen fix for
WebAssembly/binaryen#2180 we can once
again allow `-fPIC` at compile time as an alternative to MAIN_MODULE
or SIDE_MODULE.

This reverts commit 19a9e35.
sbc100 added a commit to emscripten-core/emscripten that referenced this issue Jan 29, 2020
Now that we have landed (for the third time) the binaryen fix for
WebAssembly/binaryen#2180 we can once
again allow `-fPIC` at compile time as an alternative to MAIN_MODULE
or SIDE_MODULE.

This reverts commit 19a9e35.
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.

4 participants