I have a certain a project consisting of multiple *.cpp files which I compile using g++.
I changed one source file to add some code. Built the project again . Just to check I did
diff -s origbinaryfile changedbinaryfile
It showed me that files are identical, which was strange as I have added a extra code and was hoping to see a difference in the generated linux binaries.
I have added a code which is a extra case statement in a existing switch case code .e.g.
Earlier I had
switch(x) {
case DEV1:
...
case DEV2:
...
Changed one is
switch(x) {
case DEV1:
...
case DEV2:
...
case DEV3:
DEV1, DEV2, DEV3 are enumerators of a enum declaration.
How can I verify using nm command or any other command to see if that added code is really present in the binary?
Any other way?
[It might sound silly but I did it carefully to make sure I was not making any error in compiling]
You can not.
Of course you can disassemble your files and compare asm code, but it’s so heavily optimized by compiler that you’ll hardly get any meaningful results by such method.
Alternatively you can compare your files using
cmpcommand, it’s intended for binary files and will likely be more adequate thandiff.However binary difference is not 100% guarantee that any code was actually changed. Compilers usually add debug info and compile timestamps, so same code compiled twice in a row will result in two binaries that have different bytes.