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

    <tr>
        <th>Summary</th>
        <td>
            Tip of tree ld64.lld report "No available targets" when using `-object_path_lto`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld:MachO
      </td>
    </tr>

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

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

<pre>
    We recently rolled llvm toolchain and noticed a linker error on the Mac builder:
```
[3356/6995] LINK ./geometry_benchmarks
[3357/6995] SOLINK libtessellator.dylib libtessellator.dylib.TOC
FAILED: libtessellator.dylib libtessellator.dylib.TOC 
if [ ! -e ./libtessellator.dylib -o ! -e ./libtessellator.dylib.TOC ] || otool -l ./libtessellator.dylib | grep -q LC_REEXPORT_DYLIB ; then ../../buildtools/mac-x64/clang/bin/clang++ -shared -isysroot /Volumes/Work/s/w/ir/cache/osx_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -mmacosx-version-min=10.14.0  -Wl,-object_path_lto,./lto_libtessellator.o -arch x86_64 -nostdlib++ -Wl,-search_paths_first -L. -Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/../../.. -o ./libtessellator.dylib -Wl,-filelist,./libtessellator.dylib.rsp   -framework Foundation && { otool -l ./libtessellator.dylib | grep LC_ID_DYLIB -A 5; nm -gP ./libtessellator.dylib | cut -f1-2 -d' ' | grep -v U$$; true; } > ./libtessellator.dylib.TOC; else ../../buildtools/mac-x64/clang/bin/clang++ -shared -isysroot /Volumes/Work/s/w/ir/cache/osx_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -mmacosx-version-min=10.14.0  -Wl,-object_path_lto,./lto_libtessellator.o -arch x86_64 -nostdlib++ -Wl,-search_paths_first -L. -Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/../../.. -o ./libtessellator.dylib -Wl,-filelist,./libtessellator.dylib.rsp   -framework Foundation && { otool -l ./libtessellator.dylib | grep LC_ID_DYLIB -A 5; nm -gP ./libtessellator.dylib | cut -f1-2 -d' ' | grep -v U$$; true; } > ./libtessellator.dylib.tmp && if ! cmp -s ./libtessellator.dylib.tmp ./libtessellator.dylib.TOC; then mv ./libtessellator.dylib.tmp ./libtessellator.dylib.TOC ; fi; fi
ld64.lld: error: No available targets are compatible with triple ""
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```
We did a bisecting and we believe this error starts to manifest after patch aa0883b59ae17e5465906dad51b5561b5292a28d .

Upon inspection, the patch itself doesn't seem to introduce the bug, instead it enabled a few features by default and likely one of them doesn't have the target triple properly propagated, therefore we are seeing failures like this.

The error can be reproduced on a Mac x64 machine with following steps:

* Create a source file `foo.c` containing `int foo() { return 123; }`
* Run `clang++ -c -o foo.o foo.c` 
* Run `clang++ -shared -nostdlib -Wl,-object_path_lto,foo.o -o foo.dylib foo.o`

With aa0883b59ae17e5465906dad51b5561b5292a28d, it will output: `ld64.lld: error: No available targets are compatible with triple ""`. Without aa0883b59ae17e5465906dad51b5561b5292a28d, the clang++ will return 0.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV1FzozgS_jXySxcUCIPtBz_E9rgqtZnN1Ez2MvfkEqIxugiJk4Qd36-_asCXzF4mu3N1T1tThWUQ6k_drU_qD-G9OhrENcs3LN_NRB8a69b_Qmdti0cxK211WT8iOJRogr6As1pjBVqfWgjWatkIZUCYCowNSmIFArQyT-gAnbMOrIHQIHwUEspe6Qody25YsmPJDSuS6Rof802W5QXj-2K1ylm-g7vbX3-BmPH9EW2LwV0OJRrZtMI9-dc2i1c2X-4HK63KgN6j1iJYF1cXrco3O-OH--2Itb-5vfuwY9nNjxnDaK1qYPkGGE8hwsHpN1Ei-0dDRsx8B2yxZYstWEozRPr7mDTq6LCD6J9wtz18_vD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