3 ms·
Building your code (I fixed a few typos, strings -> symbols, fprintf(" -> fprintf(stderr, ") with gcc -s -Os -fuse-ld=lld a.c && ls -al a.out leads to a 5
by rfoo 3y ago
Building your code (I fixed a few typos, strings -> symbols, fprintf(" -> fprintf(stderr, ") with
gcc -s -Os -fuse-ld=lld a.c && ls -al a.out
leads to a 5496 bytes ELF though. Which is not much larger than just printf("Hello World!\n"), see sibling comment.
I think the point is C "cheated" by including a lot of goodness (format, backtrace etc) in the shared library so they does not have to be copied to each binary.
- lifthrasiir 3y agoThank you for the actual testing (and sorry for typos...). Yes, a C version is small because it dynamically links to libc.so in this case, and I meant to compare against a statically linked version. I primarily wrote this example as a response to the claim that an equivalent---it isn't---C code with musl is very small.
- pca006132 3y agoThe problem is musl does not support execinfo. For a simple hello world, I managed to statically link with musl to get something with 7888 bytes.