Running the Emscripten compiler on Android

1,167 views
Skip to first unread message

jrbru...@yahoo.com

unread,
Jul 17, 2014, 8:47:42 AM7/17/14
to emscripte...@googlegroups.com
I fascinated with the idea of using Android code editor/IDE (like DroidEdit or AIDE) to program C++ applications while on a phone.

I was wondering if there is a way to run emscripten on Android. Can I compile emscripten to android? Has anyone tried it?


Alon Zakai

unread,
Jul 17, 2014, 7:53:13 PM7/17/14
to emscripte...@googlegroups.com
If LLVM+clang, node.js and python work on android, then emscripten should.

- Alon



On Thu, Jul 17, 2014 at 5:47 AM, jrbrusseau via emscripten-discuss <emscripte...@googlegroups.com> wrote:
I fascinated with the idea of using Android code editor/IDE (like DroidEdit or AIDE) to program C++ applications while on a phone.

I was wondering if there is a way to run emscripten on Android. Can I compile emscripten to android? Has anyone tried it?


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jrbru...@yahoo.com

unread,
Jul 18, 2014, 1:41:58 PM7/18/14
to emscripte...@googlegroups.com
Looks like getting those to work on android is a bit tricky at least for node.js and python. I can't seem to find anything on running llvm and clang on android. Might need to play around with the android emulator and try some things.


On Thursday, July 17, 2014 6:53:13 PM UTC-5, Alon Zakai wrote:
If LLVM+clang, node.js and python work on android, then emscripten should.

- Alon

On Thu, Jul 17, 2014 at 5:47 AM, jrbrusseau via emscripten-discuss <emscripte...@googlegroups.com> wrote:
I fascinated with the idea of using Android code editor/IDE (like DroidEdit or AIDE) to program C++ applications while on a phone.

I was wondering if there is a way to run emscripten on Android. Can I compile emscripten to android? Has anyone tried it?


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

jrbru...@yahoo.com

unread,
Aug 22, 2014, 12:20:13 PM8/22/14
to emscripte...@googlegroups.com
Here's an update to my progress with this:

I only ran into a two problems compiling fastcomp (llvm & clang). The fix for them required minor changes to two files. I attached a diff with the changes I made. Though I haven't tested it on a new build.
  • The first was caused by Process.inc looking for unistd.h in sys which at least on android platform 9 it not.
    •    
       /home/bobajeff/Downloads/emscripten-fastcomp-1.22.1/lib/Support/Unix/Process.inc:39:24: fatal error: sys/unistd.h: No such file or directory

  • The second was cause by JITMemoryManager.cpp trying to use the open64 function which isn't available in Bionic (at least not platform 9).
    •  /home/bobajeff/Downloads/emscripten-fastcomp-1.22.1/lib/ExecutionEngine/JIT/JITMemoryManager.cpp:831:66: error: 'open64' was not declared in this scope

The first error was easy enough to fix. For the second error I studied Sean Childs' patch. Only the JITMemoryManager.cpp related bit though. I didn't yet know if I'd need the rest so I left those changes out (which turns out I didn't). I would probably still work if I reduced the coverage of the ifndef to only the open64 line.

Some how I have to test it on Android to see if it runs. I'll probably need to make JNI wrapper for it and package it as a apk. Other things I have yet to do is build python, node.js and emscripten. I expect I'll probably run into permissions issues with one more of those.
ndk_platform9_compat.diff

Alon Zakai

unread,
Aug 22, 2014, 7:07:35 PM8/22/14
to emscripte...@googlegroups.com
It sounds like these would be needed to run LLVM+clang on Android in general (not emscripten-specific)? Upstream LLVM sounds like the right place to push those fixes. Nice work!

- Alon



--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

jrbru...@yahoo.com

unread,
Aug 23, 2014, 9:47:17 PM8/23/14
to emscripte...@googlegroups.com
Thanks. No, I'm not committing code just providing documentation from my attempt. I'm sure the clang/llvm code has changed quite a bit from fastcomp's fork and I doubt my quick fix would be suitable for submission anyway.

Anyways, I managed to test my build on the Android SDK's VM and it seemingly works. It needs to use the commands not available on Android like 'as' and 'ld' so at the moment I haven't actually compiled anything with it but the preprocessor seems to work.

Using the guide at Keving Boon's guides helped me figure out how to run fastcomp (clang) on Android Terminal Emulator without root privilages. Many of the things I test in that but eventually got tired of not being able to cut and paste so I ended up using the adb shell (from android SDK) at some point which is swithed to root mode right now. So some tests weren't done completely rootless but I believe everything works without rooting.

