1

I have an executable i build on Ubuntu 16.04. The file size shown on the GUI and through the ls -l command is:

-rwxrwxr-x 1 alibivmuser alibivmuser 19108760 dic 20 15:49 NreSpeechApplication

And I know this means the actual size of the file is 19 MB. On my file system, the size is somehow similar (using ls -s):

18664 NreSpeechApplication

I expected the size output of the size command in Linux would give something similar, but it shows as a total more or less 1.8 MB:

text    data     bss     dec     hex filename
1806360    2416    4552 1813328  1bab50 NreSpeechApplication

So my question is: why the two results are so different? And where do these additional MBs come from to form 18MB from 1.8?

2

size shows the traditional sections of an executable file.

Notice that these traditional sections do not include debugging information, for example. Debugging information takes up a lot of space. For a complete list of sections, run objdump -h NreSpeechApplication

The total (dec/hex) is not directly tied to filesize for another reason: it includes bss. This section is initialized to zero when loading the executable, therefore it is not included in the file.

It's also possible the file is just abnormal, e.g. has random garbage added on the end :).

1
  • Thanks!! With objdump I can see that most of the space is used by debug_info – Carlo Benussi Dec 23 '16 at 9:01
3

ls shows the size of the actual file, the amount of bytes when you open and read it.

If you want to know how much space the file takes on your disk you should use du -h. du takes into account the blocks of the filesystem.

Example: If you have a file with the size of 1500 and your block size is 1024, du should show 2048 (because the file does not 'fit' into one block, while ls will show you 1500.

size shows the size of the runtime image of your executable. As in, your executable will use about 1.8MB of RAM/ROM. This is not directly related to the size of the file.

If you want to know how much RAM/ROM an executable will take excluding dynamic memory allocation, size gives you the information you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.