Complied C Lab
In this lab, we were asked to compile a C program, using gcc command with different options.
At the beginning of this lab, we wrote a simple C program that prints a message:
Then using gcc command and the following compiler options to compile the program:
Note that the size of file is 73088 bytes
We can use objdump --source a.out command to show source code, the source code is under <main> section. And readelf -p .rodata a.out contains the string to be printed.
Then we add the option "-static" to recompile the program, found out the size is changed to 696264 bytes, which is bigger than the original program. And section headers are also increased.
Next, I removed the builtin function optimization by remove option "-fno-builtin", and rebuilt the program. Note that the size is smaller than using the built-in function to 696256 bytes.
Then I disabled debugging information by removing option "-g"
Note that the size is smaller to 693840 bytes
And there are also more section headers and disassembly outputs.
With adding a number to the argument of printf() function, we note the argument is assigned to a register and added to a stack, and moved.
Finally, I added an option "-O3" instead of "-O0", which is stand to optimization level to 3, I found that the size is not changed, but the lines are less than original.
In this lab, we were asked to compile a C program, using gcc command with different options.
At the beginning of this lab, we wrote a simple C program that prints a message:
Then using gcc command and the following compiler options to compile the program:
-g # enable debugging information -O0 # do not optimize (that's a capital letter and then the digit zero) -fno-builtin # do not use builtin function optimizations
Note that the size of file is 73088 bytes
We can use objdump --source a.out command to show source code, the source code is under <main> section. And readelf -p .rodata a.out contains the string to be printed.
Then we add the option "-static" to recompile the program, found out the size is changed to 696264 bytes, which is bigger than the original program. And section headers are also increased.
Next, I removed the builtin function optimization by remove option "-fno-builtin", and rebuilt the program. Note that the size is smaller than using the built-in function to 696256 bytes.
Then I disabled debugging information by removing option "-g"
Note that the size is smaller to 693840 bytes
And there are also more section headers and disassembly outputs.
With adding a number to the argument of printf() function, we note the argument is assigned to a register and added to a stack, and moved.
Finally, I added an option "-O3" instead of "-O0", which is stand to optimization level to 3, I found that the size is not changed, but the lines are less than original.
Comments
Post a Comment