strip(1) vs. llvm-strip(1) vs. strip via ld.lld(1).

Hi fellows!

I'm playing with stripping the binaries and I found that there are several ways to perform this task and they work slightly differently. They are strip(1), llvm-strip(1) and stripping via ld.lld(1).
I'm on 13.4-RELEASE and using a standard toolchain for compiling (LLVM, clang(1)).

So, I created a sample C program hello.c:
C:
#include<unistd.h>
int main() {
    write(1, "hello, world!\n", 14);
    return 0;
}
and created different binaries out of it using above-mentioned tools:

1) unstripped (default, via clang(1)):
cc -o hello-unstripped hello.c

2) stripped via strip(1):
cc -o hello-strip hello.c && strip ./hello-strip

3) stripped via llvm-strip(1):
cc -o hello-llvm-strip hello.c && llvm-strip ./hello-llvm-strip

4) and finally stripped via passing a clang(1) -Xlinker option -s for the ld.lld(1) linker:
cc -o hello-ld-strip -Xlinker -s hello.c

and this is what I got:
-rwxr-xr-x 1 artembunichev wheel 5000 Jan 2 13:15 hello-ld-strip
-rwxr-xr-x 1 artembunichev wheel 4744 Jan 2 13:15 hello-llvm-strip
-rwxr-xr-x 1 artembunichev wheel 5000 Jan 2 13:14 hello-strip
-rwxr-xr-x 1 artembunichev wheel 6504 Jan 2 13:13 hello-unstripped


As you can see, strip(1) and ld.lld(1) stripping produce binaries with the same size. And llvm-strip(1) reduces the size better.

Well, there is no a particular question from me, just basic curiosity of mine: why do we have such results?
None of these programs mention each other in their manual pages, and as I can see, these tools aren't the same program either (not hard-linked):
$ which strip llvm-strip llvm-strip15 | xargs ls -l
-r-xr-xr-x 2 root wheel 4609104 Jan 1 16:28 /usr/bin/llvm-strip
-r-xr-xr-x 2 root wheel 126776 Jan 1 16:28 /usr/bin/strip
-r-xr-xr-x 115 root wheel 285 Sep 5 09:12 /usr/local/bin/llvm-strip15


Moreover, ld.lld(1) and llvm-strip(1) are both from the same LLVM project, so why does ld.lld(1) doesn't use llvm-strip(1) (which seems to perform the task better) under the hood? I also supposed that it should be easier to strip the binary in the compilation process (just don't include the symbols so that we won't need to strip them back) rather than do this with a separate tool post-factum.

What from these tools (or maybe other tools as well) do you guys use to strip your binaries?


Artem.
 
Back
Top