SPO600 Lab2

Adam Chimienti

107904156

SPO600

Lab2 Compiler C Lab

For this lab I will write a very simple “Hello World!” program in C. I will then compile the program several different times with different options in the command line. I will analyze the different results that each of the command line options yield. I will also test these results over different architectures, and for this I will be using our default SPO600 servers aarchie which is a standard set up, and ccharlie chich has 8GB of RAM and 40GB of space. The default compiler command we will enter at the beginning will be “gcc  -g -O0 -fno-builtin – o hello hello.c” The different compiler options will be listed and a description will follow.

1) Add -static to the command line

The file size is almost 10X as large, the header call is “free_mem” instead of “init”, also the function call is ”IO_printf”. Static is used to instruct the compiler to link statically against the C runtimes libraries.

 

2) Remove -fno-builtin from the command line

The file is the same size as the default command, however the function call is “puts” instead of “printf”. This is because -fno-builtin tells the compiler not to recognize built-in functions that do not being with __builtin__ as a prefix. This means there are a whole host of library functions that the compiler will not recognize. Thus removing the -fno-builtin from the compiler command allows it to use the easiest to find and resolve function to optimize results.

 

3)Remove -g from the command line.

The file is a bit smaller than the default one. The section header is listed as “init”. I did not happen to notice any other changes from the main compiler command. The command -g produces debugging information in the operating system’s native format. Thus the shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values were already at hand; some statements may execute in different places because they were moved out of loops. Although I did not notice these changes.

 

4) Add additional arguments to the printf() function in your program (go up to 10 arguments)

What happened here is when looking at the compiler up until the 7th variable, after that it no longer registers in the compiler they simply come up as zero values,  and the str or store register command appears, and tries to store SP or and address into w0 instead of w1, w2, w3 etc.

 

5) Move the printf call to a separate function named output() and call that function from main().

The function call is “output” not “printf” or “puts”. Ardp, add and .inst are no longer there as well. The file seems to be ever so slightly larger, probably due to the few extra lines of code.

 

6) Remove -O0 and add -O3 to the gcc options.

The command -O0 before meant “do not optimize” and this is default. The -O3 option turns on all optimizations specified by -O2 and turns on “-fineline-functions” and “-frename-registers” options. So this options compared to the main one is that -O3 does not have mov, and it also does not have .insta probably due to maximizing the optimization.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s