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

emcc and em++ generate different result for the same source code. #689

Closed
xxuejie opened this issue Nov 9, 2012 · 4 comments
Closed

emcc and em++ generate different result for the same source code. #689

xxuejie opened this issue Nov 9, 2012 · 4 comments

Comments

@xxuejie
Copy link
Contributor

xxuejie commented Nov 9, 2012

Hi there,

I ported mruby to the browser via emscripten, the source code is at https://github.com/xxuejie/mruby-browser. However, I found that if I build the source using emcc, the result js file will run forever. But if I change to build with em++, the code is working without any problem.

How to build with em++:

git clone git://github.com/xxuejie/mruby-browser.git
git checkout master
make clean
./script/bootstrap

How to build with emcc:
(for the same source code)
git checkout build-with-emcc
make clean
./script/bootstrap

The diff file of the two generated js file is at https://github.com/xxuejie/mruby-browser/blob/build-with-emcc/diff.tar.gz. But it is very huge(~3MB unzipped).

@kripken
Copy link
Member

kripken commented Nov 10, 2012

I can reproduce the problem. I poked around with some debugging tools, but it's hard to say what is going wrong here. Comparing memory logs fails because the C++ build uses slightly more memory - it has some strings that are different, things like that.

So it is possible that some C++ vs C difference in those strings is the cause, and it hits an underlying bug in the code. Or, it could be that some code conversion limitation is hit. The closest I can think of is we have seen issues with compiling C++ and C code and calling a function from one to the other. So if some code is compiled using em++, all probably should be. Although we should throw an error on that, and I don't see one.

LABEL_DEBUG does show the hang is inside _mrb_include_module. If you understand what the source code does there, then it might be easy to find out what is going wrong there. Might help to put some debug printouts in the generated JS for that function, it is not very large, and should be easy to map to the original.

@xxuejie
Copy link
Contributor Author

xxuejie commented Nov 10, 2012

Thanks, Alon. I tried dig into the source code a little bit. And the problem occurs in the standard library, with the following code:

class Array
  include Enumerable
end

For those who are not familiar with Ruby, what this piece of code does is to invoke "include" method of "Array" class object with the argument "Enumerable". And for some reason, the self variable which should point to "Array" class object is invalid. It maybe the case that the ruby virtual machine failed to map the literal string "Array" to the correct class object, or it maybe the case that the value is right, but some how got truncated in the calling chain from decoding the opcode of the ruby vm, to the actual calling of _mrb_include_module.

Anyway, I will continue to investigate in this and update this issue when I got more findings. Thanks again for you help!

@xxuejie
Copy link
Contributor Author

xxuejie commented Nov 13, 2012

After some time of debugging, I found one bug which may (or may not) be the reason of this issue. I created another issue with a simplified version of source to debug.

@xxuejie
Copy link
Contributor Author

xxuejie commented Nov 13, 2012

I've just tested the code with the new commit for issue #705. It did fix this problem, I've also updated the mruby-browser project pointing to the new commit: xxuejie/mruby-browser@9044daf.

Thanks @kripken for the very fast fix!

@xxuejie xxuejie closed this as completed Nov 13, 2012
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

2 participants