[PATCH] D119074: [ELF] Parse archives as --start-lib object files

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 6 02:02:41 PST 2022


MaskRay created this revision.
MaskRay added reviewers: bd1976llvm, ikudrin, peter.smith.
Herald added subscribers: ormris, arphaman, steven_wu, hiraditya, arichardson, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

https://maskray.me/blog/2022-01-16-archives-and-start-lib

For every definition in an extracted archive member, we intern the symbol twice,
once for the archive index, once for the .o symbol table after extraction. This
is inefficient.

Symbols in a --start-lib ObjFile/BitcodeFile are only interned once
because the result is cached in symbols[i].

Just parse an archive as a group of --start-lib object files. We can therefore
remove ArchiveFile. Linking a Release build of clang is 1.01x as fast.

Note: archive index entries created by llvm-ar are in exact the same order of
ld.lld visiting archive members as lazy ObjFiles, so the symbol resolution is
identical. In a contrived case where an archive has an incomplete index, the
symbol resolution can be different. I consider such cases user errors.
Therefore, I rejected the idea to add an option to get the archive symbol
resolution behavior.

- In some tests, the diagnostics get improved: `b.a:` => `b.a(b.o):`.
- no-obj.s: the link is now allowed, matching GNU ld

This patch allows us to remove ArchiveFile and LazyArchive.

---

Technically archive index can avoid some disk seeks if a member is not
extracted. However, for many projects, archive member extraction ratio is high.
The disk seek argument is very weak.

I recently decreased sizeof(SymbolUnion) by 8 and decreased memory usage quite a
bit, so `symbols` for un-extracted archive members should not cause a memory
usage problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119074

Files:
  lld/ELF/Driver.cpp
  lld/ELF/Driver.h
  lld/ELF/InputFiles.cpp
  lld/ELF/InputFiles.h
  lld/ELF/MapFile.cpp
  lld/ELF/Symbols.cpp
  lld/ELF/Symbols.h
  lld/test/ELF/archive-as-start-lib.s
  lld/test/ELF/archive-no-index.s
  lld/test/ELF/archive-thin-missing-member.s
  lld/test/ELF/incompatible-ar-first.s
  lld/test/ELF/incompatible.s
  lld/test/ELF/lto/comdat-mixed-archive.test
  lld/test/ELF/lto/exclude-libs-libcall.ll
  lld/test/ELF/no-obj.s
  lld/test/ELF/trace-symbols.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119074.406239.patch
Type: text/x-patch
Size: 23728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220206/9a0fed2e/attachment.bin>


More information about the llvm-commits mailing list