llvm-project/lld/docs
Fangrui Song a954bb18b1 [ELF] Add --why-extract= to query why archive members/lazy object files are extracted
Similar to D69607 but for archive member extraction unrelated to GC. 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.

Arm's proprietary linker
```
Selecting member vsnprintf.o(c_wfu.l) to define vsnprintf.
...
Loading member vsnprintf.o from c_wfu.l.
              definition:  vsnprintf
              reference :  _printf_a
```

---

--why-extract= gives the user the full data (which is much shorter than GNU ld
-Map). It is easy to track a chain of references to one archive member with a
one-liner, e.g.

```
% ld.lld main.o a_b.a b_c.a c.a -o /dev/null --why-extract=- | tee stdout
reference       extracted       symbol
main.o  a_b.a(a_b.o)    a
a_b.a(a_b.o)    b_c.a(b_c.o)    b()
b_c.a(b_c.o)    c.a(c.o)        c()

% 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}' stdout
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
```

Archive member extraction happens before --gc-sections, so this may not be a live path
under --gc-sections, but I think it is a good approximation in practice.

* Specifying a file avoids output interleaving with --verbose.
* Required `=` prevents accidental overwrite of an input if the user forgets `=`. (Most of compiler drivers' long options accept `=` but not ` `)

Differential Revision: https://reviews.llvm.org/D109572
2021-09-20 09:52:30 -07:00
..
ELF [ELF] Add OVERWRITE_SECTIONS command 2021-06-13 12:41:11 -07:00
_static
_templates
llvm-theme
AtomLLD.rst Doc: Links should use https 2020-03-22 22:49:33 +01:00
CMakeLists.txt
Driver.rst
NewLLD.rst Doc: Links should use https 2020-03-22 22:49:33 +01:00
Partitions.rst
README.txt
Readers.rst
ReleaseNotes.rst [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
WebAssembly.rst [lld][WebAssembly] Add new `--import-undefined` option 2021-06-17 11:44:21 -07:00
conf.py Bump the trunk major version to 14 2021-07-27 21:58:25 -07:00
design.rst Doc: Links should use https 2020-03-22 22:49:33 +01:00
development.rst Doc: Links should use https 2020-03-22 22:49:33 +01:00
error_handling_script.rst [lld] Provide a hook to customize undefined symbols error handling 2020-11-09 13:28:48 +01:00
getting_started.rst doc: use the right url to bugzilla 2020-03-22 22:49:40 +01:00
hello.png
index.rst Provide a hook to customize missing library error handling 2020-11-03 11:01:29 +01:00
ld.lld.1 [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
make.bat
missingkeyfunction.rst
open_projects.rst
partitions.dot
partitions.svg
sphinx_intro.rst
windows_support.rst

README.txt

lld Documentation
=================

The lld documentation is written using the Sphinx documentation generator. It is
currently tested with Sphinx 1.1.3.

We currently use the 'nature' theme and a Beaker inspired structure.

See sphinx_intro.rst for more details.