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

    <tr>
        <th>Summary</th>
        <td>
            change wasm_apply_data_relocs to use loop for constant relocations
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          Maksim-Bozhko
      </td>
    </tr>
</table>

<pre>
    wasm_apply_data_relocs scales poorly with number of relocations and often hits function size limit, so I am trying to fix it, but I don't understand LLD code well enough yet. Function has many parts like this, which only differ in constants, which are known when it is generated
```
i32.const 3652
global.get $__memory_base
i32.add
global.get $__memory_base
i32.const 4308
i32.add
i32.store
```
The idea is to create 2 arrays: one for offsets used in store, another for values store writes at offset. So i understand how to generate a loop and how to go over 2 arrays, read values from them, pass constants to i32.store, but I din't figure out yet how to put relocation offsets in static data segment, so if anyone more familiar with LLD could help, I would appreciate it. This change would make it so wasm_apply_data_relocs doesn't grow with number of relocations like this at a cost of adding 2 synthetic arrays of integers, where size equals relocation count. We can't apply loop approach to cases like `global.get $GOT.data...`, but for our port most of the relocations in MAIN_MODULE use constants and not `$GOT`

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVE2PpDYQ_TVwKS2ioemPA4fZTCYaaSZ7yEQ5tgpcgNPGJrYZwv76lKF7uleaRIqEBHbZVe-9ekVlxFxO6PoTDoOaTwI9niwpUztwNSpyMBhj1QyT9B3osa_IgmlgOYNeGu0AteAtTxo66R00o65DAJz8TqBkL32U_QTOwDNgD97OUrfgDTTyb1hj1eg5KIyOsr2HUQuyzoe0Ly-PUBtBMJFSQNqMbQcz-QSerlU6dNCjnmFAy9WVPBP4TrqQd-pk3YHRjF_IpmHoUnM-HZL7uxNoCc7aTJrXTEN6kA5a0mTRk4jSxyh9iHbp5VmWMs-SJRPkuyJb91plKlRJSx6ibH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