Skip to content

JS Math.* equivalent cstdlib functions are not in FUNCTION_TABLE #29

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
timdawborn opened this issue Jun 24, 2011 · 3 comments
Closed

Comments

@timdawborn
Copy link
Contributor

The addresses of the corresponding cstdlib maths functions are not added to FUNCTION_TABLE. This causes any dereferenced function pointer to a cstdlib maths function to die.

$ cat test.c
#include <math.h>
#include <stdio.h>

int
main(void) {
  float (*fn)(float) = &sqrtf;
  printf("fn(10) = %f\n", fn(10));
  return 0;
}
$ ~/downloads/llvm-gcc-4.2-2.9.source/cbuild/install/bin/llvm-gcc -emit-llvm -c -o test.o test.c
$ ~/downloads/llvm-2.9/cbuild/Release/bin/llvm-link -o test test.o 
$ ~/downloads/llvm-2.9/cbuild/Release/bin/llvm-dis -show-annotations test
$ ~/reposs/emscripten/emscripten.py test.ll > test.js
$ ~/downloads/v8/d8 test.js 
test.js:727: TypeError: Property 'function sqrt() { [native code] }' of object 0,0 is not a function
        var $2=FUNCTION_TABLE[$1](10);
                                ^
TypeError: Property 'function sqrt() { [native code] }' of object 0,0 is not a function
    at _main (test.js:727:33)
    at Object.callMain (test.js:762:10)
    at run (test.js:779:18)
    at test.js:790:3

I'm going to guess they're not in FUNCTION_TABLE since they're normally dynamically linked functions. In this case however, since emscripten is providing equivalent functions for these cstdlib function calls, they should be added to FUNCTION_TABLE.

@kripken
Copy link
Member

kripken commented Jun 25, 2011

Heh, I did vaguely have an idea this could be a problem, the source contains

function indexizeFunctions(value) { // TODO: Also check for externals

which is the issue. Will fix this. Thanks for reporting it!

@kripken
Copy link
Member

kripken commented Jun 25, 2011

Fixed in 936ccd9

@kripken kripken closed this as completed Jun 25, 2011
@timdawborn
Copy link
Contributor Author

Thanks!

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