diff options
Diffstat (limited to 'lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp')
-rw-r--r-- | lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp b/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp new file mode 100644 index 000000000000..a11410784b8c --- /dev/null +++ b/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp @@ -0,0 +1,48 @@ +//===- lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.cpp --------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "LinkerGeneratedSymbolFile.h" + +namespace lld { +namespace pecoff { + +// Find decorated symbol, namely /sym@[0-9]+/ or /\?sym@@.+/. +bool findDecoratedSymbol(PECOFFLinkingContext *ctx, + std::string sym, std::string &res) { + const std::set<std::string> &defined = ctx->definedSymbols(); + // Search for /sym@[0-9]+/ + { + std::string s = sym + '@'; + auto it = defined.lower_bound(s); + for (auto e = defined.end(); it != e; ++it) { + if (!StringRef(*it).startswith(s)) + break; + if (it->size() == s.size()) + continue; + StringRef suffix = StringRef(*it).substr(s.size()); + if (suffix.find_first_not_of("0123456789") != StringRef::npos) + continue; + res = *it; + return true; + } + } + // Search for /\?sym@@.+/ + { + std::string s = "?" + ctx->undecorateSymbol(sym).str() + "@@"; + auto it = defined.lower_bound(s); + if (it != defined.end() && StringRef(*it).startswith(s)) { + res = *it; + return true; + } + } + return false; +} + +} // namespace pecoff +} // namespace lld |