I suggest as first step to understanding where the large size you have experienced and are wondering about comes from to check out:
https://unix.stackexchange.com/questions/2969/what-are-stripped-and-not-stripped-executables-in-unix
The extremely large (24 MByte) size of the executable you are wondering about is caused by debugging information inserted into the executable by the compiler and by the fact the the executable is not stripped and containing symbols. According to what is stated in GNU emacs manual, the standard configuration of the source code package available for download specifies the -g flag for the gcc compiler to include debug information.
Check it out yourself using the file
command to see if the executable contains debugging information and is a stripped one:
~ $ file emacs-28.2.1
ELF 64-bit [...skipped some info...], with debug_info, not stripped
In other words if you compare sizes you should first make sure that the compared executable files are without debugging information and stripped.
See below the effect of applying strip
which removes symbols and debug information from an executable to tmacs
, one of the identical emacs executable files you mention in your question:
~ $ strip temacs
~ $
~ $ ls -il *emacs*
4873475 -rwxrwxr-x 1 neo neo 24566712 Mar 14 16:45 bootstrap-emacs
4873479 -rwxrwxr-x 2 neo neo 24566712 Mar 14 16:45 emacs
4873479 -rwxrwxr-x 2 neo neo 24566712 Mar 14 16:45 emacs-28.2.1
4873473 -rwxrwxr-x 1 neo neo 6349376 Mar 17 17:37 temacs
As you can see above emacs and emacs-28.2.1 occupy the same storage space in the file system (have the same inode) and the stripped temacs shrinked from 24 MByte to 6 MByte.
P.S. thanks goes to matteol which helpful comment to my question put me on the right track and made this answer possible.