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

    <tr>
        <th>Summary</th>
        <td>
            Supporting Windows SEH without the ORC runtime
        </td>
    </tr>

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

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

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

<pre>
    It'd be nice to get Windows SEH working without requiring the ORC runtime.

This would bring Windows into line with Darwin and Linux, both of which support exceptions in-process without the runtime.

`RtlAddFunctionTable` (https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtladdfunctiontable) and `RtlDeleteFunctionTable` seem to be the registration APIs.

`RtlAddFunctionTable` takes a base address and a pointer to a table where function addresses are expressed as 32-bit offsets from the base:
``
NTSYSAPI BOOLEAN RtlAddFunctionTable(
  [in] PRUNTIME_FUNCTION FunctionTable,
  [in] DWORD             EntryCount,
  [in] DWORD64 BaseAddress
);
```

I do not know whether the SEH runtime looks at any metadata at the base address, or whether it's used purely for address calculations, but I suspect the latter (or the various out-of-tree SEH experiments that people have gotten working would have blown up differently).

Assuming that `BaseAddress` is only used for address calculation then we can probably just find the lowest address in the graph and use that for each grab.

If `BaseAddress` needs to contain useful metadata (e.g. a COFF header) then we can do something similar to what we do for compact-unwind (see https://github.com/llvm/llvm-project/blob/d83fe1201e9d91da192d9292fea1a65579086e04/llvm/lib/ExecutionEngine/JITLink/CompactUnwindSupport.h#L634)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUlc1u4zYQx5-GvgxsyJRkWwcfHCdCXaTJIsli0VNBiSOLG4pUyWEUv31ByU687RZFDQOWTHL4m_98Ce_V0SBuWX7D8tuZCNRat9Wt6NDPKitP2wMxvpZQIRhVI5CFIxJ8U0bawcPz3S8wWPeqzBEGRa0NBA7_DMrFf6hFeHzagwuGVIc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