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

    <tr>
        <th>Summary</th>
        <td>
            [LTO] Objects brought in by LTO-generated libcalls do not handle deplibs.
        </td>
    </tr>

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

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

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

<pre>
    We've been seeing failures when attempting to build ICU and FFmpeg on aarch64-...-fuchsia with LTO enabled:
```
ld.lld: error: undefined symbol: _zx_system_get_features
>>> referenced by cpu_model.c:818 (.../cpu_model.c:818)
>>>               cpu_model.c.obj:(init_have_lse_atomics) in archive .../clang/linux-x64/lib/clang/15.0.0/lib/aarch64-unknown-fuchsia/libclang_rt.builtins.a
clang++: error: ld.lld command failed with exit code 1 (use -v to see invocation)
```

We've traced this down to an LTO corner case. LTO code generation can introduce new undefined symbols by emitting external references to libcalls; this can, for example, happen if external atomics are used on aarch64. From the comments in the ELF LTO driver, it appears that it's not generally desirable to pull these in before the link (except if absolutely necessary, say, if they contain bitcode), since this may pull in unnecessary dependencies. Until LTO code generation is finished, the precise set of libcalls needed is unknown, and cannot be determined by examining the bitcode.

The LTO object file seems to be  parsed and added to the link largely if it were an input file; this may pull in other object files to satisfy these new libcall references. This seems to work fine, as far as it goes; the trouble is that the objects files pulled in are only partially processed. In particular, if they contain a `.deplibs` section pointing to another library, then that library is never fully added to the link, which can cause symbols in the object file (`_zx_system_get_features` above) to remain unresolved.

A candidate fix (https://reviews.llvm.org/D127885) is to add `parseFile()` calls to handle any newly-introduced files (such as those produced by .deplibs) as they would have been handled had they been present before LTO occurred.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx1Vctu4zgQ_Br5QliQ5diODz4kkzEwwABzyWCPBiW2LG4oUiApP_brt5pSHGczGxiRRIrd1VXV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