[llvm-dev] [LLD] Linker Relaxation

Bruce Hoult via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 12 15:07:15 PDT 2017


As a concrete suggestion, here is code for deciding how many bytes of
padding to emit.

For the case of .align 2 (4 byte alignment), it will emit a minimum of 3
and a maximum of 6 bytes of padding. For .align 4 it emit a minimum of 15
and a maximum of 30 bytes of padding.

/*
  RISC-V align.

  Goals:
  1) align to the desired amount in the generated object file.
  2) provide enough extra padding that alignment can be maintained in the
face of
     code size changes, by only making the padding smaller, never bigger.
*/

void emit_padding(uintptr_t sz);

uintptr_t align(uintptr_t oldPos, int logAligment){
    uintptr_t alignment = 1 << logAligment, mask = alignment - 1;
    uintptr_t newPos = (oldPos + mask) & mask;
    if ((newPos - oldPos) < mask) newPos += alignment;
    emit_padding(newPos - oldPos);
    return newPos;
}


On Wed, Jul 12, 2017 at 9:07 PM, Rafael Avila de Espindola via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> PkmX via llvm-dev <llvm-dev at lists.llvm.org> writes:
> > Note that RISC-V also handles alignment as part of relaxation, so it
> > isn't really optional. For example:
> >
> > _start:
> >     mv      a0, a0
> >     .p2align 2
> >     li      a0, 0
> >
> > The assembler inserts a 3-byte padding (note: this behavior isn't
> > merged yet, see: https://github.com/riscv/riscv-binutils-gdb/pull/88):
>
> Why 3 bytes? The assembler knows the section alignment.
>
> I can see why another relaxation would require alignments to be
> revisited, but it should be possible to link without any relaxations,
> no?
>
> Cheers,
> Rafael
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170713/564042bf/attachment-0001.html>


More information about the llvm-dev mailing list