0

My professor showed us the following slide while trying to explain why executables are so large, but I still don't get it.

We eliminated everything in the assembly program yet it's still HUGE compared to what it contains (4 lines of code which are less than 1kb)....

Can someone help me understand?

enter image description here

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
algo
  • 101
  • 6
  • define executable? what file format? did you examine the file format? Understanding what is in that file and why? How many binary file formats did you convert it to and did you see how they vary in size? Did you strip the file? do you know what that tool does and how it may affect the file size of different file formats? – old_timer Oct 07 '21 at 18:48
  • [Editing an ELF executable to reduce it's size](https://stackoverflow.com/q/35389087/995714), [Analyzing an ELF binary to minimize its size](https://stackoverflow.com/q/25513771/995714) – phuclv Oct 07 '21 at 18:50
  • 2
    If you don't need any libraries, you can use the `-static` option when linking with `gcc`. This will reduce the file size massively (on my computer: about 900 instead of about 8000 bytes). If you don't use the option, `-dynamic` is assumed. This will add information needed for loading dynamic libraries - although you don't load any dynamic library. – Martin Rosenau Oct 07 '21 at 19:15
  • 1
    You're right, it's not very small. See [Minimal executable size now 10x larger after linking than 2 years ago, for tiny programs?](https://stackoverflow.com/q/65037919). (And note that using `ld` directly is equivalent to `gcc -static -nostdlib -no-pie`; modern Linux distros config GCC to make PIEs by default, so old tutorial examples often don't account for that. It used to be that `gcc -nostdlib` would make a static executable by default because a non-PIE with no libraries might as well be static, unlike with a PIE where runtime fixups need to happen for any absolute addresses ) – Peter Cordes Oct 07 '21 at 20:03

0 Answers0