trzecieu / emscripten-docker

Docker image with Emscripten to compile ASM.js and WebAssembly
MIT License
97 stars 29 forks source link

Add precached LTO variants of libraries #67

Closed RReverser closed 4 years ago

RReverser commented 4 years ago

I've noticed that, when building with LTO (most of my projects), the standard libraries are rebuilt on each invocation of docker run. This is noticeable from logs e.g.:

cache:INFO: generating system library: libc-wasm.a... (this will be cached in "/emsdk_portable/.data/cache/wasm-lto/libc-wasm.a" for subsequent builds)

At the same time, /emsdk_portable/.data/cache/wasm are available within the container.

It appears that the reason is that images are shipped with standard C / C++ libraries precompiled and cached as part of the image, but only without LTO flag (LTO uses LLVM IR bitcode as object files, so has to be compiled separately).

Would it be possible to add LTO variants too?

trzecieu commented 4 years ago

I think so! Good idea!

trzecieu commented 4 years ago

Hi, I see that there is an attempt in your case to create a new cache entry under wasm-lto but I have a difficult to reproduce it. Simple command doesn't work.

em++ test.cpp -flto -o test.js -s WASM=1

Is it possible for you to share compilation flags?

trzecieu commented 4 years ago

I've addressed blindly this issue in the commit ec1eaff, I will update images soon with that change.

RReverser commented 4 years ago

em++ test.cpp -flto -o test.js -s WASM=1

Hmm, I'll need some time to get around but could you try adding optimisation and/or debug flags?

trzecieu commented 4 years ago

I've tested a various of flags under 1.39.5 - nothing has worked unfortunately. Some images have been already updated with precompiled LTO, i.e:

RReverser commented 4 years ago

Ah, it probably depends on contents of your test.cpp and which libraries end up being linked. If it's not using the standard library, it might be skipping these compilations altogether.

as I've found that this emscripten-core/emscripten#10603 might be related

Unlikely - that issue is just about size inefficiency, which is not very related.

trzecieu commented 4 years ago

So I've added a bunch of most common libs to cache with lto, please check if something missing I can add explicitly to the list : )

Thanks!