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

    <tr>
        <th>Summary</th>
        <td>
            How to use distributed thin lto?
        </td>
    </tr>

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

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

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

<pre>
    I got a **3%** optimization effect by using `thinlto`, which I think is great. But it will increase my link time from **10 seconds to 20 minutes** when using lld, so **I hope to find some means to speed up thinlto.** At present, I learned from the official website [documents](https://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html) that you can use `--thinlto-index-only` to generate indexes and optimize each bitcode (.o) separately, and **use distributed construction to speed up the process.**
The problem I’m having is that by following the command below, I’m linking only the .o and everything works fine. **There are some usage issues when linking with .a**

**compiler and generate index**
```shell
clang++ lib.cc -flto=thin -O3 -c -o lib.o
clang++ main.cc -flto=thin -O3 -c -o main.o
clang++ main.o lib.o -fuse-ld=lld -o main -Wl,--thinlto-index-only=main.rsp,--thinlto-emit-imports-files

clang++ -O3 -o lib.thinlto.o -x ir lib.o -c -fthinlto-index=lib.o.thinlto.bc
clang++ -O3 -o main.thinlto.o -x ir main.o -c -fthinlto-index=main.o.thinlto.bc
clang++ lib.thinlto.o main.thinlto.o -o -fuse-ld=lld -o main
```
But when I package `lib.o` into `lib.a`, the generated files are a little different.
```
clang++ main.o lib.a -fuse-ld=lld -o main -Wl,--thinlto-index-only=main.rsp,--thinlto-emit-imports-files
```
This generates `lib.a(lib.o at 94).imports` and `lib.a(lib.o at 94).thinlto.bc`.
I understand this may be the offset of lib.o in lib.a, and I want to run.
```
clang++ -O3 -o lib.thinlto.o -x ir lib.o -c -fthinlto-index="lib.a( lib.o at 94).thinlto.bc"
```
get `Error loading imported file lib.a(lib.o at 94)`.
I tried renaming lib.o to "lib.a(lib.o at 94)" and it worked
```
mv lib.o "lib.a(lib.o at 94)"
clang++ -O3 -o lib.thinlto.o -x ir "lib.a(lib.o at 94)" -c -fthinlto -index="lib.a(lib.o at 94).thinlto.bc"
```
This seems to work fine, but integrating it into a distributed build system seems unlikely.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vk9v47gP_TTKhbDhyHEmPuTQTib45fS7DLBn2aJtbfXHkOhmMp9-IdmZJt20i9nDAoXbSuLj4yNFSoSgeou4Z9Uzqw4rMdHg_P5n2w2rxsnL_gS9IxDA-BPjTyXj1fwXuJGUUT8FKWcBuw5bguYCU1C2B7YtaFBWk2PbgvGvcB5UO8AJ4uoLqAC9R0E5PE8EiuCstAZlW48iIJgL6HiMlEHovDOL93UBAVtnZQBywAswyk6EYWF0HtAu_rWW0Wtwi-UJBjditOqUlRCcQTAobAIKI6KEaYSFcr7gPRGMHgNailgn0Ci8RTkzogHBdZ1qldBwxiYoQmDVs3TtZNBSYNWB8d1ANAZWPjF-ZPzYaNfnWr-a3Pme8SMv1lvGj0X8LM6z0AotGo2ZsDJLkkQ4obPIbCCjGa-BBkFwcRO0IoaMUfAsu0IoK_FH5qy-sG0RI-zRoheEkHYwgLDymkAEFO0AjaLWSQTGd7mLLgKOItroS4w-GsyyRG9SBfKqmQgltM4G8lOb6uBeTYTRuxZDWBRlxYEVT9_n9UajgRP7xtmuYHVtYBCvMXUqzNE1F-ic1u4cFyNW64yJNBrU7pwycmMc6yUejEGn07lLnPEV_SXq0sPZ-ZcQ84_5Esr3AT2C8DgXxBREj6BCmDDMxXRFPSsaIBe3USzftNI6MyqNPnm81_rOZFvMP2FAree1VgvbM_7M-DNo1eRtC1kXr015iKwh-38JWQuZS7vu70ZGKPuJVdr-yGwBhaybAmZasvKgtbyaQfaHZvzrw7IqDwnAh_HuBBpFmTKj8xSyTmkMt2Ld-k8MZ__XW-cg-wHKXznFkO48R3Zx65dB036Im9i9B15ifog8730Kfc_1vYePVHyX-vnf2PVSgZ1g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