[llvm] r196334 - [Stackmap] Emit multi-byte nops for X86.

Juergen Ributzka juergen at apple.com
Wed Dec 4 11:00:38 PST 2013


Hi Rafael,

I already tried going down that path and adding emitNops to MCObjectStreamer was pretty easy, because you just need to add a fill fragment (and add nop emission support). Once that fragment gets emitted to the object file it simply calls the target specific writeNopData method. Unfortunately that doesn’t work for MCAsmStreamer. MCAsmStreamer just emits an align directive to perform the code alignment and the assembler that has to later on parse the assembly file has to deal with it. I don’t want to align the code - I need a nop slide of a given size that can be patched later on. I could take the raw bytes from writeNopData and write them with byte directives to the asm file, but that would be really ugly. Another way is to change the interface and implementation of writeNopData and return a vector of MCInst instructions that can be emitted by both - MCObjectStreamer and MCAsmStreamer. Besides changing every backend implementation it also would require some more work on X86 to emit operations with multiple OpSize prefixes which isn't supported either. It’s a lot of changes to all targets (that don’t even need it) just to make the X86 case work. A third solution would be to just get the MCObjectStreamer case right and just emit simple nops in the asm file, but that would generate different binaries depending on which path you take through the pipeline.

What do you think?

Cheers,
Juergen
  
On Dec 3, 2013, at 7:24 PM, Rafael Espíndola <rafael.espindola at gmail.com> wrote:

> On 3 December 2013 19:49, Juergen Ributzka <juergen at apple.com> wrote:
>> The existing long nop support is only used to align code sections in the AsmBackend and directly emits the raw bytes into the object file.
>> This implementation is on a higher level that works for MCAsmStreamer and MCObjectStreamer.
> 
> That is still a duplication, and a non trivial one given that
> different CPUs have different nop preferences and the new code is
> quiet a bit harder to test.
> 
> There is a similar issues with the CFI directives where we want to be
> able to print assembly that works with older assemblers without
> duplicating the logic in CodeGen.
> 
> I think this duplication could be fixed by adding emitNops method to
> the Streamer interface. This code would just call that method. The
> alignment implementation in the Object streamer would figure out how
> many bytes it needs and call emitNops. That way all the logic about
> which nops to use for which cpu would be in emitNops.
> 
> Cheers,
> Rafael





More information about the llvm-commits mailing list