This lab will investigate the differences in compiler options by compiling a simple “Hello World” program. The changes for each GCC compiler option can affect the size, lines of code, the execution of code, the use of libraries, and so on.
(1) Add the compiler option -static.
Note and explain the change in size, section headers, and the function call.
The –static option links a program statically and prevents the use of using shared libraries, making the file much larger than without the option. The other change is that <_IO_printf> is called instead, again also due to the -static option.
(2) Remove the compiler option -fno-builtin. Note and explain the change in the function call.
The difference with removing this compiler option is that it calls put() instead of printf(). According to https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html , the -fno-builtin “results in code is often both smaller and faster, but since the function calls no longer appear as such, you cannot set a breakpoint on those calls, nor can you change the behavior of the functions by linking with a different library.” Without it, it seems that put() is called by default here.
(3) Remove the compiler option -g. Note and explain the change in size, section headers, and disassembly output.
Removing the compiler option -g results in a smaller sized file, which makes sense since the debugging information is removed.
(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).
The arguments put into the printf function add some data stored into registers. It seems like some arguments have their own register and others have their own.
(5) Move the printf() call to a separate function named output(), and call that function from main(). Explain the changes in the object code.
The difference here is that the <main> calls <output>, which in turn calls the printf in the code.
(6) Remove -O0 and add -O3 to the gcc options. Note and explain the difference in the compiled code.
Changing from -O0 to –O3 is supposed to have a higher level of optimization – meaning the program should run faster, according to https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-O3. The mov $0x0,%eax is changed to xor %eax,%eax.