<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/87985>87985</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            There are defects in Alias handling by ORC JIT during the linking stage?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Thrrreeee
      </td>
    </tr>
</table>

<pre>
    Based on my findings, ORC JIT has defects in Alias handling that result in the generated ELF file. For each alias symbol, ORC JIT sets its size to be the same as the size of the original variable symbol it points to.
Therefore, an error occurs during the ELFLink stage when the [Offset + Sym.st_size > B->getSize() ](https://github.com/llvm/llvm-project/blob/fc9a5076c31139878da2fa12ef16090a58d55782/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h#L515)check is performed, leading to exceeding the block's size.The test file is [`llvm/test/Assembler/alias-use-list-order.ll`](https://github.com/llvm/llvm-project/blob/8b3b4a92adee40483c27f26c478a384cd69c6f05/llvm/test/Assembler/alias-use-list-order.ll#L1).I simply added a main function that directly returns 0. The source IR code is as follows:
``` 
RUN: verify-uselistorder < %s
; Globals.
@global = global i32 0
@alias.ref1 = global ptr getelementptr inbounds (i32, ptr @alias, i64 1)
@alias.ref2 = global ptr getelementptr inbounds (i32, ptr @alias, i64 1)

; Aliases.
@alias = alias i32, ptr @global
@alias.ref3 = alias i32, getelementptr inbounds (i32, ptr @alias, i64 1)
@alias.ref4 = alias i32, getelementptr inbounds (i32, ptr @alias, i64 1)

define dso_local noundef i32 @main() {
entry:
  ret i32 0
}
```

Error information as follows:

> JIT session error: In /home/sole/llvm/test/Assembler/alias-use-list-order.ll-jitted-objectbuffer, symbol alias.ref3 (0x4 -- 0x8) extends 0x4 bytes past the end of its containing block (0x0 -- 0x4)

In that case,"Offset" may refer to the offset address of the alias with respect to the variable it points to.Moreover, the calculation of the block's size does not take into account the alias symbols. So, as long as there's an offset, it will potentially exceed the size of that block.
It's unlikely to be due to errors in the LLVM IR, as I can statically compile it using clang directly. The command is `clang++ alias-use-list-order.ll -o alias-use-list-order`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk1v2zgQ_TX0ZWBDoj4sH3yIk7hwkW6BNLvXgiKHEhuKNEgqifvrF6Tk1Gm7C3S3QBBLIvk4M3x8b5j3qjOIW1LtSHWzYGPords-9M45RMRFa8Vpu2MeBVgDwwmkMkKZzhN6DR_vr-H94QF65kGgRB48KANXWjEPPTNCK9NB6FkAh37UIY6GHqFDg44FFHB7twepNK5gbx0g4z2wtNyfhtbqy108RvjgwauvCMFCiwnMswGB-ek5DlmZnq1TnTJMwxNzirUaZ0xQAY5WmeAh2BXJbkh29dCjQ2kdxg2ZAXTOOrCcj86DGN2UB8Zw75R5BB9Yh_Dc45QPqXYfpfQYgNAdfDoNKx8-p1hIcQu7JSluOwyf1FcktCF0A6S6IbTpQzh6UlwRuid036nQj-2K24HQvdZP55_l0dkvyAOh-1bbltC95BtWZeuaF3lebJp1IxiVLKco8zrbZKxqRFWtG3qBo-K62xfkY1DW3JpOGSR0__7wEPOJY1Nm7xw79rtRaYFu1RNa3FV5ReiG98gfQXk4opPWDShipTQykUpjAV84ojjXqdWWPxK6ng5r9dAjBPQhHXVEiXSrszm4OELo_sp7HFqNjtB94sBy9LjUyoeldTEcrUmd_b_KNW3RlmxDmUAss7IpOF1LWvNy3bCiKbmoN7yWWfUN5xeCo8VdTuhmdQCvhqM-ARMCBTAYmDIgR8Nj7af7IJRDHvQJHIbRGQ_ZCmKVvB0dRzjcA7cilYp5kFZr-5zyTWyNZUh_ML3f__kHKa7gCZ2SpxhYjCuFBaS4BkIrPy8sdvBO25ZpPxOflFmXPgApbmB-VAWF7HU8pbtyKPPLOcfgoMOAGgc0Ib4p09rRCA-ENqqgkR_x8xkhvqu6hFiiH7Hp78Z-zTepEV7kO-lL3G56eos3hfBjgMWPK35j-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