Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Section 7.7, why does the size of executable file differ so dramatically when

ID: 3723662 • Letter: I

Question

In Section 7.7, why does the size of executable file differ so dramatically when we use shared libraries for such a trivial program?

Most UNIX systems today support shared libraries. Arnold [1986] describes an early implementation under System V, and Gingell et al. 1987] describe a different implementation under SunOS. Shared libraries remove the common library routines from the executable file, instead maintaining a single copy of the library routine somewhere in memory that all processes reference. This reduces the size of each executable file but may add some runtime overhead, either when the program is first executed or the first time each shared library function is called. Another advantage of shared libraries is that library functions can be replaced with new versions without having to relink edit every program that uses the library (assuming that the number and type of arguments haven't changed). rogram to say that it wants to use or not use the shared libraries. Options for the cc(1) and ld(1) commands are typical. As wing executable file-the classic hello.c Different systems provide different ways for a p an example of the size differences, the follo program-was first created without shared libraries: prevent gcc from using shared libraries $ gcc -static hellol.c $ ls -l a.out -rwxr-xr-x 1 sar $ size a.out 879443 Sep 2 10:39 a.out hex filename data 6128 11272 805175 C4937 a.out text bss dec 787775 If we compile this program to use shared libraries, the text and data sizes of the executable file are greatly decreased gec defaults to use shared libraries $ gcc hellol.c $ ls -l a.out -rwxr-xr-x $ size a.out 1 sar 8378 Sep 2 10:39 a.out text 1176 data 504 bss 16 dec 1696 hex filename 6a0 a.out

Explanation / Answer

Hi Student,

Please find the answer below :

Let us try to understand two import aspects :

1. Static Linking [ gcc -static hello1.c ]

Static linking is the process of copying all library modules used in the program into the final executable image.A library contains hundreds or thousands of object files. Becuse of this when we are using the -static it is forcing the linker to link all the library modules which inturn is having a huge impact on the size. One advantage would be that the -static option does not require a dependency on dynamic libraries at runtime in order to run.

2. Dynamic Linking

On the other hand, Dynamic linking defers much of the linking process until a program starts running. It performs the linking process "on the fly" as programs are executed in the system. So the libraries are used as and when they are required on the fly on the basis of the requirement. Thus there is no overhead of the libraries linking and hence the size is significantly diminished.

Hope you like this answer! If yes, give a thumbs up! Happy Learning :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote