Friday, September 13, 2024 Martin Storsjö <mar...@martin.st> wrote: >> When the offset is >= 1MB: >> >> adrp x0, symbol + offset % (1 << 20) // it prevents relocation overflow in >> IMAGE_REL_ARM64_PAGEBASE_REL21 >> add x0, x0, (offset & ~0xfffff) >> 12, lsl #12 // a workaround to support >> 4GB offset >> add x0, x0, :lo12:symbol + offset % (1 << 20) > > Ah, I see. Yeah, that works. > > That won't get you up to a full 4 GB offset from your symbol though, I > think that'll get you up to 16 MB offsets. In the "add x0, x0, #imm, lsl > #12" case, the immediate is a 12 bit immediate, shifted left by 12, so you > effectively have 24 bit range there. But clearly this works a bit further > than 1 MB at least.
Sorry for the delay in replying. Thanks for noticing this! It looks like a 16MB offset is enough to cover our CI needs. However, it would be good to also support a 4GB offset. If the offset is >= 16MB, it will require one more instruction to cover this case. A separate patch series will be introduced later to roll these helper instructions for COFF in the linker into one adrp call. Regards, Evgeny