This lab was done on x86_64 Architecture
The first image was compiled using the following command
gcc -g -O0 -fno-builtin
followed by
objdump -fs --source (program_name_here)
The following is an output of the main from the objdump command.
(1)
The following is an output adding the -static command when compiling, you will notice at 401bc3, instead of calling printf like the original, _IO_printf is called. The file is also a lot larger at 1720912 bits vs 22272 (standard). The reason being for this is because the executable must have all library files ready within its own executable file.
(2)
The following is an output by removing the -no-built-in command when compiling, so we're using built in function optimizations. At 40112f instead of printf being called, a puts function is called instead.
(3)
The following is an output by removing the -g command when compiling, skipping debugging information. You'll notice the line printf("Hello World!\n"); is missing now right after 401127, as this information is only useful for debugging... and we've told the compiler we don't need debugging info, it does not bother outputting any of that info, making the program smaller as well. Although the current size of the files are at 22272 vs 22272 bits each, we only have a few lines in our program (the printf line) so the savings by not using -g are non perceptible.
(4)
The following is an output by adding more arguments at the end of the printf. In my example I added an integer, float and another string. You'll notice there are much more lines in this <main> than any of the other images. This is because the we need more registers to hold the additional integer,, float and string values I added which is accomplished by the extra mov and movq.
(5)
The following is an output by moving the printf function in the main method to another function called output() and calling output() in the main method. You'll notice instead of calling printf, the program is instead calling output.
(6)
The following is an output by modifying the -O0 option when compiling which uses minimal optimization to -O3 ... make as many optimizations as possible, even ones that may be dangerous for certain programs. The program skips the first step entirely from the original and puts the printf line right onto the current location in stack. Instead of the mov of a value into the eax register, it does a xor of the register with itself
No comments:
Post a Comment