[LLVMdev] Implementing the hotpatch attribute for X86

Charles Davis cdavis at mymail.mines.edu
Mon Nov 8 08:44:24 PST 2010


On 10/27/10 2:34 AM, Anton Korobeynikov wrote:
>> I don't know how GCC handles this case. They may do the padding in the
>> compiler. You are going to have to look at exactly what GCC does and
>> whatever hotpatch loader Wine uses to figure out what to do, but it
>> will most likely be incompatible with the Windows implementation.
> Why? I don't see how this might be incompatible with what MS linker does;
> in any case the end result should be the same.
> 
> gcc just emits series of bytes before the function (16 in 32 bit code,
> 32 - in 64 bit code).
> 0xcccccccc is used as a filler.
Sorry it took me so long to get back. I was busy with school.

All right, so I know that there are two things I have to do:

- Emit some padding before the function, and
- Make sure the first instruction in the prologue is at least two bytes
long.

What I really want to know is how I would go about doing them. That's
why I started this thread in the first place. Again, I'm not too
familiar with the x86 backend or how it works. To be honest, looking at
it myself makes it seem overwhelming to me.

I remember the emitPrologue method from the force_align_arg_pointer
work, but I don't know how I would go about meeting that second
requirement. I'm thinking of emitting a two-byte nop (0x66 0x90), but I
don't know how to do that yet. Or do any of you have a better idea? (By
the way, IIRC MSVC emits a 'mov %edi, %edi' instruction, whose encoding
is (0x8b 0xff).)

As for the padding, it seems to me that the easiest way to do that is to
increase the function's alignment. But this won't work when the function
is already aligned. I think we have to emit the padding when we emit the
function itself. But again I have no idea how to go about doing that.
What should I do?

Chip



More information about the llvm-dev mailing list