Implement almost-zero-cost --trace-symbol.

--trace-symbol is a command line option to watch a symbol.
Previosly, we looked up a hash table for a new symbol if the
option is given. Any code that looks up a hash table for each
symbol is expensive because the linker handles a lot of symbols.
In our design, we look up a hash table strictly only once
for a symbol, so --trace-symbol was an exception.

This patch improves efficiency of the option by merging the
hash table into the symbol table.

Instead of looking up a separate hash table with a string,
this patch sets `Traced` flag to symbols specified by --trace-symbol.
So, if you insert a symbol and get a symbol with `Traced` flag on,
you know that you need to print out a log message for the symbol.
This is nearly zero cost.

llvm-svn: 275716
This commit is contained in:
Rui Ueyama
2016-07-17 17:50:09 +00:00
parent b06700fa78
commit 69c778c084
8 changed files with 65 additions and 33 deletions

View File

@@ -360,11 +360,6 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
switch (Sym->st_shndx) {
case SHN_UNDEF:
// Handle --trace-symbol option. Prints out a log message
// if the current symbol is being watched. Useful for debugging.
if (!Config->TraceSymbol.empty() && Config->TraceSymbol.count(Name))
outs() << getFilename(this) << ": reference to " << Name << "\n";
return elf::Symtab<ELFT>::X
->addUndefined(Name, Binding, Sym->st_other, Sym->getType(),
/*CanOmitFromDynSym*/ false, this)