[LinkerWrapper] Only import static libraries with needed symbols
authorJoseph Huber <jhuber6@vols.utk.edu>
Tue, 24 Jan 2023 17:04:47 +0000 (11:04 -0600)
committerJoseph Huber <jhuber6@vols.utk.edu>
Tue, 24 Jan 2023 23:01:33 +0000 (17:01 -0600)
commit1964c334782e7c5961772fbdcdcc0029cba3a7fa
tree1202ed1a352fb4616025472b76e386efca469d14
parent4b88bf5c70c351c9b6758da7026b5673c0dcc8d9
[LinkerWrapper] Only import static libraries with needed symbols

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
```

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D142484
clang/test/Driver/linker-wrapper-libs.c [new file with mode: 0644]
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp