[PATCH] D124895: [Object] Fix updating darwin archives

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 3 18:51:37 PDT 2022


keith created this revision.
keith added reviewers: jyknight, compnerd.
Herald added subscribers: rupprecht, hiraditya.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jhenderson.
Herald added a project: All.
keith requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay, aheejin.
Herald added a project: LLVM.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124895

Files:
  llvm/lib/Object/Archive.cpp
  llvm/test/tools/llvm-ar/default-macho.test
  llvm/test/tools/llvm-objcopy/MachO/Inputs/unaligned_objects.yaml
  llvm/test/tools/llvm-objcopy/MachO/real-world-input-copy.test

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124895.426890.patch
Type: text/x-patch
Size: 17472 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220504/3b39611f/attachment.bin>


More information about the llvm-commits mailing list