[PATCH] D109572: [ELF] Add --why-extract to query why an archive member/lazy object file is extracted

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 00:38:03 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: jhenderson, ruiu, pcc, grimar, peter.smith.
Herald added subscribers: dang, arichardson, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Alternative to D69607 <https://reviews.llvm.org/D69607>. This patch adds --why-extract.

Prior art:

GNU ld -M prints

  Archive member included to satisfy reference by file (symbol)
  
  a.a(a.o)                      main.o (a)
  b.a(b.o)                      (b())

-M is mainly for input section/symbol assignment <-> output section mapping
(often huge output) and the information may appear ad-hoc.

Apple ld64

  __Z1bv forced load of b.a(b.o)
  _a forced load of a.a(a.o)

It doesn't say the reference file.

---

--why-extract does not take an argument because the user may want to analyze
more than one files. Just give the user the full data (which is much shorter
than GNU ld -M). It is easy to derive D69607 <https://reviews.llvm.org/D69607> like output an awk/ruby/perl
one-liner, e.g.

  % ld.lld main.o a_b.a b_c.a c.a -o /dev/null --why-extract | ruby -ane 'BEGIN{p={}}; p[$F[1]]=[$F[0],$F[2]] if $.>1; END{x="c.a(c.o)"; while y=p[x]; puts "#{y[0]} extracts #{x} to resolve #{y[1]}"; x=y[0] end}'
  b_c.a(b_c.o) extracts c.a(c.o) to resolve c()
  a_b.a(a_b.o) extracts b_c.a(b_c.o) to resolve b()
  main.o extracts a_b.a(a_b.o) to resolve a


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109572

Files:
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/Options.td
  lld/ELF/Symbols.cpp
  lld/test/ELF/why-extract.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109572.371803.patch
Type: text/x-patch
Size: 5684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210910/39c3bf23/attachment.bin>


More information about the llvm-commits mailing list