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

    <tr>
        <th>Summary</th>
        <td>
            Inconsistentent / rationale for symbol registeration in GenericLLVMIRPlatformSupport
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            orcjit
      </td>
    </tr>

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

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

<pre>
    Hi all, can somebody help me understand the differences between the three places in `GenericLLVMIRPlatformSupport` to define symbols:
1. The constructor defines via `StdInterposes`: `__lljit.platform_support_instance` and `__lljit.cxa_atexit_helper`.
2. `setupJITDylib` defines via `PerJDInterposes`: `__lljit.run_atexits_helper` and `__lljit.atexit_helper`. It constructs a `__standard_lib` module with `__dso_handle`, `__lljit_run_atexits`, and `atexit`.
3. `createPlatformRuntimeModule` constructs another `__standard_lib` with `__cxa_atexit`.

Now, as far as I understand, `setupJITDylib` is called for every added `JITDylib`. On the other hand, the constructor and `createPlatformRuntimeModule` only define symbols in the main `JITDylib`, which means they cannot be used for symbols that need to change per `JITDylib`. However, why do we need `PerJDInterposes` - these symbols come from the host process and their addresses should always be the same, no?

I understand that `__dso_handle` needs to be defined per `JITDylib`. However, why do we need to construct a module, could it also be defined via `absoluteSymbols`?

Finally, we generate `__cxa_atexit` only once, but `atexit` (and `__lljit_run_atexits`) once per `JITDylib`. I understand that it needs to *reference* `__dso_handle`, but the actual symbols should always be the same, shouldn't they?

(Related thought, but maybe off-topic: Why do we need `__lljit_run_atexits` at all? We are in the `GenericLLVMIRPlatformSupport` and know the `JITDylib`, so we could just run `runAtExits` ourselves...)

I feel like I'm missing some bigger picture here...
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU2P2zYQ_TX0ZbCCTPnz4IObrRsHSRvsBs3RoKSRxQ1FCpzhOv73BSW5_lh32wKLNSA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