[PATCH] x86: Add .nop directive to assembler

H.J. Lu hjl.tools@gmail.com
Mon Feb 12 19:38:00 GMT 2018


On Mon, Feb 12, 2018 at 7:48 AM, Maciej W. Rozycki <macro@mips.com> wrote:
> On Mon, 12 Feb 2018, H.J. Lu wrote:
>
>> My implementation uses the existing relaxation frame work.
>> When we are processing .nop, we don't know exactly how big the
>> the NOP size will be.  We allocate a frag with the maximum size
>> and set the exact size after relaxation.  After relaxation is done,
>> all frags are converted to rs_fill.  We can add rs_fill_nop to
>> support arbitrary .nop directive size. But I don't know if it is
>> necessary.
>
>  Right, so this is needed for argument expressions using forward
> references.  Understood and accepted.  Thank your for patience.
>

Implement the '.nop SIZE[, LIMIT]' directive for x86 assembler.  This
directive emits SIZE bytes filled with 'NOP' instructions.  SIZE is
absolute expression, which must be between 0 and 512.  LIMIT specifies
the size limit of a single 'NOP' instruction.  If the comma and LIMIT
are omitted, LIMIT is assumed to the maximum supported size of a single
'NOP' instruction.  The valid values of LIMIT are between 1 and 8 for
16-bit mode, between 1 and 10 for 32-bit mode, between 1 and 11 for
64-bit mode.  This directive is only allowed in text sections.

This is implemented by adding a relax state, rs_space_nop, to enum
_relax_state, which is similar to rs_space, but it fills with NOPs,
instead of a single byte.  A pseudo relocation, BFD_RELOC_NOP_DIRECTIVE,
is added to fix up frag data with the proper number of NOPs.  The new
rs_space_nop state is processed only when TARGET_USE_NOP_DIRECTIVE is
defined.  To enable .nop directive, a target backend should

1. Define TARGET_USE_NOP_DIRECTIVE.
2. Create a rs_space_nop frag for .nop directive.
3. Update md_convert_frag to create a fixup with BFD_RELOC_NOP_DIRECTIVE
for rs_space_nop frag.
4. Update md_apply_fix to process fixup with BFD_RELOC_NOP_DIRECTIVE.

OK for master?

Andrew, please test my current users/hjl/nop branch.

Thanks.


-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-x86-Add-.nop-directive-to-assembler.patch
Type: text/x-patch
Size: 44205 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20180212/cbed1fb5/attachment.bin>


More information about the Binutils mailing list