WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Playing around with strip, llvm-strip, sstrip  (Read 2689 times)

Offline polikuo

  • Hero Member
  • *****
  • Posts: 714
Playing around with strip, llvm-strip, sstrip
« on: February 07, 2022, 08:24:38 AM »
I'm recompiling extensions on x86_64 and decide to try out different stripping tools.
The library is already stripped during the compilation.
Since the extension is enormous, I'm checking out different ways to reduce the overall size.
Therefore, I'm stripping an already stripped shared object.

I'm encountering interesting phenomenons with a particular binary.
llvm-strip returns 1 and refuse to strip.
Then I strip it with the usual GNU strip
The size stays the same, but diff reports they're different
Now, with llvm-strip, it returns 0, the error is gone.
Code: [Select]
$ ls
libvk_swiftshader.so.orig
$ cp libvk_swiftshader.so.orig libvk_swiftshader.so.gnu
$ cp libvk_swiftshader.so.orig libvk_swiftshader.so.llvm
$ strip --strip-unneeded libvk_swiftshader.so.gnu
$ llvm-strip --strip-unneeded libvk_swiftshader.so.llvm
llvm-strip: error: program header with offset 0x407f90 and file size 0x40070 goes past the end of the file
$ du -b *
4488304 libvk_swiftshader.so.gnu
4488304 libvk_swiftshader.so.llvm
4488304 libvk_swiftshader.so.orig
$ diff -sq libvk_swiftshader.so.orig libvk_swiftshader.so.gnu
Files libvk_swiftshader.so.orig and libvk_swiftshader.so.gnu differ
$ diff -sq libvk_swiftshader.so.orig libvk_swiftshader.so.llvm
Files libvk_swiftshader.so.orig and libvk_swiftshader.so.llvm are identical
$ strip --strip-unneeded libvk_swiftshader.so.llvm
$ llvm-strip --strip-unneeded libvk_swiftshader.so.llvm
$ echo $?
0
$ du -b *
4488304 libvk_swiftshader.so.gnu
4488304 libvk_swiftshader.so.llvm
4488304 libvk_swiftshader.so.orig
$ diff -sq libvk_swiftshader.so.gnu libvk_swiftshader.so.llvm
Files libvk_swiftshader.so.gnu and libvk_swiftshader.so.llvm differ

Now adding sstrip to the fun  :D
Woah! :o
This is the first time I'm seeing sstrip adding weight to a binary.
Then I find out if you join forces, with this particular order, it's possible to drop the section header.
Code: [Select]
$ cp libvk_swiftshader.so.orig libvk_swiftshader.so.sstrip
$ sstrip libvk_swiftshader.so.sstrip
$ du -b *
4488304 libvk_swiftshader.so.gnu
4488304 libvk_swiftshader.so.llvm
4488304 libvk_swiftshader.so.orig
4489216 libvk_swiftshader.so.sstrip
$ cp libvk_swiftshader.so.orig libvk_swiftshader.so.all
$ strip --strip-unneeded libvk_swiftshader.so.all
$ llvm-strip --strip-unneeded libvk_swiftshader.so.all
$ sstrip libvk_swiftshader.so.all
$ file *
libvk_swiftshader.so.all:    ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), BuildID[sha1]=3ac7cba3b980738c950b4f65063d26a2bdea49cd, dynamically linked, no section header
libvk_swiftshader.so.gnu:    ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=3ac7cba3b980738c950b4f65063d26a2bdea49cd, stripped
libvk_swiftshader.so.llvm:   ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=3ac7cba3b980738c950b4f65063d26a2bdea49cd, stripped
libvk_swiftshader.so.orig:   ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=3ac7cba3b980738c950b4f65063d26a2bdea49cd, stripped
libvk_swiftshader.so.sstrip: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=3ac7cba3b980738c950b4f65063d26a2bdea49cd, stripped
$ du -b *
4485864 libvk_swiftshader.so.all
4488304 libvk_swiftshader.so.gnu
4488304 libvk_swiftshader.so.llvm
4488304 libvk_swiftshader.so.orig
4489216 libvk_swiftshader.so.sstrip

Does anyone know anything with this behavior ?

P.S. How about the section header, how do I know if it's OK to drop that ?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14790
Re: Playing around with strip, llvm-strip, sstrip
« Reply #1 on: February 07, 2022, 09:09:35 AM »
Whilst sstrip seems to work well on small simple binaries, I've seen problems in the past with large ones.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11041
Re: Playing around with strip, llvm-strip, sstrip
« Reply #2 on: February 07, 2022, 01:42:56 PM »
sstrip shouldn't be used on libraries, IIRC.
The only barriers that can stop you are the ones you create yourself.