SPO Lab 4 compiled C Code

In this lab, we need to analyze the ELF file after we have compiled a hello world program. We use -g -o0 -fno-bultin when we compiled then did a objdump with -f -s -d –source in order to see more detail of are compiled programs. We then had to recompile the code with some command changes and not the difference. Overall it was a pretty straight forward lab.

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

A) This option allows you to pull the whole library that was needed to complete your program. One thing noted is that library’s drastically use up a lot more space than I thought

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

A)  Instead of using the printf() function it replaces it with puts() instead.

(3) Remove the compiler option -g. Note and explain the change in size, section headers, and disassembly output.

A)  This reduced the size of the output file because all of the debugging information was taken out.

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

A)  After a certain amount of arguments, the stack and file size stopped increasing. It seemed this decreased the performance of the program and it needs more memory in order to get the rest of the arguments.

(5) Move the printf() call to a separate function named output(), and call that function from main(). Explain the changes in the object code. It becomes inline and is only called once.

A) It becomes inline and is only called once.

 

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

A) With -0o the compiler adds less debugging information and has the least optimization, while -03 adds more debugging information, but it takes longer to compile as it is trying to figure out the best way to optimize the program and also reduce its size.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s