<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 12, 2017 at 7:57 PM, PkmX via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="auto"><div><div class="h5"><div>On Jul 13, 2017 02:07, "Rafael Avila de Espindola" <<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>> wrote:<br></div></div></div><div dir="auto"><div><div class="h5"><div class="gmail_extra" dir="auto"><div class="gmail_quote"><blockquote class="m_3017222637470267122gmail-m_6382405190375240122m_7497449639015439026m_-2192316273540329815quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="m_3017222637470267122gmail-m_6382405190375240122m_7497449639015439026m_-2192316273540329815quoted-text">PkmX via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> writes:<br>
> Note that RISC-V also handles alignment as part of relaxation, so it<br>
> isn't really optional. For example:<br>
><br>
> _start:<br>
>     mv      a0, a0<br>
>     .p2align 2<br>
>     li      a0, 0<br>
><br>
> The assembler inserts a 3-byte padding (note: this behavior isn't<br>
> merged yet, see: <a href="https://github.com/riscv/riscv-binutils-gdb/pull/88" rel="noreferrer" target="_blank">https://github.com/riscv/riscv<wbr>-binutils-gdb/pull/88</a>):<br>
<br>
</div>Why 3 bytes? The assembler knows the section alignment.<br>
<br>
I can see why another relaxation would require alignments to be<br>
revisited, but it should be possible to link without any relaxations,<br>
no?<br>
<br>
Cheers,<br>
Rafael<br>
</blockquote></div><br></div></div></div><div class="gmail_extra" dir="auto"><div>I agree the 3-byte padding is kinda strange. RISC-V insns are always multiples of 2 bytes and must be 2-byte aligned, so a 2-byte padding should suffice for the linker to re-align after relaxation. Indeed, the assembler should be able to configured to not emit any relaxation info and directly emit the correct number of nop's (w/o R_RISCV_ALIGN), and the object file can be linked without relaxation, but I don't think GAS can do that right now. (There is `.option norelax`, but currently it just emits zeros in the padding.)</div><div><br></div><div dir="auto">So the issue remains that GAS assumes linkers will always handle alignment (this is true for GNU ld even if --no-relax is given), so even for a basic RISC-V port lld needs to be extended to support relaxation.</div></div></div></div></div></blockquote><div><br></div><div>I really wish you or someone else make a change to gas so that the assembler doesn't emit code that depends on code shrinking relaxation.</div><div><br></div><div>Mandating code shrinking relaxation is I believe really bad from the perspective of linker portability and also from the link speed point of view.</div><div><br></div><div>If gas requires it even with --no-relax, it sounds like it is just a bug that needs fixing.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="auto"><div dir="auto"><div class="gmail_extra" dir="auto"><span class=""><div dir="auto">On Thu, Jul 13, 2017 at 6:07 AM, Bruce Hoult <<a href="mailto:bruce@hoult.org" target="_blank">bruce@hoult.org</a>> wrote:<br>> As a concrete suggestion, here is code for deciding how many bytes of<br>> padding to emit.<br>><br>> For the case of .align 2 (4 byte alignment), it will emit a minimum of 3 and<br>> a maximum of 6 bytes of padding. For .align 4 it emit a minimum of 15 and a<br>> maximum of 30 bytes of padding.<br></div><div dir="auto"><br></div></span><div>Why does .align 2 need 3 to 6 bytes of padding though? I think for `.p2align n` only 2^n - 2 (or 2^n - 4 without RVC) padding bytes would be needed.</div></div></div></div>
</div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>