Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can gcc linker options change assembler instructions in the compiled binary?

I am wondering if gcc linker options (e.g.: -Wl,options) can change assembler instructions in the compiled executable, as this happens if you use certain gcc optimization options? Can the difference between using a linker option and not using it be seen when you compare the compiled binaries (e.g. comparing signatures)?

UPDATE

To be more precise I want to figure out if FLIRT signatures change when I use certain linking options during compilation process. These signatures only use library functions for creating the signatures.

like image 993
Maximilian Avatar asked May 17 '16 12:05

Maximilian


2 Answers

For some linker options, changes can be seen in the produced binary, for example:

  • Options to get rid of/keep debugging symbols (--strip-all, --strip-debug, --discard-all)
  • Options to get rid of/keep unused sections, e.g. a section containing a function that is never referenced in other sections. These sections can easily be removed. Or to keep relocation sections/content. (--as-needed, --emit-relocs)
  • Options to include one static library or another compatible one (For example library version x.0 vs version x.1)
  • The order in which objects and static libraries are placed on the commandline. For example ld -o foo a.obj b.obj c.obj and ld -o foo a.obj c.obj b.obj will probably produce a different binary if a call from a to a function in c is resolved (the offset for the code from c.obj and thus the address of the function in c will probably be different)

But even after linking, the signature of a binary could change. For example in Linux, when you optimize binary startup time by running prelink

like image 79
Elijan9 Avatar answered Sep 27 '22 19:09

Elijan9


Yes, you will see a different checksum on two binaries linked with different linker options--unless the option had no effect, such as when you specify a default option or an option that doesn't change the binary (-print-map).

What are you trying to figure out exactly? It sounds like you are having problems when you specify certain linker options and you are trying to figure out why. Tell us more and maybe we can give better assistance.

like image 22
Daniel Wisehart Avatar answered Sep 27 '22 20:09

Daniel Wisehart