Default output format for emcc

146 views
Skip to first unread message

Xuejie Xiao

unread,
Jan 8, 2013, 12:37:03 PM1/8/13
to emscripte...@googlegroups.com
Hi there,

I'm not sure whether this is a bug or a design decision, so I will just post it here instead of opening an issue.

According to here: https://github.com/kripken/emscripten/blob/master/emcc#L356, it seems that the default output format is the JavaScript file. However, if I omit the ".js" suffix, the result will be a LLVM bitcode file(main.c file is just a minimal c source file including a main function):

$ emcc main.c -o main
$ file main
main: data
$ hexdump -n 16 main
0000000 42 43 c0 de 21 0c 00 00 98 00 00 00 0b 82 20 00
0000010

The first two characters of the output file is thus "BC", I assume that this is a LLVM bitcode file, right?

So is there any plan to fix this? Thanks for your help!

-Xuejie Xiao

Alon Zakai

unread,
Jan 8, 2013, 8:58:44 PM1/8/13
to emscripte...@googlegroups.com
Yeah, it is intentional, and the docs look out of date - I'll fix those, thanks for reporting.

Basically, our default is to compile to bitcode. Compiling to JS or HTML requires saying that you want that. This approach is the best we found for fitting into project build systems, see more details and explanations here

https://github.com/kripken/emscripten/wiki/Building-Projects

- azakai

Xuejie Xiao

unread,
Jan 9, 2013, 10:56:22 AM1/9/13
to emscripte...@googlegroups.com
Thanks for your reply! Sorry I'm not sure I got your meaning, so I will just write what I thoughts here:

Normally in a project we are referring to binaries if we specify an output file name without extensions. Such as the following:

$(LD) $(LDFLAGS) main.o lib.so -o main

Here the generated main file usually is a binary, however, emcc would emit a bitcode file, we have to do more steps here:

$ cp main main.bc
$ emcc main.bc -o main.js

The cp is here because emcc uses extensions to distinguish file type(or maybe I'm wrong here? Is there a better way?). So if we have to go through this copy and linking everywhere, why not just emit the JavaScript file at first place(the main file)?

I didn't mean here that we should change the spec. I just didn't quite understand here what you mean by "fitting into project build systems". Is there anything I'm missing? I would really appreciate it if you can help me point it out:)

- Xuejie Xiao

Best Regards,

肖雪洁
Xuejie(Rafael) Xiao

Alon Zakai

unread,
Jan 10, 2013, 6:07:04 PM1/10/13
to emscripte...@googlegroups.com
Yes, what you wrote is correct: if you generate "main" in your project, you would need to rename it to main.bc, then compile that to JS.

The renaming is just because we rely on suffixes. That could be fixed, but it would mean that we need to look inside input files to see if they are bitcode or text etc., which adds overhead. That's why this wasn't fixed already.

The manual step of compiling bitcode to JS is necessary because our build system builds and links bitcode, using llvm-link. If we generated JS at each step, we would need to write a linker for JS files which is a lot of work that I wanted to avoid.

- azakai

Xuejie Xiao

unread,
Jan 10, 2013, 7:51:53 PM1/10/13
to emscripte...@googlegroups.com
That makes sense, now I know how it works. Thanks for your help!

Best Regards,

肖雪洁
Xuejie(Rafael) Xiao



Reply all
Reply to author
Forward
0 new messages