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

    <tr>
        <th>Summary</th>
        <td>
            Compile HIP code directly to HIP object file with embedded device images
        </td>
    </tr>

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

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

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

<pre>
    During HIP compilation (in particular, I think it belongs to the offloading step), there's an intermediate compilation artifact which is a native arch object file that has all the devices images embedded within it. The code for doing this is `constructGenerateObjFileFromHIPFatBinary` in [`HIPUtility.cpp`](https://github.com/llvm/llvm-project/blob/119a72866f0e143127355fe6e03f57c4f8bab1ae/clang/lib/Driver/ToolChains/HIPUtility.cpp#L104)

Is there a way to compile code to this intermediate artifact? It is okay if multiple steps are needed, but the goal is to **end** at this stage and don't compile further. I was implementing separable HIP compilation for CMake and couldn't find a way to compile my code to this intermediate object file containing all the GPU code, so that the final linker step can be completed by any linker. The process would look something like this:
1. Compile code into an object file targeting host only through `--offload-host-only`: `clang --offload-host-only -o file.host.o -x hip -c file.cpp`
2. Then, somehow compile code into this intermediate object file with GPU code embedded in it, ideally separately for each `--offload-arch`: for every `--offload-arch=$arch`, `clang ??? -o file.$arch.o -x hip -c file.cpp`
3. Link all object files together. Since all objects are are targeting the host arch, any host linker should be able to perform this step and doesn't have to be `lld`: `ld.mold -o file file.gfx1030.o file.gfx900.o file.host.o -lamdhip64 -lstdc++`

Is there currently a functionality or flag combination that can achieve (2)?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVUtv27wS_TX0ZmBDpmzZXniRJlBq4Lu4AW676W5EjiQ2FCmQlF3_-4uh7CR9oMAHKA-Ro3mdc2YwRtM5oqPYfhLbpwVOqffh-PztGc_GfevRLxqvr8enKRjXwefTCyg_jMZiMt6BkHvjYMSQjJos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