BTW, last time I forgot to show how I built fastcomp. Reading Android NDK Cross-Compile Setup (libpng and freetype) and Manually building Fastcomp from source were all it took to get me going.

The commands I ended up using were:

After extracting fastcomp and renaming fastcomp-clang to clang and moving it to the tools subdirectory. Then entering the fastcomp directory I did:

mkdir build
cd build

export PLATFORM_PREFIX=/home/bobajeff/android-ext
export NDK_PATH=/home/bobajeff/Downloads/android-ndk-r10
export NDK_PLATFORM=android-9
export PATH=$PLATFORM_PREFIX/bin:$PATH

make

KEEP_SYMBOLS
=1 make install



Note KEEP_SYMBOLS=1 is neccessary because without it make install will fail because llvm will try to use my system's version of strip instead of the android ndk version of strip.

And to install it in android what I did was:

KEEP_SYMBOLS=1 make DESTDIR=/home/bobajeff/clangandroid install



So I wouldn't have the NDK files mixed in with fastcomps when I copied it over.

Then I did:

adt-bundle-linux-x86-20140702/sdk/platform-tools/adb install Term.apk



to install android terminal emulator.

adt-bundle-linux-x86-20140702/sdk/platform-tools/adb push /home/bobajeff/clangandroid/home/bobajeff/android-ext /data/data/jackpal.androidterm/shared_prefs



then I got emscriptens system folder and accidentaly merged it with my fastcomp rootdir (I wanted the system folder to be moved not the content of the folder)

adt-bundle-linux-x86-20140702/sdk/platform-tools/adb push system/ /data/data/jackpal.androidterm/shared_prefs



Here's output from running

bin/clang --save-temps hello_world.c -isystem/data/data/jackpal.androidterm/shared_prefs/include/libc -E



from inside /data/data/jackpal.androidterm/shared_prefs/

clang: warning: argument unused during compilation: '--save-temps'
# 1 "hello_world.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 151 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "hello_world.c" 2
# 1 "/data/data/jackpal.androidterm/shared_prefs/include/libc/stdio.h" 1 3







# 1 "/data/data/jackpal.androidterm/shared_prefs/include/libc/features.h" 1 3
# 9 "/data/data/jackpal.androidterm/shared_prefs/include/libc/stdio.h" 2 3
# 22 "/data/data/jackpal.androidterm/shared_prefs/include/libc/stdio.h" 3
# 1 "/data/data/jackpal.androidterm/shared_prefs/include/libc/bits/alltypes.h" 1 3






typedef __builtin_va_list va_list;




typedef __builtin_va_list __isoc_va_list;
# 111 "/data/data/jackpal.androidterm/shared_prefs/include/libc/bits/alltypes.h" 3
typedef unsigned int size_t;
# 126 "/data/data/jackpal.androidterm/shared_prefs/include/libc/bits/alltypes.h" 3
typedef int ssize_t;
# 213 "/data/data/jackpal.androidterm/shared_prefs/include/libc/bits/alltypes.h" 3
typedef int off_t;
# 361 "/data/data/jackpal.androidterm/shared_prefs/include/libc/bits/alltypes.h" 3
typedef struct _IO_FILE FILE;
# 23 "/data/data/jackpal.androidterm/shared_prefs/include/libc/stdio.h" 2 3
# 50 "/data/data/jackpal.androidterm/shared_prefs/include/libc/stdio.h" 3
typedef union _G_fpos64_t {
 
char __opaque[16];
 
double __align;
} fpos_t;

extern FILE *const stdin;
extern FILE *const stdout;
extern FILE *const stderr;





FILE
*fopen(const char *restrict, const char *restrict);
FILE
*freopen(const char *restrict, const char *restrict, FILE *restrict);
int fclose(FILE *);

int remove(const char *);
int rename(const char *, const char *);

int feof(FILE *);
int ferror(FILE *);
int fflush(FILE *);
void clearerr(FILE *);

int fseek(FILE *, long, int);
long ftell(FILE *);
void rewind(FILE *);

int fgetpos(FILE *restrict, fpos_t *restrict);
int fsetpos(FILE *, const fpos_t *);

size_t fread
(void *restrict, size_t, size_t, FILE *restrict);
size_t fwrite
(const void *restrict, size_t, size_t, FILE *restrict);

