Add DT_INIT and DT_FINI entries to the dynamic table section if corresponding symbols are defined, "_init" and "_fini" respectively.
Symbol names can be overridden by using -init and -fini command line switches.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
What happens if the symbol given by -fini is in an archive? Does linker have to resolve the symbol by extracting and parsing the object file from the archive?
ELF/OutputSections.cpp | ||
---|---|---|
221–232 ↗ | (On Diff #36364) | Lambda doesn't seem to help improve readability here. This would be better. if (Symbol *S = Symtab.getSymbols().lookup(Config->Init))) InitSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body); if (Symbol *S = Symtab.getSymbols().lookup(Config->Fini))) FiniSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body); if (InitSym) ++NumEntries; // DT_FINI if (FiniSym) ++NumEntries; // DT_INIT |
ELF/OutputSections.h | ||
334–335 ↗ | (On Diff #36364) | InitSymbolBody -> InitSym |
334–335 ↗ | (On Diff #36364) | These symbols type should be Defined<ELFT>, no? They can't be Undefined<ELFT> which is a subclass of ELFSymbolBody<ELFT> |
I investigated this case with ld. These switches don't force the linker to resolve these symbols. Moreover, there is even no warning if the symbols stay unresolved.
ELF/OutputSections.h | ||
---|---|---|
334–335 ↗ | (On Diff #36364) |
It sounds strange, but: $ cat > x.s .globl _start,_init,_fini; _start: ^C $ llvm-mc -filetype=obj -triple=x86_64-pc-linux -o x.o x.s $ ld -shared -o x.out x.o $ llvm-readobj -dynamic-table -symbols x.out File: x.out Format: ELF64-x86-64 Arch: x86_64 AddressSize: 64bit LoadName: Symbols [ ... Symbol { Name: _init (32) Value: 0x0 Size: 0 Binding: Global (0x1) Type: None (0x0) Other: 0 Section: Undefined (0x0) } ... Symbol { Name: _fini (57) Value: 0x0 Size: 0 Binding: Global (0x1) Type: None (0x0) Other: 0 Section: Undefined (0x0) } ... ] DynamicSection [ (8 entries) Tag Type Name/Value 0x000000000000000C INIT 0x0 0x000000000000000D FINI 0x0 0x0000000000000004 HASH 0xE8 0x0000000000000005 STRTAB 0x1C0 0x0000000000000006 SYMTAB 0x118 0x000000000000000A STRSZ 37 (bytes) 0x000000000000000B SYMENT 24 (bytes) 0x0000000000000000 NULL 0x0 ] |
Thank you for the investigation. LGTM
lld/trunk/ELF/OutputSections.cpp | ||
---|---|---|
232 | Remove this blank line. |
Remove this blank line.