llvm-project/lld/ELF
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
..
Arch [lld][Hexagon] Add checks for instructions that can have TLS relocations 2021-09-01 13:15:18 -07:00
AArch64ErrataFix.cpp [ELF] Move the outSecOff addend from relocAlloc/relocNonAlloc/... to InputSectionBase::relocate 2020-08-11 08:06:38 -07:00
AArch64ErrataFix.h [LLD][ELF] Optimize linker script filename glob pattern matching NFC 2020-09-16 10:26:11 +01:00
ARMErrataFix.cpp [LLD][ELF][ARM] Fix case of patched unrelocated BLX 2021-06-30 14:07:35 +01:00
ARMErrataFix.h [LLD][ELF] Optimize linker script filename glob pattern matching NFC 2020-09-16 10:26:11 +01:00
CMakeLists.txt [CMake] Make `intrinsics_gen` dependency unconditional. 2020-07-17 16:43:17 -07:00
CallGraphSort.cpp [COFF] Port CallGraphSort to COFF from ELF 2020-07-30 15:21:44 -07:00
CallGraphSort.h
Config.h [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
DWARF.cpp [lib/Object] - Generalize the RelocationResolver API. 2020-11-20 10:32:49 +03:00
DWARF.h [ELF] --gdb-index: skip SHF_GROUP .debug_info 2020-08-13 09:11:01 -07:00
Driver.cpp [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
Driver.h [LLD] Rename lld port driver entry function to a consistent name 2020-12-18 12:18:37 +05:30
DriverUtils.cpp [OptTable] Rename PrintHelp to printHelp 2021-06-24 14:47:03 -07:00
EhFrame.cpp ELF: Teach the linker about the 'B' augmentation string character. 2021-01-05 19:51:11 -08:00
EhFrame.h [ELF] --icf: don't fold text sections with LSDA 2020-08-05 09:16:28 -07:00
ICF.cpp [LLD][ELF] Improve ICF for relocations to ineligible sections via "aliases" 2020-10-15 12:43:14 +01:00
ICF.h
InputFiles.cpp [ELF] Infer EM_HEXAGON in getBitcodeMachineKind 2021-09-07 20:46:37 -07:00
InputFiles.h [LLD] Adding support for RELA for CG Profile. 2021-07-13 13:56:30 -07:00
InputSection.cpp [LLD] Support compressed input sections on big-endian targets 2021-08-07 13:20:13 +03:00
InputSection.h [LLD] Support compressed input sections on big-endian targets 2021-08-07 13:20:13 +03:00
LTO.cpp [LTO][lld] Add lto-pgo-warn-mismatch option 2021-08-11 09:45:55 -07:00
LTO.h
LinkerScript.cpp [ELF] Make dot in .tbss correct 2021-08-04 08:58:50 -07:00
LinkerScript.h [ELF] Make dot in .tbss correct 2021-08-04 08:58:50 -07:00
MapFile.cpp [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
MapFile.h [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
MarkLive.cpp Revert "[ELF] --gc-sections: allow GC on reserved sections in a group" 2021-07-27 16:34:32 -07:00
MarkLive.h
Options.td [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
OutputSections.cpp [ELF] Check the Elf_Rel addends for dynamic relocations 2021-07-09 10:41:40 +01:00
OutputSections.h [ELF] Check the Elf_Rel addends for dynamic relocations 2021-07-09 10:41:40 +01:00
README.md
Relocations.cpp [ELF] Simplify addGotEntry. NFC 2021-08-29 13:40:08 -07:00
Relocations.h [ELF] Support .rela.eh_frame with unordered r_offset values 2021-04-29 08:51:09 -07:00
ScriptLexer.cpp [ELF] Optimize ScriptLexer::getLineNumber by caching the previous line number and offset 2021-06-22 15:35:24 -07:00
ScriptLexer.h [ELF] Optimize ScriptLexer::getLineNumber by caching the previous line number and offset 2021-06-22 15:35:24 -07:00
ScriptParser.cpp [ELF] Apply version script patterns to non-default version symbols 2021-08-04 23:52:56 -07:00
ScriptParser.h [ELF] Improve --export-dynamic-symbol performance by checking whether wildcard is really used 2020-06-17 17:12:10 -07:00
SymbolTable.cpp [ELF] Apply version script patterns to non-default version symbols 2021-08-04 23:52:56 -07:00
SymbolTable.h [ELF] Apply version script patterns to non-default version symbols 2021-08-04 23:52:56 -07:00
Symbols.cpp [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
Symbols.h [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
SyntheticSections.cpp [ELF] Add -Bsymbolic-non-weak-functions 2021-07-29 14:46:53 -07:00
SyntheticSections.h [ELF][AArch64] Write addends for TLSDESC relocations with -z rel 2021-07-09 10:41:41 +01:00
Target.cpp [ELF] Check the Elf_Rel addends for dynamic relocations 2021-07-09 10:41:40 +01:00
Target.h [lld][X86] Restore gotEntrySize. 2021-05-17 00:13:00 +01:00
Thunks.cpp [ELF] Refactor DynamicReloc to fix incorrect relocation addends 2021-07-09 10:41:40 +01:00
Thunks.h [lld] Add missing includes (NFC) 2021-06-03 18:55:18 +02:00
Writer.cpp [ELF] Add --why-extract= to query why archive members/lazy object files are extracted 2021-09-20 09:52:30 -07:00
Writer.h Revert "Revert r370635, it caused PR43241." 2019-09-06 15:57:24 +00:00

README.md

See docs/NewLLD.rst