int fgetc(FILE *);
int getc(FILE *);
int getchar(void);
int ungetc(int, FILE *);

int fputc(int, FILE *);
int putc(int, FILE *);
int putchar(int);

char *fgets(char *restrict, int, FILE *restrict);

char *gets(char *);


int fputs(const char *restrict, FILE *restrict);
int puts(const char *);

int printf(const char *restrict, ...);
int fprintf(FILE *restrict, const char *restrict, ...);
int sprintf(char *restrict, const char *restrict, ...);
int snprintf(char *restrict, size_t, const char *restrict, ...);

int vprintf(const char *restrict, __isoc_va_list);
int vfprintf(FILE *restrict, const char *restrict, __isoc_va_list);
int vsprintf(char *restrict, const char *restrict, __isoc_va_list);
int vsnprintf(char *restrict, size_t, const char *restrict, __isoc_va_list);

int scanf(const char *restrict, ...);
int fscanf(FILE *restrict, const char *restrict, ...);
int sscanf(const char *restrict, const char *restrict, ...);
int vscanf(const char *restrict, __isoc_va_list);
int vfscanf(FILE *restrict, const char *restrict, __isoc_va_list);
int vsscanf(const char *restrict, const char *restrict, __isoc_va_list);

void perror(const char *);

int setvbuf(FILE *restrict, char *restrict, int, size_t);
void setbuf(FILE *restrict, char *restrict);

char *tmpnam(char *);
FILE
*tmpfile(void);




FILE
*fmemopen(void *restrict, size_t, const char *restrict);
FILE
*open_memstream(char **, size_t *);
FILE
*fdopen(int, const char *);
FILE
*popen(const char *, const char *);
int pclose(FILE *);
int fileno(FILE *);
int fseeko(FILE *, off_t, int);
off_t ftello
(FILE *);
int dprintf(int, const char *restrict, ...);
int vdprintf(int, const char *restrict, __isoc_va_list);
void flockfile(FILE *);
int ftrylockfile(FILE *);
void funlockfile(FILE *);
int getc_unlocked(FILE *);
int getchar_unlocked(void);
int putc_unlocked(int, FILE *);
int putchar_unlocked(int);
ssize_t getdelim
(char **restrict, size_t *restrict, int, FILE *restrict);
ssize_t getline
(char **restrict, size_t *restrict, FILE *restrict);
int renameat(int, const char *, int, const char *);
char *ctermid(char *);







char *tempnam(const char *, const char *);




char *cuserid(char *);
void setlinebuf(FILE *);
void setbuffer(FILE *, char *, size_t);
int fgetc_unlocked(FILE *);
int fputc_unlocked(int, FILE *);
int fflush_unlocked(FILE *);
size_t fread_unlocked
(void *, size_t, size_t, FILE *);
size_t fwrite_unlocked
(const void *, size_t, size_t, FILE *);
void clearerr_unlocked(FILE *);
int feof_unlocked(FILE *);
int ferror_unlocked(FILE *);
int fileno_unlocked(FILE *);
int getw(FILE *);
int putw(int, FILE *);
char *fgetln(FILE *, size_t *);
int asprintf(char **, const char *, ...);
int vasprintf(char **, const char *, __isoc_va_list);
# 2 "hello_world.c" 2

int main() {
  printf
("hello, world!\n");
 
return 0;
}
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

jrbru...@yahoo.com

unread,
Aug 23, 2014, 9:58:45 PM8/23/14
to emscripte...@googlegroups.com
I can't believe I forgot to show the configure flags I used (before make and after the export commands):

../configure --enable-optimized --disable-assertions --enable-targets=host,js --host=arm-linux-androideabi --prefix=$PLATFORM_PREFIX


jrbru...@yahoo.com

unread,
Aug 24, 2014, 9:25:59 PM8/24/14
to emscripte...@googlegroups.com
I got the hello_world.c file to compile and run.

In short I installed Binutils (for ld and as) and some libraries (.a and .so files) from the Android NDK to get it compile. Binutils I compiled myself but the libraries I just ripped from Android NDK hoping they would just work (which they did). It's also worth noting that right now the --save-temps and --sysroot are necessary becuase of the way everything is setup. I think I might be able to get it to work without those flags and more importantly I think emscripten might have problems with it if I don't.

