Lab3

Compiled C Lab






Let's start by writing the hello world.



then with this saved we can run the compiler with the Flags specified 

                   gcc -g -O0 -fno-builtin hello.c


Looking at the objdump header file for our program
Objdump -f



We see that:

Were using an x86 platform

File Format is in ELF (Executable and Linkable Format)

We can look at the specific selections of this output file by using objdump with -d flag which disassemble sections containing code

Objdump -d



This is our main!

We can see the function call to printf with callq on line 5.

The argument was moved into the register on line 4.


- Static

gcc -g -O0 -fno-builtin -static hello.c -o hellostatic

objdump -s hellostatic



The file was huge, when read wouldn't fit in the whole window!

This is due to the .static flag.  It causes the libraries to be included in the executable because it prevents dynamic linking to libraries .

 objdump -d



One interesting change is that instead of printf it has _IO_printf without the @plt stub

I think this is due to the libraries in the first one needed to be shared and linked so it needed to use the secure @plt stub.

FileSize is much different then the first

Filesize1: 10.8 KB
Filesize staic: 847.2 KB

-fno-buildin





No -g



Additional Arguments





We can see that there are more movs as we need to move the data we need to print!



Output Function



Things are separated into the functions, we can see our output function
We continue to use @plt as the libs are shared

No 0O


The More optimized compiler looks alot different, One thing is that there is only 1 mov compared to the 3 or 4 from the non optimized version




After exploring some compiler flags I can see that they can have a large effect on things no matter the size of the program. Even our simple hello world program has many differences between 03 and 0O which i didnt think was going to happen. Optimization can happen in many ways and we should always keep an open mind as to how to improve our programs performance

Comments

Popular posts from this blog

Stage 2: CowPatty

Cowpatty!