How can I generate completely static binaries with clang? I have used the following command:
clang -flto <source files> -o <executable output> -fuse-ld=lld -static-libgcc -lc -Bstatic -m32
And yet, the generated output depends on a certain .so
file:
$ ldd <executable output file>
linux-gate.so.1 => (0xf77dd000)
libc.so.6 => /lib/libc.so.6 (0xf75f0000)
/lib/ld-linux.so.2 (0x5663b000)
The following answer tries to answer the question but doesn't directly address the problem.
Is it even possible, to generate completely independent binaries? Or should I have resort to using other different C library implementations other than libgcc
?
If yes, then how do I link it with clang if I have the source code, of for example newlib
?
linux-gate.so
is the syscall interface andld-linux.so
is the ELF binary interpreter (See: #19982362). You might be able to get a statically linked version oflibc
but the others need to be there. This begs the question: "Why?" and "What is the ultimate purpose?" Unless you're doing a boot loader or some such ... – Gemeinschaftlibc.so
, you usually get an executable that is less portable. – Schadenfreude