SPO600 Lab4 Compiled C Lab

Hi all, I was assigned to work in my lab for my SPO600 class. Here is the outline of the specifications:

Create a C program to print “Hello Word” and compile with -g, -O0, -fno-builtin. Use objdump to analysis the object.

(1) Add the compiler option -static. Note and explain the change in size, section headers, and the function call.

With -static:
-rwxrwxr-x. 1 qdtran qdtran 682979 Feb 7 11:20 a.out
Without -static:
-rwxrwxr-x. 1 qdtran qdtran 8486 Jan 31 12:50 a.out
The size of the static file is much bigger than the original one. Because it imports the all the library that was in the program.

(2) Remove the compiler option -fno-builtin. Note and explain the change in the function call. When

When objdump the object we see that the function puts@plt is used instead of the printf@plt. The compiler tries to find differents function to increase the speed of the program.

(3) Remove the compiler option -g. Note and explain the change in size, section headers, and disassembly output. This will reduce the size of the file because we don’t enable the debugging option in the program.

This will reduce the size of the file because we don’t enable the debugging option in the program.

(4) Add additional arguments to the printf() function in your program. Note which register each argument is placed in. (Tip: Use sequential integer arguments after the first string argument. Go up to 10 arguments and note the pattern).

We note that there are more registers being use to store arguments for the program. The arguments are put on stack.

(5) Move the printf() call to a separate function named output(), and call that function from main(). Explain the changes in the object code.

Creating a function in the separate part and call it will be less efficient than coding them as in line format which will create high optimization and only gets called once.

(6) Remove -O0 and add -O3 to the gcc options. Note and explain the difference in the compiled code.

with -O0 the compiler has less debugging information and optimization. While The -O3 has more debugging information and optimization.