[llvm-dev] [LLD] Linker Relaxation
Rafael Avila de Espindola via llvm-dev
llvm-dev at lists.llvm.org
Thu Jul 13 17:22:35 PDT 2017
Bruce Hoult <bruce at hoult.org> writes:
> 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;
> }
Where is this code btw? I don't see it in the binutils repo or the pull
request you pointed to.
Cheers,
Rafael
More information about the llvm-dev
mailing list