I probably could've taken the ld and as from the NDK but I didn't think they were compiled for use on arm so I just grabbed NDK toolchain sources and built binutils-2.21 with NDK. I needed to make some changes to get it to compile which I included them in the diff attached to this post. I also needed to build and install texinfo to the NDK toolchain (binutils wouldn't complain about missing makeinfo) which thankfully was straightforward as no patches or other dependencies were needed.

So if I had to repeat the process again I would just do.

#retrieve the files
git clone https
://android.googlesource.com/toolchain/binutils
wget http
://ftp.gnu.org/gnu/texinfo/texinfo-5.2.tar.gz
tar
-zxvf texinfo-5.2.tar.gz

#set the environment variables

export PLATFORM_PREFIX=/home/bobajeff/android-ext
export NDK_PATH=/home/bobajeff/Downloads/android-ndk-r10
export NDK_PLATFORM=android-9
export PATH=$PLATFORM_PREFIX/bin:$PATH

#build and install texinfo to NDK toolchain
cd texinfo
-5.2
mkdir build
cd build
../configure --host=arm-linux-androideabi --prefix=$PLATFORM_PREFIX
make
make install

#build binutils
cd
../../binutils/binutils-2.21
#assuming the patch file is in the same location you cloned binutils
patch
-p1 < ../../binutils-2.21_sloppyquick_android_compat.diff
mkdir build
cd build
../configure --host=arm-linux-androideabi --prefix=$PLATFORM_PREFIX --with-sysroot
make
#Note: I'd already deleted the fastcomp files that were in clangandroid previously
make DESTDIR
=/home/bobajeff/clangandroid install




Then assuming everything went well you push binutils along with the necessary libraries to android terminal emulator:

#push binutils.
adt
-bundle-linux-x86-20140702/sdk/platform-tools/adb push /home/bobajeff/clangandroid/home/bobajeff/android-ext /data/data/jackpal.androidterm/shared_prefs

#push the libraries
adt
-bundle-linux-x86-20140702/sdk/platform-tools/adb push /home/bobajeff/android-ext/sysroot/usr/lib /data/data/jackpal.androidterm/shared_prefs/lib
adt
-bundle-linux-x86-20140702/sdk/platform-tools/adb push /home/bobajeff/android-ext/lib/gcc/arm-linux-androideabi/4.6/armv7-a/libgcc.a /data/data/jackpal.androidterm/shared_prefs/lib




If all goes well you should be able to compile from inside android terminal emulator by doing.

cd /data/data/jackpal.androidterm/shared_prefs/
bin
/clang --save-temps hello_world.c -isystem/data/data/jackpal.androidterm/shared_prefs/include/libc --sysroot=/data/data/jackpal.androidterm/shared_prefs/




On Thursday, July 17, 2014 7:47:42 AM UTC-5, jrbru...@yahoo.com wrote:
binutils-2.21_sloppyquick_android_compat.diff

jrbru...@yahoo.com

unread,
Aug 26, 2014, 3:55:47 PM8/26/14
to emscripte...@googlegroups.com
Here's another update on my progress:
Now I got python to build and run on android. (Tested it with a simply HelloWorld.py.)

I ran into a few issue with this one. First Android has some missing things in their lconv and passwd structs so I found some workarounds for those. But the big issue ultimately was that python it turns out isn't really designed with cross-compiling in mind. I didn't know this so when I ran into "error: undefined reference to '_PyParser_Grammar'" my search lead to believe it was issue with data race issue when running pygen (however that patch had already made it in my version). But eventually I stumbled upon another patch addressing pygen that looked applicable to what I'm doing and from there found this helpful post on it:  Cross-Compiling Python-2.7.5 for Embedded Linux it's from there I got most of the step to cross-compiling python for android.

I followed most of his guide but made a few adjustment for my process.

#get and extract the official python-2.7.5
wget http
://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
tar
-jxf Python-2.7.5.tar.bz2


#set toolchain environment variable

export PLATFORM_PREFIX=/home/bobajeff/android-ext
export NDK_PATH=/home/bobajeff/Downloads/android-ndk-r10
export NDK_PLATFORM=android-9
export PATH=$PLATFORM_PREFIX/bin:$PATH

#build python for build system
./configure
make
mv python python_for_build
mv
Parser/pgen Parser/pgen_for_build

#clean up and apply patches and changes
make distclean
#assuming you all ready copied over the patch
patch
-pl < Python-2.7.5-android-compat.diff
#note: this patch incorporates much but not all of whats in the Python-2.7.5-xcompile.patch (specifically it doesn't apply the Modules/Setup.dist changes since those caused problems)

#build python for the host/target system
./configure --host=arm-linux-androideabi --build=i686-pc-linux-gnu --prefix=$PLATFORM_PREFIX --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no ac_cv_have_long_long_format=yes
make
#again I already cleaned out clangandroid folder before doing this
make DESTDIR
=/home/bobajeff/clangandroid install



And to install in the Android Terminal Emulator:

adt-bundle-linux-x86-20140702/sdk/platform-tools/adb push /home/bobajeff/clangandroid/home/bobajeff/android-ext /data/data/jackpal.androidterm/shared_prefs



For my test i created a simple HelloWorld.py pushed it to android and then ran it like so:

cd /data/data/jackpal.androidterm/shared_prefs
bin
/python HelloWorld.py



And it works! Now onto nodejs.



On Thursday, July 17, 2014 7:47:42 AM UTC-5, jrbru...@yahoo.com wrote:
Python-2.7.5-android-compat.diff

jrbru...@yahoo.com

unread,
Aug 26, 2014, 6:20:12 PM8/26/14
to emscripte...@googlegroups.com
Quick Update:

I got nodejs built and running on android.

I went and tried the usual process from the Android NDK Cross-Compile Setup (libpng and freetype) article. Then quicky ran into a issue that nodes configure doesn't support the --host flag. Did a bit of searching and found out the newer versions (testing unstable) of nodejs have a configure script just for android. So I went and downloaded node-v0.11.9 from their website and tried some steps I saw other do with similar versions then ran into a error with node looking for bz2 module in python (which I guess NDK build doesn't have) fixed that and it worked.

