[clang] [LinkerWrapper] Relax ordering of static libraries for offloading (PR #87532)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 9 10:16:17 PDT 2024


jhuber6 wrote:

> if a.o depends on b.o in libb.a, and b.o depends on c.o in libb.a, will the linker wrapper be able to link all the dependencies?

Given an invocation like this with those dependencies
```console
$ clang main.o libb.a liba.a
```
main.o will extract `a.o` from `liba.a`. We will then re-scan all the libraries so `a.o` will extract `b.o` from `libb.a`. This will then re-scan all the libraries and find nothing left to extract so we are done.

> For archive of objects with embedded device bitcode, why not creating an archive of device bitcode for each required target ID and let lld handle the dependencies in its usual way?

I tried doing that at a very early stage, two reasons.
1. This needs to work for CUDA / x86_64 linking so we can't rely on LLD specific handling
2. Offloading requires special handling for kernels and globals since we *always* want to extract callable kernels. This is a little hacky.

For 2. I'm thinking of embedding callable kernels into the host symbol table somehow. That way we can make the offloading extraction rules work more like "If this kernel is externally visible and used by the host it should be extracted".

https://github.com/llvm/llvm-project/pull/87532


More information about the cfe-commits mailing list