Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sstrip for better stripping and other notes #1

Open
ghost opened this issue Apr 24, 2023 · 1 comment
Open

Use sstrip for better stripping and other notes #1

ghost opened this issue Apr 24, 2023 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 24, 2023

I recently discovered an interesting tool - sstrip, see https://man.archlinux.org/man/community/elfkickers/sstrip.1.en
https://www.muppetlabs.com/~breadbox/software/elfkickers.html

sudo pacman -S elfkickers

It's a better strip that strips everything that isn't needed for the binary to run.

Also, FYI, -s for the C compiler is worse than using strip, so it should always be done.

Default repo (I don't have musl-* stuff):

 98.2 KiB 
 67.3 KiB -d:release
 39.6 KiB -d:release --passC:-flto --passL:-flto
 34.5 KiB -d:release --passC:-flto --passL:-flto --passL:-s
 26.5 KiB -d:release --passC:-flto --passL:-flto --passL:-s --opt:size
  6.1 KiB -d:release --opt:size --panics:on -d:useMalloc --os:any -d:posix -d:noSignalHandler --cc=clang --clang.exe='/home/dian/Projects/NimExperiments/binary-size/zigcc' --clang.linkerexe='/home/dian/Projects/NimExperiments/binary-size/zigcc' --passC:'-flto -target x86_64-linux-musl' --passL:'-flto -target x86_64-linux-musl'

Use the strip command in the code for all compilers, not just zig cc:

 82.4 KiB 
 58.4 KiB -d:release
 34.4 KiB -d:release --passC:-flto --passL:-flto
 34.4 KiB -d:release --passC:-flto --passL:-flto --passL:-s
 26.4 KiB -d:release --passC:-flto --passL:-flto --passL:-s --opt:size
  6.1 KiB -d:release --opt:size --panics:on -d:useMalloc --os:any -d:posix -d:noSignalHandler --cc=clang --clang.exe='/home/dian/Projects/NimExperiments/binary-size/zigcc' --clang.linkerexe='/home/dian/Projects/NimExperiments/binary-size/zigcc' --passC:'-flto -target x86_64-linux-musl' --passL:'-flto -target x86_64-linux-musl'

Use sstrip -z {filename} instead:

80.3 KiB 
56.3 KiB -d:release
32.3 KiB -d:release --passC:-flto --passL:-flto
32.3 KiB -d:release --passC:-flto --passL:-flto --passL:-s
24.3 KiB -d:release --passC:-flto --passL:-flto --passL:-s --opt:size
 5.3 KiB -d:release --opt:size --panics:on -d:useMalloc --os:any -d:posix -d:noSignalHandler --cc=clang --clang.exe='/home/dian/Projects/NimExperiments/binary-size/zigcc' --clang.linkerexe='/home/dian/Projects/NimExperiments/binary-size/zigcc' --passC:'-flto -target x86_64-linux-musl' --passL:'-flto -target x86_64-linux-musl'

As you can see, it saves ~1KB for zig cc and ~2KB for other compilers, for free :)

@ghost ghost changed the title Use sstrip Use sstrip for better stripping Apr 24, 2023
@ghost
Copy link
Author

ghost commented Apr 24, 2023

Some other notes:

IMO zig cc should also be tried with both Glibc (dynamic linking) and musl, but without all the os:any/useMalloc/posix stuff, basically same as other options.

For example:

nim c -d:release --opt:size --cc=clang --clang.exe='/home/dian/Projects/NimExperiments/binary-size/zigcc' --clang.linkerexe='/home/dian/Projects/NimExperiments/binary-size/zigcc' --passC:'-flto -target x86_64-linux-gnu' --passL:'-flto -target x86_64-linux-gnu' -o:helooo --gc:arc hello.nim

after sstrip results in a 16KB glibc-linked binary (8KB smaller than the same with GCC), which is really interesting

And yeah, any reason you're not testing with -d:danger as well?

@ghost ghost changed the title Use sstrip for better stripping Use sstrip for better stripping and other notes Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants