Safe Identical Code Folding for X86-64.

John Reiser
Fri Jan 22 05:51:00 GMT 2010

On 01/21/2010 05:42 PM, Sriraman Tallam wrote:

> If bar calls foo and does not use a relocation for foo and uses a
> displacement instead, it is somehow guaranteed that foo and bar will
> be linked with that displacement.

Correct.  The compiler translates directly from source (.c or .cc, etc.)
to object (.o), without going through any text-based assembly language.
The compiler says, "If I can see a suitable target for a CALL, then I
will address the target directly via pc-relative addressing with a
numerical constant displacement and no relocation record."

>  That, in effect, rules out any kind of folding, not just safe, right ?

Folding still is possible.  However it requires an analysis that understands
the meaning of compiled instructions, and not just 'join' operations over
tables of Elf64_Rela, Elf64_Sym, etc.  Inter-linking of code compiled
by different compilers can be an adventure, too.  The specifications
such as an ABI (Application Binary Interface) often do not mention
all of the properties that a simple implementation of code folding
might want to assume.


More information about the Binutils mailing list