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

    <tr>
        <th>Summary</th>
        <td>
            Assertion failure with link-time optimization and link command that duplicates static library
        </td>
    </tr>

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

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

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

<pre>
    Given the following two translation units:

a.c:
```c
```

b.c:
```c
int main() {}
```

And compiling with

```sh
clang -flto=thin -c a.c
clang -flto=thin -c b.c
llvm-ar qc c.a a.o
clang -fuse-ld=mold -flto=thin b.o -o /dev/null c.a c.a
```

Causes a crash with

```console
ld.mold: /home/david/llvm/llvm/tools/gold/gold-plugin.cpp:1069: std::vector<std::pair<SmallString<128>, bool>> runLTO(): Assertion `ObjFilename.second' failed.
clang: error: unable to execute command: Aborted (core dumped)
clang: error: linker command failed due to signal (use -v to see invocation)
```

I'm not sure if the bug is in llvm's gold-plugin code or mold calls that plugin incorrectly or if clang's compiler driver calls mold incorrectly.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VE2PozgQ_TXmUgIRQwIcOGQ6k9VKK81h9g8Yu4CaNTbrD3p7f_3KJNOdXk23FAVwuV75-dUr4T1NBrFnxy_seMlEDLN1vRIbKR-swWyw6qX_jTY0EGaE0Wptn8lMEJ4tBCeM1yKQNRANBc-qMysvrLz_i0K-rZzK20_-7_sxYfgkgUyARZBhvGW8A9Z8Yc3lE6yzUSDtspJOx32mMD9GX1P8fVlqYSbIRx0sqy5hJgO5hMTgk_DwM6z1tuTCwd8SZCFAFPZ9WvSYa8Wqy2K1eg8zFBZyC4xfFW6MX03UegeRhfiE3pOIHj0IkE74-WN-0hpvNd6PqYp0AFadU73ZLpjKJrUZvyYOb49grfaMX6e0__bIVx0nMoVcV1adD-WpS0A-JDxWnTeUwTpWPb2urILS9_dFaP09ODITq54OvGXVV8afYLBWp9fqK7ho_vjz203aBHr2Ht3eV-xUfht-XEmjEQsWHqU1ivEGRkEaVfFwzykRnUtnOEM0YtAIwQL-gzIGTM2wCLOTPw_WBVTAeCutQ1BxWVGl2h-gaTJ_ofsJca8NKu4FkoeETmDRI-TbvoYIZDYrd3e8Iv9Syt8ZbxYwNoCPDoHG3WpDnIA8kIGbIo2HBxFAWoVgHewNJYXWHsIsAtzDZKR1DmXQL2kXjXAjlWBurkAHytGWWO3ZO9BDWpGpvlJd1YkM-0PDq1NTnto2m_tmrMeqPR6Psh06HKuDPHGF7ZF3dS34Ycyo5yWvy_ZQ8wOv67aoVNe1TVfzQSp1UkdWl7gI0kWiVlg3ZeR9xP5Q1ryuMi0G1H4fSpwbfIY9yjhPM8r1u9mGOHlWl5p88G8wgYLG_q17klDpTpM9dhHzQAuCXQMt9O9tciVBU-hV3f0eVVw1SRHQgw8ikARNgxPuJYtO93MI6z7t-DWZg8Ich0La5b2N8tXZHygD49edQfLTneLW8_8CAAD___iJs2Q">