[PATCH] D97426: [lld-macho] Infer machine type from input files

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 16:51:43 PST 2021


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added subscribers: steven_wu, hiraditya.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I initially tried to do this by mirroring LLD-ELF's architecture of having
InputFile construction separated from parsing of the file contents. However, I
think that model is a bit more of an awkward fit for Mach-O with its .tbd files

- since one TBD file can generate multiple corresponding InputFiles, there

isn't a 1:1 mapping between unparsed buffers and InputFile objects. Moreover, I
found having files in an unparsed state & having to remember to parse them
before use was confusing in general.

As such, I've decided to have us infer the machine type by scanning the input
object files without constructing them. While this does mean that we read in one
extra page per file in the worst case, I think there should be almost no
overhead in practice, since 1. we'll usually succeed in inferring the type from
the first file we examine, 2. we're only reading in one page, and 3. this entire
logic can be bypassed by specifying `-arch` on the command line.

Note that we only look at object files (and not bitcode) when doing this
inference. This matches ld64's behavior, though I suppose it would be nice to
support inference from bitcode in the future.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97426

Files:
  lld/MachO/Driver.cpp
  lld/MachO/Target.cpp
  lld/MachO/Target.h
  lld/test/MachO/arch.s
  lld/test/MachO/arm64-reloc-got-load.s
  lld/test/MachO/arm64-reloc-pointer-to-got.s
  lld/test/MachO/arm64-relocs.s
  lld/test/MachO/codemodel.ll
  lld/test/MachO/cpu-string.ll
  lld/test/MachO/fat-arch.s
  lld/test/MachO/header.s
  lld/test/MachO/invalid/invalid-executable.s
  lld/test/MachO/invalid/invalid-fat-offset.s
  lld/test/MachO/invalid/invalid-relocation-pcrel.yaml
  lld/test/MachO/lc-linker-option.ll
  lld/test/MachO/linkonce.ll
  lld/test/MachO/lto-object-path.ll
  lld/test/MachO/lto-save-temps.ll
  lld/test/MachO/mattrs.ll
  lld/test/MachO/module-asm.ll
  lld/test/MachO/objc-arc-contract.ll
  lld/test/MachO/reloc-subtractor.s
  lld/test/MachO/reproduce-thin-archives.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97426.326243.patch
Type: text/x-patch
Size: 22077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210225/cefd5a40/attachment.bin>


More information about the llvm-commits mailing list