Is it possible to optimize a compiled binary?

This is more of a curiosity, I suppose, but I was wondering if compiler compilation can be applied after compilation. Are most optimization methods highly IR-dependent or can be easily moved back and forth?

+7
optimization assembly compiler-construction
source share
3 answers

This was done, although I do not know many standard tools that do this.

This document describes the optimizer for Compaq Alpha processors, which works after the connection has already been completed, and some of the problems they encountered while writing.

If you define the definition a bit, you can use the profile-oriented optimization to process the binary, and then rewrite it based on its observed behavior regarding cache misses, page errors, etc.

There has also been some work in dynamic translation in which you run an existing binary in the interpreter and use standard dynamic compilation methods to try to speed it up. Here is one document that details this.

Hope this helps!

+4
source share

This space has been interested in a recent interest in research. The Alex Aiken STOKE project does just that with some pretty impressive results. In one example, their optimizer discovered a function that is twice as fast as gcc -O3 for the Montgomery Multiplication step in the OpenSSL RSA library. It applies these optimizations to already compiled ELF binaries.

Here is a link to the article.

+2
source share

Some compilers have a spy optimizer that basically does just that, before it moves on to an assembly that represents IR, it has little opportunity for optimization.

Basically, you would like to do the same thing, from binary, machine code to machine code. Not the same tool, but the same process, consider the code size block and optimize it.

Now there is a problem that you will have to face, although, for example, you may have had some variables that were marked volatile in C, so they are very inefficiently used in binary format, the optimizer does not know what programmers want there, and can end up optimizing this is.

Of course, you can take it to IR and forward it again, nothing to stop you from doing this.

+1
source share

All Articles