On Sep 18, 2006, Roman Kononov <[EMAIL PROTECTED]> wrote:

> Merge can be safely done like this:
> If both functions A and B are not inlined functions, and they have
> single entry points, and memcmp of their asm code is zero, and the
> code is large enough, then the asm code of the functions B is replaced
> by "jmp A" instruction.

The linker already has code to merge sections.  There's nothing to
stop us from compiling every function into say:

foo:
  jmp .foo.impl
.section .gnu.impl.foo, "axM"
.foo.impl:
  [actual code for foo emitted]
.previous

Then the linker doesn't need any smarts whatsoever to merge functions
with identical code.  Hmm, maybe it does, since it must compare
relocations as well, but this doesn't sound too hard at first.

For extra bonus points, it may short-circuit relocations that call foo
(as opposed to taking its address) when it binds locally and skip the
jmp altogether.  Ditto for *all* relocations that reference foo, when
it doesn't merge .foo.impl with anything else.

-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Secretary for FSF Latin America        http://www.fsfla.org/
Red Hat Compiler Engineer   [EMAIL PROTECTED], gcc.gnu.org}
Free Software Evangelist  [EMAIL PROTECTED], gnu.org}

Reply via email to