Currently, we pull in every single static archive member as long as we
have an offloading architecture that requires it. This goes against the
standard sematnics of static libraries that only pull in symbols that
define currently undefined symbols. In order to support this we roll
some custom symbol resolution logic to check if a static library is
needed. Because of offloading semantics, this requires an extra check
for externally visibile symbols. E.g. if a static member defines a
kernel we should import it.
The main benefit to this is that we can now link against the
libomptarget.devicertl.a library unconditionally. This removes the
requirement for users to specify LTO on the link command. This will also
allow us to stop using the amdgcn bitcode versions of the libraries.
clang foo.c -fopenmp --offload-arch=gfx1030 -foffload-lto -c clang foo.o -fopenmp --offload-arch=gfx1030 -foffload-lto
This could use some comments.
@MaskRay's blog post https://maskray.me/blog/2021-06-20-symbol-processing#archive-processing would be helpful to explain what's going on here.
I'd also refactor the condition a bit for readability: