Darwin/ARM64: Linker corrupts generated code #39820
Comments
For posterity, the linker in question here is |
Actually, the linker is fine here. The issue is the intervening assignment to |
Looks like the fix in https://reviews.llvm.org/D80834 needs to be extended to the adrp/add/ldr case also. |
Do you have an IR reproducer? I tried to re-construct the issue by using this MIR:
but linking this I get a binary that has the last load becoming a literal load, which seems correct:
|
Can you try making the address of |
@aemerson Here's a full end-to-end example for you: https://gist.github.com/Keno/97c670bb659866ed1925081624fa1fb6. The .s is generated from the .ll in the gist using the command at the top (this is on LLVM11, but the issue reproduced on trunk also, though I didn't check this particular test case). You can see the problematic sequence here: https://gist.github.com/Keno/97c670bb659866ed1925081624fa1fb6#file-extract-loh-s-L476-L488 |
(Note this is only extracting the one function. If that turns out to not be big enough to reproduce this fully, I can send you the whole .bc file. It's about 100MB though. |
Ok, adding some very large padding in the assembly seems to have reproduced it. I now see:
|
Yep, that's the issue. The |
LLVM emits the following:
LOH is what's called
Linker-optimization-hint
which is an aarch64-specific thing where the linker patches out some instructions (an explanation of how that works is here: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AArch64/AArch64CollectLOH.cpp). However, after linking the instruction sequence is:looks to me like what happened here is that the relocation offset overflowed the size of the available immediate operand of the subsequent load, causing it to overflow into the source register field, causing crashes.The text was updated successfully, but these errors were encountered: