From: Rui Ueyama Date: Mon, 18 Jul 2016 01:35:00 +0000 (+0000) Subject: Remove SymbolBody::PlaceholderKind. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e33579072d8d8a97d029fc136314f642105c080a;p=platform%2Fupstream%2Fllvm.git Remove SymbolBody::PlaceholderKind. In the last patch for --trace-symbol, I introduced a new symbol type PlaceholderKind and store it to SymVector storage. It made all code that iterates over SymVector to recognize and skip PlaceholderKind symbols. I found that that's annoying. In this patch, I removed PlaceholderKind and stop storing them to SymVector. Now the information whether a symbol is being watched by --trace-symbol is stored to the Symtab hash table. llvm-svn: 275747 --- diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index fd97c6b..50b9401 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -1465,7 +1465,6 @@ SymbolTableSection::getOutputSection(SymbolBody *Sym) { case SymbolBody::LazyArchiveKind: case SymbolBody::LazyObjectKind: break; - case SymbolBody::PlaceholderKind: case SymbolBody::DefinedBitcodeKind: llvm_unreachable("should have been replaced"); } diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index d02c8d6..78c1298 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -143,17 +143,7 @@ DefinedRegular *SymbolTable::addIgnored(StringRef Name, // Set a flag for --trace-symbol so that we can print out a log message // if a new symbol with the same name is inserted into the symbol table. template void SymbolTable::trace(StringRef Name) { - Symbol *S; - bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - assert(WasInserted); - - S->Traced = true; - - // We created a new symbol just to turn on Trace flag. - // Write a dummy SymbolBody so that trace() does not affect - // normal symbol operations. - new (S->body()) SymbolBody(SymbolBody::PlaceholderKind); + Symtab.insert({Name, {-1, true}}); } // Rename SYM as __wrap_SYM. The original symbol is preserved as __real_SYM. @@ -184,10 +174,15 @@ static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) { // Find an existing symbol or create and insert a new one. template std::pair SymbolTable::insert(StringRef Name) { - unsigned NumSyms = SymVector.size(); - auto P = Symtab.insert(std::make_pair(Name, NumSyms)); + auto P = Symtab.insert({Name, {(int)SymVector.size(), false}}); + SymIndex &V = P.first->second; bool IsNew = P.second; + if (V.Idx == -1) { + IsNew = true; + V = {(int)SymVector.size(), true}; + } + Symbol *Sym; if (IsNew) { Sym = new (Alloc) Symbol; @@ -196,12 +191,10 @@ std::pair SymbolTable::insert(StringRef Name) { Sym->IsUsedInRegularObj = false; Sym->ExportDynamic = false; Sym->VersionId = Config->DefaultSymbolVersion; - Sym->Traced = false; + Sym->Traced = V.Traced; SymVector.push_back(Sym); } else { - Sym = SymVector[P.first->second]; - if (Sym->body()->kind() == SymbolBody::PlaceholderKind) - IsNew = true; + Sym = SymVector[V.Idx]; } return {Sym, IsNew}; } @@ -449,7 +442,10 @@ template SymbolBody *SymbolTable::find(StringRef Name) { auto It = Symtab.find(Name); if (It == Symtab.end()) return nullptr; - return SymVector[It->second]->body(); + SymIndex V = It->second; + if (V.Idx == -1) + return nullptr; + return SymVector[V.Idx]->body(); } // Returns a list of defined symbols that match with a given glob pattern. diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index 727f2e9..40415b6 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -101,6 +101,11 @@ private: std::map getDemangledSyms(); + struct SymIndex { + int Idx : 31; + unsigned Traced : 1; + }; + // The order the global symbols are in is not defined. We can use an arbitrary // order, but it has to be reproducible. That is true even when cross linking. // The default hashing of StringRef produces different results on 32 and 64 @@ -108,7 +113,7 @@ private: // but a bit inefficient. // FIXME: Experiment with passing in a custom hashing or sorting the symbols // once symbol resolution is finished. - llvm::DenseMap Symtab; + llvm::DenseMap Symtab; std::vector SymVector; llvm::BumpPtrAllocator Alloc; diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 4f95281..d6a605d 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -79,7 +79,6 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body, case SymbolBody::LazyObjectKind: assert(Body.symbol()->IsUsedInRegularObj && "lazy symbol reached writer"); return 0; - case SymbolBody::PlaceholderKind: case SymbolBody::DefinedBitcodeKind: llvm_unreachable("should have been replaced"); } diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index 6847f46..aa9a87d 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -51,7 +51,6 @@ public: UndefinedKind, LazyArchiveKind, LazyObjectKind, - PlaceholderKind, }; SymbolBody(Kind K) : SymbolKind(K) {} diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 60152fe..387bec3 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -698,8 +698,6 @@ template void Writer::createSections() { std::vector CommonSymbols; for (Symbol *S : Symtab.getSymbols()) { SymbolBody *Body = S->body(); - if (Body->kind() == SymbolBody::PlaceholderKind) - continue; // We only report undefined symbols in regular objects. This means that we // will accept an undefined reference in bitcode if it can be optimized out.