In: Computer Science
UNIX/LINUX LAB
(1) Compile hello.c program: gcc hello.c -o hello
(2) Compile hello.c program with -static option: gcc -static hello.c -o hello1
(3) Use size command to see the memory layout of these two programs (hello and hello1).
(4) Write a brief summary of what you have noted here.
Submit the session history (log) of this activity and a brief summary.
hello.c program bottom //////////// #include <stdio.h> #include <stdlib.h> int main() { printf("Hello World\n"); // waw hello Richard and ok exit(0); // end of the program }
vi hello.c
cat hello.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello World\n"); // waw hello Richard and ok
exit(0); // end of the program
}
$ gcc hello.c -o hello
$ gcc -static hello.c -o hello1
$ size hello
text data bss dec hex filename
1297 556 4 1857 741 hello
$ size hello1
text data bss dec hex filename
533437 3456 12408 549301 861b5 hello1
$ history
1158 vi hello.c
1159 gcc hello.c -o hello
1160 gcc -static hello.c -o hello1
1161 size hello
1162 size hello1
1163 history
Size command : Size command takes the argument of
the file name. If none are specified, the file a.out will be
used.
It outputs text, data, bss, dec, hex, and filename.
Text column displays the actual machine instructions that CPU is
going to execute.
Data column displays all initialized variables declared.
Bss column displays uninitialized data such as arrays or null
pointers.
When we compile a file with -static option, It links a program statically, that is it does not require a dependency on dynamic libraries at runtime in order to run. Also, In the above observation, when we compile with static option (i.e. when the hello1 file is generated, values of text, data and bss are increased).