[all-commits] [llvm/llvm-project] 50d368: [LinkerWrapper] Relax ordering of static libraries...

Joseph Huber via All-commits all-commits at lists.llvm.org
Wed Apr 10 07:08:06 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 50d368aee981738cd05f3d16f5d1cfc122c9b0ab
      https://github.com/llvm/llvm-project/commit/50d368aee981738cd05f3d16f5d1cfc122c9b0ab
  Author: Joseph Huber <huberjn at outlook.com>
  Date:   2024-04-10 (Wed, 10 Apr 2024)

  Changed paths:
    M clang/test/Driver/linker-wrapper-libs.c
    M clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

  Log Message:
  -----------
  [LinkerWrapper] Relax ordering of static libraries for offloading (#87532)

Summary:
The linker wrapper attempts to maintain consistent semantics with
existing host invocations. Static libraries by default only extract if
there are non-weak symbols that remain undefined. However, we have
situations between linkers that put different meanings on ordering. The
ld.bfd linker requires static libraries to be defined after the symbols,
while `ld.lld` relaxes this rule. The linker wrapper went with the
former as it's the easier solution, however this has caused a lot of
issues as I've had to explain this rule to several people, it also make
it difficult to include things like `libc` in the OpenMP runtime because
it would sometimes be linked before or after.

This patch reworks the logic to more or less perform the following logic
for static libraries.

  1. Split library / object inputs.
  2. Include every object input and record its undefined symbols
  3. Repeatedly try to extract static libraries to resolve these
     symbols. If a file is extracted we need to check every library
     again to resolve any new undefined symbols.

This allows the following to work and will cause fewer issues when
replacing HIP, which does `--whole-archive` so it's very likely the old
logic will regress.
```console
$ clang -lfoo main.c -fopenmp --offload-arch=native
```



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list