Here's the build process:
#download nodejs
wget http
://nodejs.org/dist/v0.11.9/node-v0.11.9.tar.gz


#export toolchain environment variable

export PLATFORM_PREFIX=/home/bobajeff/android-ext
export NDK_PATH=/home/bobajeff/Downloads/android-ndk-r10
export NDK_PLATFORM=android-9
export PATH=$PLATFORM_PREFIX/bin:$PATH

#make necessary alterations for toolchain
cd node
-v0.11.9
# assuming your using the same version of NDK I am and have the patch for it
patch
-p1 < node-v0.11.9-android-ndk-r10.diff

#build and install nodejs
source
./android-configure $NDK_PATH
make
make DESTDIR
=/home/bobajeff/clangandroid install



this time it install to  a slightly different location but still contained in clangandroid. So to push it to android I did:

adt-bundle-linux-x86-20140702/sdk/platform-tools/adb push /home/bobajeff/clangandroid/usr/local /data/data/jackpal.androidterm/shared_prefs



Then your ready to test the node with a helloworld

cd /data/data/jackpal.androidterm/shared_prefs
bin
/node hello.js



And it works! Next it's finally time to see what I'm in for by trying to run Emscripten.


On Thursday, July 17, 2014 7:47:42 AM UTC-5, jrbru...@yahoo.com wrote:
node-v0.11.9-android-ndk-r10.diff

jrbru...@yahoo.com

unread,
Aug 27, 2014, 4:39:14 PM8/27/14
to emscripte...@googlegroups.com
Another update for everyone:

I already ran into a issue. Here's what happend:


I pushed the Emscripten folder to android.

adt-bundle-linux-x86-20140702/sdk/platform-tools/adb push empush_folder/ /data/data/jackpal.androidterm/shared_prefs



Then ran emcc from the android terminal emulator:

cd /data/data/jackpal.androidterm/shared_prefs
bin
/python2 emscripten-1.22.1/emcc -v



The result:

[2] + Stopped (signal)     bin/python emscripten-1.22.1/emcc -v
[1] - Segmentation fault   bin/python emscripten-1.22.1/emcc -v



