Skip to content

Instantly share code, notes, and snippets.

@bvibber
Created October 25, 2019 22:38
Show Gist options
  • Save bvibber/ef605cb6b71a81c763c59ed15efd9a78 to your computer and use it in GitHub Desktop.
Save bvibber/ef605cb6b71a81c763c59ed15efd9a78 to your computer and use it in GitHub Desktop.
Demo of Linux 'strip' command damaging emscripten .a files

With the 'strip' in the Makefile:

$ make
emcc  -c -o b.o b.c
emcc  -c -o a.o a.c
emar crs liba.a a.o
# Removing this 'strip' results in not failing
strip liba.a
strip:liba.a(a_66244f1c.o): Unable to recognise the format of file: file format not recognized
emcc  -o b.js -L. -la b.o
wasm-ld: error: ./liba.a: archive has no index; run ranlib to add one
shared:ERROR: '/home/brion/src/emsdk/upstream/bin/wasm-ld -o /tmp/emscripten_temp_HVxR_2/b.wasm --allow-undefined --lto-O0 -L. ./liba.a -L/home/brion/src/emsdk/upstream/emscripten/system/local/lib b.o -L/home/brion/src/emsdk/upstream/emscripten/system/lib -L/home/brion/.emscripten_cache/wasm-obj /home/brion/.emscripten_cache/wasm-obj/libc.a /home/brion/.emscripten_cache/wasm-obj/libcompiler_rt.a /home/brion/.emscripten_cache/wasm-obj/libc-wasm.a /home/brion/.emscripten_cache/wasm-obj/libdlmalloc.a /home/brion/.emscripten_cache/wasm-obj/libpthread_stub.a /home/brion/.emscripten_cache/wasm-obj/libc_rt_wasm.a --import-memory --import-table -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export __wasm_call_ctors --export __data_end --export main --export malloc --export free --export setThrew --export __errno_location --export fflush -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (1)
make: *** [Makefile:21: b.js] Error 1

Without the 'strip' in the Makefile, it builds as expected.

Tested on Ubuntu 19.04 with emscripten 1.39.0 LLVM backend (where it fails) and Fastcomp backend (where it compiles through anyway).

#include "a.h"
int func_a(void) {
return 42;
}
extern int func_a(void);
#include <stdio.h>
#include "a.h"
int main(int argc, const char **argv) {
printf("%d\n", func_a());
return 0;
}
CFLAGS=
all : b.js
clean :
rm -f a.o b.o liba.a b.js b.wasm
a.o : a.c a.h
emcc $(CFLAGS) -c -o a.o a.c
b.o : b.c a.h
emcc $(CFLAGS) -c -o b.o b.c
liba.a : a.o
emar crs liba.a a.o
# Removing this 'strip' results in not failing
strip liba.a
b.js : b.o liba.a
emcc $(CFLAGS) -o b.js -L. b.o -la
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment