www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why is the compiled file size so huge?

reply Alexander Zhirov <azhirov1991 gmail.com> writes:
I'm trying to compile a file that weighs 3 kilobytes. I'm also 
linking a self-written dynamic library. I don't understand why 
the resulting executable file is so huge? After all, all 
libraries are present:

```sh
-rwxr-xr-x 1 root root 6.3M May 27 13:39 app
-rw-r--r-- 1 root root 2.9K May 27 12:57 app.d
-rw-r--r-- 1 root root  25K May 27 13:39 app.o
```

```sh
ldc2 -O app.d -L-lpq -L-lX11 -L-lXrandr -L-lm -L-lmira
```

```sh
	linux-vdso.so.1 (0x00007fff3a5bf000)
	libpq.so.5 => /usr/lib/libpq.so.5 (0x00007fe89f8a7000)
	libX11.so.6 => /usr/lib/libX11.so.6 (0x00007fe89f763000)
	libXrandr.so.2 => /usr/lib/libXrandr.so.2 (0x00007fe89f756000)
	libm.so.6 => /lib/libm.so.6 (0x00007fe89f611000)
	libmira.so => /usr/lib/libmira.so (0x00007fe89f4c7000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x00007fe89f4a6000)
	librt.so.1 => /lib/librt.so.1 (0x00007fe89f499000)
	libdl.so.2 => /lib/libdl.so.2 (0x00007fe89f493000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fe89f479000)
	libc.so.6 => /lib/libc.so.6 (0x00007fe89f2af000)
	/lib64/ld-linux-x86-64.so.2 => /lib/ld-linux-x86-64.so.2 
(0x00007fe89f91b000)
	libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007fe89f284000)
	libXau.so.6 => /usr/lib/libXau.so.6 (0x00007fe89f27f000)
	libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007fe89f275000)
	libbsd.so.0 => /usr/lib/libbsd.so.0 (0x00007fe89f25c000)
	libXext.so.6 => /usr/lib/libXext.so.6 (0x00007fe89f247000)
	libXrender.so.1 => /usr/lib/libXrender.so.1 (0x00007fe89f23a000)
	libphobos2-ldc-shared.so.99 => 
/root/dlang/ldc-1.29.0/bin/../lib/libphobos2-ldc-shared.so.99 
(0x00007fe89ed89000)
	libdruntime-ldc-shared.so.99 => 
/root/dlang/ldc-1.29.0/bin/../lib/libdruntime-ldc-shared.so.99 
(0x00007fe89ec3b000)
(dmd-2.100.0)
```
May 27 2022
next sibling parent rempas <rempas tutanota.com> writes:
On Friday, 27 May 2022 at 13:40:25 UTC, Alexander Zhirov wrote:
 I'm trying to compile a file that weighs 3 kilobytes. I'm also 
 linking a self-written dynamic library. I don't understand why 
 the resulting executable file is so huge? After all, all 
 libraries are present:
 [...]
I did a similar question in a C forum regarding an huge file sizes of GCC compared to manually writing assembly and linking (at least for the smallest possible program on Linux) and well... You won't get an answer!
May 28 2022
prev sibling next sibling parent user1234 <user1234 12.dr> writes:
On Friday, 27 May 2022 at 13:40:25 UTC, Alexander Zhirov wrote:
 I'm trying to compile a file that weighs 3 kilobytes. I'm also 
 linking a self-written dynamic library. I don't understand why 
 the resulting executable file is so huge? After all, all 
 libraries are present:
I'd take a look with IDA or hydra to check the details (maybe something is statically linked after all, that should be visible by inspecting the names view) but one thing to understand in a first time is that 1. even if druntime and phobos are dynamic libraries all the template instances are generated in your binary. 2. use of some module has for effect to create huge static tables. I think to all the UTF stuff and also std regex.
May 28 2022
prev sibling next sibling parent zjh <fqbqrr 163.com> writes:
On Friday, 27 May 2022 at 13:40:25 UTC, Alexander Zhirov wrote:
 I'm trying to compile a file that weighs 3 kilobytes. I'm also 
 linking a self-written dynamic library. I don't understand why 
 the resulting executable file is so huge?
I just switched from `32-bit` to 64 bit, but the '64' bit program is too large. I'm going to continue compiling into 32-bit.
May 28 2022
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 5/27/22 9:40 AM, Alexander Zhirov wrote:
 I'm trying to compile a file that weighs 3 kilobytes. I'm also linking a 
 self-written dynamic library. I don't understand why the resulting 
 executable file is so huge? After all, all libraries are present:
 
 ```sh
 -rwxr-xr-x 1 root root 6.3M May 27 13:39 app
 -rw-r--r-- 1 root root 2.9K May 27 12:57 app.d
 -rw-r--r-- 1 root root  25K May 27 13:39 app.o
 ```
 
I'd say 2.9k of source is enough to produce a large binary. But looking at your *object file*, it shouldn't be much bigger than that, especially if all libs are dynamic. Try ldc2 -v and see if there's any clues as to what else it's linking. You should be able also to use nm to spit out all the symbols defined in the binary, maybe there's some that you wouldn't expect to be there. -Steve
May 28 2022