I'm not quite sure what's going on there. I don't think any of these files are binaries so it can't be incompatible architecture or corruption of emcc. So that leaves maybe permissions issues, memory issues (though internal storage seems to be fine) maybe the Ram is too small (it's only 512MB), and/or something I haven't thought of. As usual I'll post back if I find something.


On Thursday, July 17, 2014 7:47:42 AM UTC-5, jrbru...@yahoo.com wrote:

jrbru...@yahoo.com

unread,
Aug 28, 2014, 11:50:48 AM8/28/14
to emscripte...@googlegroups.com
Update:

Found out what the signal stops and seg fault messages were. Apparently python is crashing. It look like I have some faulty modules in my build (shutil for example). So it crashes before it can get past the first import line in emcc. Haven't found a solution yet.

On Thursday, July 17, 2014 7:47:42 AM UTC-5, jrbru...@yahoo.com wrote:

jrbru...@yahoo.com

unread,
Aug 30, 2014, 10:18:02 PM8/30/14
to emscripte...@googlegroups.com
Update:

After trying several different ways to build python and not getting any builds with fully working modules I decided to give Python4Android a try specifically the Python2.7 fork of it. I looked at their guide on getting it to run the shell and then tested importing the modules that I was having trouble with (crashing python throwing error messages) before. And the modules worked I'm not sure what they did but I'm sure I was running into some android security enforced limitations or something and they must have did some workaround for those.

So I then pushed my builds of fastcomp, node and emscripten to /data/data/com.android.python27/files/

Then push the .emscripten file to /data/ which contains:
import os
LLVM_ROOT
='/data/data/com.android.python27/files/fastcomp/bin'
NODE_JS
='/data/data/com.android.python27/files/node/bin/node'
PYTHON
='/data/data/com.android.python27/files/python/bin/python'
EMSCRIPTEN_ROOT
='/data/data/com.android.python27/files/emscripten-1.22.1'
TEMP_DIR
= '/data/data/com.android.python27/files/temp'
COMPILER_ENGINE
= NODE_JS
JS_ENGINES
= [NODE_JS]



Then pushed the hello_world.c file to /data/ then ran the following in adb shell:

export PYTHONHOME=/data/data/com.android.python27/files/python
export PYTHONPATH=/sdcard/com.android.python27/extras/python:/data/data/com.android.python27/files/python/lib/python2.7/lib-dynload:/data/data/com.android.python27/files/python/lib/python2.7
export PATH=$PYTHONHOME/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/data/com.android.python27/files/python/lib:/data/data/com.android.python27/files/python/lib/python2.7/lib-dynload





cd
~ #that's /data/
python
/data/data/com.android.python27/files/emscripten-1.22.1/emcc hello_world.c



This is the result:
Stack dump:
0.    Program arguments: /data/data/com.android.python27/files/fastcomp/bin/lli /data/tmpbqS_LI.ll
1.    Running pass 'ARM Machine Code Emitter' on function '@main'
FAIL
: Running the generated program failed!



It basically creates a a.out.js and a.out.js.map with just version info and no logic.

On Thursday, July 17, 2014 7:47:42 AM UTC-5, jrbru...@yahoo.com wrote:

jrbru...@yahoo.com

unread,
Aug 31, 2014, 2:51:28 AM8/31/14
to emscripte...@googlegroups.com
Success!!!

I did a little searching and found out that lli's default jit doesn't work very well on Arm so I tried to switch it to using mc-jit instead. It took me forever to figure out the python script I needed to edit in order to add the -use-mcjit  flag to lli (tools/gen_struct_info.py). But sadly I got a message saying "No available targets are compatible with this  triple, see -version for the available targets." I'm not sure why if it was to do with how I built fastcomp or if it's just and order version because I was under the impression that mc-jit was well supported on armv7-a. But I discovered another option in lli: -force-interpreter. So I used that flag and it works! I tested hello_world.c again and it generated a working html and js file.

Next, I need to get everything to work in Android Terminal Emulator so I can actually use it on a phone without rooting. I also would like to figure out if I can rebuild fastcomp to support mc-jit.

Just so this post doesn't feel so empty, here's some output from running "EMCC_DEBUG=1 python /data/data/com.android.python27/files/emscripten-1.22.1/emcc hello_world.c -o hello.html" bare in mind this is still the notoriously slow android emulator:
DEBUG    root: JAVA not defined in ~/.emscripten, using "java"
WARNING  root: invocation: /
data/data/com.android.python27/files/emscripten-1.22.1/emcc hello_world.c -o hello.html  (in /data)
WARNING  root
: did not see a source tree above the LLVM root directory (guessing based on directory of /data/data/com.android.python27/files/fastcomp/bin/llc), could not verify version numbers match
INFO     root
: (Emscripten: Running sanity checks)
WARNING  root
: java does not seem to exist, required for closure compiler. -O2 and above will fail. You need to define JAVA in ~/.emscripten
DEBUG    root: compiling to bitcode
DEBUG    root: emcc step "parse arguments and setup" took 0.16 seconds
DEBUG    root: compiling source file: hello_world.c
DEBUG    root: running: /
data/data/com.android.python27/files/fastcomp/bin/clang -target asmjs-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=22 -D__EMSCRIPTEN_tiny__=1 -Werror=implicit-function-declaration -nostdinc -Xclang -nobuiltininc -Xclang -nostdsysteminc -Xclang -isystem/data/data/com.android.python27/files/emscripten-1.22.1/system/local/include -Xclang -isystem/data/data/com.android.python27/files/emscripten-1.22.1/system/include/compat -Xclang -isystem/data/data/com.android.python27/files/emscripten-1.22.1/system/include -Xclang -isystem/data/data/com.android.python27/files/emscripten-1.22.1/system/include/emscripten -Xclang -isystem/data/data/com.android.python27/files/emscripten-1.22.1/system/include/libc -Xclang -isystem/data/data/com.android.python27/files/emscripten-1.22.1/system/lib/libc/musl/arch/js -Xclang -isystem/data/data/com.android.python27/files/emscripten-1.22.1/system/include/gfx -Xclang -isystem/data/data/com.android.python27/files/emscripten-1.22.1/system/include/SDL -Xclang -isystem/data/data/com.android.python27/files/emscripten-1.22.1/system/include/libcxx -emit-llvm -c hello_world.c -o /data/data/com.android.python27/files/temp/tmpjeesGs/hello_world_0.o
DEBUG    root
: emcc step "bitcodeize inputs" took 0.56 seconds
DEBUG    root
: emcc step "process inputs" took 0.01 seconds
DEBUG    root
: will generate JavaScript
DEBUG    root
: including libc
DEBUG    root
: emcc step "calculate system libraries" took 0.44 seconds
DEBUG    root
: linking: ['/data/data/com.android.python27/files/temp/tmpjeesGs/hello_world_0.o', '/data/.emscripten_cache/libc.bc']
DEBUG    root
: emcc: llvm-linking: ['/data/data/com.android.python27/files/temp/tmpjeesGs/hello_world_0.o', '/data/.emscripten_cache/libc.bc'] to /data/data/com.android.python27/files/temp/tmpjeesGs/hello.bc
DEBUG    root
: emcc step "link" took 0.95 seconds
DEBUG    root
: saving intermediate processing steps to /data/data/com.android.python27/files/temp/emscripten_temp
DEBUG    root
: emcc: LLVM opts: -internalize -internalize-public-api-list=main,malloc,free -globaldce -pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt -enable-emscripten-cxx-exceptions
DEBUG    root
: emcc step "post-link" took 0.85 seconds
DEBUG    root
: LLVM => JS
DEBUG    root
: JAVA not defined in ~/.emscripten, using "java"
DEBUG    root: emscript: llvm backend: /
data/data/com.android.python27/files/fastcomp/bin/llc /data/data/com.android.python27/files/temp/tmpjeesGs/hello.bc -march=js -filetype=asm -o /data/data/com.android.python27/files/temp/emscripten_temp/tmp0lvRuU.4.js -emscripten-assertions=1 -emscripten-no-aliasing-function-pointers -O0 -emscripten-max-setjmps=20
DEBUG    root
:   emscript: llvm backend took 0.889282941818 seconds
DEBUG    root
: emscript: js compiler glue
DEBUG    root
:   emscript: glue took 15.9426500797 seconds
DEBUG    root
: asm text sizes[[105216, 1849, 25], 24, 130, 1210, 0, 0, 29, 274, 234, 679, 1372]
DEBUG    root
:   emscript: final python processing took 0.154012918472 seconds
DEBUG    root
: emcc step "emscript (llvm=>js)" took 20.06 seconds
DEBUG    root
: emcc step "source transforms" took 0.01 seconds
DEBUG    root
: emcc step "js opts" took 0.01 seconds
DEBUG    root
: generating HTML
DEBUG    root
: emcc step "final emitting" took 4.67 seconds
DEBUG    root
: total time: 27.72 seconds




On Thursday, July 17, 2014 7:47:42 AM UTC-5, jrbru...@yahoo.com wrote:
lli_force-interpreter.diff

JF Bastien

unread,
Aug 31, 2014, 6:20:56 PM8/31/14
to emscripte...@googlegroups.com
I may be misunderstanding what you're doing, but if you're generating JavaScript code then you shouldn't need MC JIT or the interpreter: the JavaScript code gets emitted from LLVM IR, whereas MC JIT and the interpreter consume LLVM IR to generate ARM instructions or interpret the IR. It's a bit clunky that they're built into fastcomp, but disentangling then from the build wasn't worth it, and it's nice to keep the compiler fully functional (not just having one possible backend).

As Alon said it would be great if you sent your patches for the bionic build to upstream LLVM, feel free to add me to the code review. These parts probably haven't changed much upstream versus the current fastcomp base (LLVM 3.4). I'm in the process of updating the branch to LLVM 3.5 (which should be stable soon), so any patch you send upstream will be very close to my soon-to-be-update version (and in the future we'll be updating things more frequently than every LLVM release).


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

jrbru...@yahoo.com

unread,
Aug 31, 2014, 10:28:19 PM8/31/14
to emscripte...@googlegroups.com
Then I don't understand why the interpreter is called on by Emscripten's Python scripts if it's not needed. Also, I'll see if I can submit the patches upstream (after cleaning them up a little bit).

Now for an Update on getting everything running rootless in the Android Terminal Emulator:

Well, I was going get everything to work with Android Terminal Emulator but since I can't cut and paste to Android Emulator I wanted something that can run bash scripts so I went with Terminal IDE (as an added bonus I get vim to edit with). So to get Python working Terminal IDE you need to:

1)Install Python4Android (We only need it to extract neccassary files to the sdcard.)

2)Extract the PythonAPK.apk file then extract ./PythonAPK.apk_FILES/res/raw/python_27.zip and push it's files /data/data/com.spartacusrex.spartacuside/files/ Push the ./PythonAPK.apk_FILES/lib/armeabi/libcom_googlecode_android_scripting_Exec.so to /data/data/com.spartacusrex.spartacuside/lib/ (I believe this is their hack to get the modules working in Android).

