Implement --trace-symbol=symbol option.

Patch by Shridhar Joshi.

This option provides names of all the link time modules which define and
reference symbols requested by user. This helps to speed up application
development by detecting references causing undefined symbols.
It also helps in detecting symbols being resolved to wrong (unintended)
definitions in case of applications containing multiple definitions for
same symbols with different types, bindings.

Implements PR28226.

llvm-svn: 273536
This commit is contained in:
Rui Ueyama
2016-06-23 07:00:17 +00:00
parent 4a716226a5
commit d60dae8a6a
10 changed files with 143 additions and 0 deletions

View File

@@ -313,6 +313,14 @@ elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec) {
return new (IAlloc.Allocate()) InputSection<ELFT>(this, &Sec);
}
// Print the module names which reference the notified
// symbols provided through -y or --trace-symbol option.
template <class ELFT>
void elf::ObjectFile<ELFT>::traceUndefined(StringRef Name) {
if (!Config->TraceSymbol.empty() && Config->TraceSymbol.count(Name))
outs() << getFilename(this) << ": reference to " << Name << "\n";
}
template <class ELFT> void elf::ObjectFile<ELFT>::initializeSymbols() {
this->initStringTable();
Elf_Sym_Range Syms = this->getElfSymbols(false);
@@ -350,6 +358,7 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
switch (Sym->st_shndx) {
case SHN_UNDEF:
traceUndefined(Name);
return elf::Symtab<ELFT>::X
->addUndefined(Name, Binding, Sym->st_other, Sym->getType(),
/*CanOmitFromDynSym*/ false, this)