[lld-macho] Refactor archive loading
authorJez Ng <jezng@fb.com>
Thu, 26 Aug 2021 15:49:47 +0000 (11:49 -0400)
committerJez Ng <jezng@fb.com>
Thu, 26 Aug 2021 22:52:07 +0000 (18:52 -0400)
commit9065fe55911923c158e0d0e739081996d4ff86f2
treeb8e42931116723b316f8f7496f90b7fe3b19c709
parent2179930868f6166deccbf21f2f7565ec7666ff70
[lld-macho] Refactor archive loading

The previous logic was duplicated between symbol-initiated
archive loads versus flag-initiated loads (i.e. `-force_load` and
`-ObjC`). This resulted in code duplication as well as redundant work --
we would create Archive instances twice whenever we had one of those
flags; once in `getArchiveMembers` and again when we constructed the
ArchiveFile.

This was motivated by an upcoming diff where we load archive members
containing ObjC-related symbols before loading those containing
ObjC-related sections, as well as before performing symbol resolution.
Without this refactor, it would be difficult to do that while avoiding
loading the same archive member twice.

Differential Revision: https://reviews.llvm.org/D108780
lld/MachO/Driver.cpp
lld/MachO/Driver.h
lld/MachO/DriverUtils.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
lld/MachO/ObjC.cpp
lld/test/MachO/invalid/bad-archive-member.s
lld/test/MachO/thin-archive.s