3)Push the built fastcomp, node along with Emscripten's files to /data/data/com.spartacusrex.spartacuside/files/

In Terminal IDE's ~/ (/data/data/com.spartacusrex.spartacuside/files/)

Put the following .bashrc (I think I might have overwrote the default one when I pushed it there):
export PYTHONHOME=/data/data/com.spartacusrex.spartacuside/files/python
export PYTHONPATH=/sdcard/com.android.python27/extras/python:/data/data/com.spartacusrex.spartacuside/files/python/lib/python2.7/lib-dynload:/data/data/com.spartacusrex.spartacuside/files/python/lib/python2.7
export PATH=$PYTHONHOME/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/data/com.spartacusrex.spartacuside/files/python/lib:/data/data/com.spartacusrex.spartacuside/files/python/lib/python2.7/lib-dynload



Then put this in .emscripten:
import os
LLVM_ROOT
='/data/data/com.spartacusrex.spartacuside/files/fastcomp/bin'
NODE_JS
='/data/data/com.spartacusrex.spartacuside/files/node/bin/node'
PYTHON
='/data/data/com.spartacusrex.spartacuside/files/python/bin/python'
EMSCRIPTEN_ROOT
='/data/data/com.spartacusrex.spartacuside/files/emscripten-1.22.1'
TEMP_DIR
= '/data/data/com.spartacusrex.spartacuside/files/tmp'

