[all-commits] [llvm/llvm-project] 066243: [Object] Fix updating darwin archives

Keith Smiley via All-commits all-commits at lists.llvm.org
Thu May 19 11:06:37 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 066243057fc2ae45ae6bbc2f4874ca1f84c3a3ff
      https://github.com/llvm/llvm-project/commit/066243057fc2ae45ae6bbc2f4874ca1f84c3a3ff
  Author: Keith Smiley <keithbsmiley at gmail.com>
  Date:   2022-05-19 (Thu, 19 May 2022)

  Changed paths:
    M llvm/include/llvm/Object/Archive.h
    M llvm/include/llvm/Object/ArchiveWriter.h
    M llvm/lib/ObjCopy/Archive.cpp
    M llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp
    M llvm/lib/Object/Archive.cpp
    M llvm/lib/Object/ArchiveWriter.cpp
    A llvm/test/tools/llvm-ar/macho-edit.test
    A llvm/test/tools/llvm-objcopy/MachO/archive-format.test
    M llvm/test/tools/llvm-objcopy/MachO/universal-object.test
    M llvm/tools/llvm-ar/llvm-ar.cpp

  Log Message:
  -----------
  [Object] Fix updating darwin archives

When creating an archive, llvm-ar looks at the host to determine the
archive format to use, on Apple platforms this means it uses the
K_DARWIN format. K_DARWIN is _virtually_ equivalent to K_BSD, expect for
some very slight differences around padding, timestamps in deterministic
mode, and 64 bit formats. When updating an archive using llvm-ar, or
llvm-objcopy, Archive would try to determine the kind, but it was not
possible to get K_DARWIN in the initialization of the archive, because
they're virtually inciting usable from K_BSD, especially since the
slight differences only apply in very specific cases. This leads to
linker failures when the alignment workaround is not applied to an
archive copied with llvm-objcopy. This change teaches Archive to infer
the K_DARWIN type in the cases where it's possible and the first object
in the archive is a macho object. This avoids using the host triple to
determine this to not affect cross compiling.

Ideally we would eliminate the separate K_DARWIN type entirely since
it's not a truly separate archive type, but then we'd have to force the
macho workarounds on the BSD format generally. This might be acceptable
but then it would be unclear how to handle this case without forcing the
K_DARWIN64 format on all BSD users:

```
if (LastOffset >= Sym64Threshold) {
  if (Kind == object::Archive::K_DARWIN)
    Kind = object::Archive::K_DARWIN64;
  else
    Kind = object::Archive::K_GNU64;
}
```

The logic used to determine if the object is macho is derived from the
logic llvm-ar uses.

Previous context:

- 111cd669e90e5b2132187d36f8b141b11a671a8b
- 23a76be5adcaa768ba538f8a4514a7afccf61988

Differential Revision: https://reviews.llvm.org/D124895




More information about the All-commits mailing list