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

    <tr>
        <th>Summary</th>
        <td>
            LLD fails due to incorrect file path when emitting thinLTO index files for bitcode object fails that are lazily loaded
        </td>
    </tr>

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

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

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

<pre>
    Currently when lld is called with the `--thinlto-emit-index-files` option and one of the bitcode object files contains symbols that never end up getting linked into the final output (and thus the InputFile's `lazy` attribute stays set to `false`), the linker fails when emitting empty index files for the lazy input files in `thinLTOCreateEmptyIndexFiles`. I've only seen this issue occurring when linking against thin archives that contain references to files in a separate folder. Minimal reproducible example:
`a.h`:
```c++
int a();
```
`a.cpp`:
```c++
#include "a.h"

int a()
{
  return 1;
}
```
`b.h`:
```c++
int b();
```
`b.cpp`:
```c++
#include "b.h"

int b()
{
  return 2;
}
```
`main.cpp`:
```c++
#include <iostream>

#include "a.h"

int main()
{
  std::cout << a() << "\n";
}
```
compilation commands:
```bash
mkdir other-folder
clang++ -flto=thin a.cpp -c -o ./other-folder/a.o
clang++ -flto=thin b.cpp -c -o ./other-folder/b.o
clang++ -flto=thin main.cpp -c -o main.o
mkdir other-folder-2
llvm-ar -crT ./other-folder-2/library.a other-folder/a.o other-folder/b.o
clang++ -fuse-ld=lld -Wl,--thinlto-emit-index-files -flto=thin main.o ./other-folder-2/library.a -o main
```

It seems like `thinLTOCreateEmptyIndexFiles()` is not prepending the path to the archive to the bitcode file it's trying to emit, but more investigation is necessary. Everything works perfectly when the symbols are actually used, but when they aren't things begin to fail.

Assigning to myself as I'm planning on working on it if I end up having time, but leaving steps to reproduce here in case anyone else decides to pick this up.

@mtrofin 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVl1vq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