COMPILER_ENGINE
= NODE_JS
JS_ENGINES
= [NODE_JS]



And everything works just as well as it did in ADB Shell; no root required. Note I've yet to test on an actual phone yet but I'm confident that the Android Emulator's permissions restrictions are being fully applied here based on a test I did by trying to load a path outside of TerminalIDE (and failing).
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

bobajeff

unread,
Sep 6, 2014, 8:13:52 PM9/6/14
to emscripte...@googlegroups.com
Update:

Just thought I'd let you know. I made a fork of VimTouch with all the necessary emscripten builds included in it. It's very buggy and I don't plan to work on it any further. But if anyone wants working builds of Fastcomp, Python and Node they are all in the res/raw part of the repository. At some point I'll put up the patches, source files and build commands in a repository. Also, I'm still going to try and upstream some of the Clang stuff even though they just released a new one.

They project is here:
https://github.com/bobajeff/vimtouch-emscripten-remix

bobajeff

unread,
Sep 6, 2014, 8:17:17 PM9/6/14
to emscripte...@googlegroups.com
Correction res/raw is the old directory they are actually in the assets/ directory now. They are renamed mp3 to get around an issue with APK compression.

bobajeff

unread,
Sep 11, 2014, 12:00:22 PM9/11/14
to emscripte...@googlegroups.com
Just a small slightly offtopic update: I've finally got around to submitting patches upstream to the LLVM project based off of the master branch. The patches are different. I'm not sure if it's because it's newer or because I was doing the Debug+Asserts build.
Reply all
Reply to author
Forward
0 new messages