LLVM  8.0.1
SymbolRemappingReader.h
Go to the documentation of this file.
1 //===- SymbolRemappingReader.h - Read symbol remapping file -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains definitions needed for reading and applying symbol
11 // remapping files.
12 //
13 // Support is provided only for the Itanium C++ name mangling scheme for now.
14 //
15 // NOTE: If you are making changes to this file format, please remember
16 // to document them in the Clang documentation at
17 // tools/clang/docs/UsersManual.rst.
18 //
19 // File format
20 // -----------
21 //
22 // The symbol remappings are written as an ASCII text file. Blank lines and
23 // lines starting with a # are ignored. All other lines specify a kind of
24 // mangled name fragment, along with two fragments of that kind that should
25 // be treated as equivalent, separated by spaces.
26 //
27 // See http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling for a
28 // description of the Itanium name mangling scheme.
29 //
30 // The accepted fragment kinds are:
31 //
32 // * name A <name>, such as 6foobar or St3__1
33 // * type A <type>, such as Ss or N4llvm9StringRefE
34 // * encoding An <encoding> (a complete mangling without the leading _Z)
35 //
36 // For example:
37 //
38 // # Ignore int / long differences to treat symbols from 32-bit and 64-bit
39 // # builds with differing size_t / ptrdiff_t / intptr_t as equivalent.
40 // type i l
41 // type j m
42 //
43 // # Ignore differences between libc++ and libstdc++, and between libstdc++'s
44 // # C++98 and C++11 ABIs.
45 // name 3std St3__1
46 // name 3std St7__cxx11
47 //
48 // # Remap a function overload to a specialization of a template (including
49 // # any local symbols declared within it).
50 // encoding N2NS1fEi N2NS1fIiEEvT_
51 //
52 // # Substitutions must be remapped separately from namespace 'std' for now.
53 // name Sa NSt3__19allocatorE
54 // name Sb NSt3__112basic_stringE
55 // type Ss NSt3__112basic_stringIcSt11char_traitsIcESaE
56 // # ...
57 //
58 //===----------------------------------------------------------------------===//
59 
60 #ifndef LLVM_SUPPORT_SYMBOLREMAPPINGREADER_H
61 #define LLVM_SUPPORT_SYMBOLREMAPPINGREADER_H
62 
63 #include "llvm/ADT/StringRef.h"
64 #include "llvm/Support/Error.h"
67 
68 namespace llvm {
69 
70 class SymbolRemappingParseError : public ErrorInfo<SymbolRemappingParseError> {
71 public:
72  SymbolRemappingParseError(StringRef File, int64_t Line, Twine Message)
73  : File(File), Line(Line), Message(Message.str()) {}
74 
75  void log(llvm::raw_ostream &OS) const override {
76  OS << File << ':' << Line << ": " << Message;
77  }
78  std::error_code convertToErrorCode() const override {
80  }
81 
82  StringRef getFileName() const { return File; }
83  int64_t getLineNum() const { return Line; }
84  StringRef getMessage() const { return Message; }
85 
86  static char ID;
87 
88 private:
89  std::string File;
90  int64_t Line;
91  std::string Message;
92 };
93 
94 /// Reader for symbol remapping files.
95 ///
96 /// Remaps the symbol names in profile data to match those in the program
97 /// according to a set of rules specified in a given file.
99 public:
100  /// Read remappings from the given buffer, which must live as long as
101  /// the remapper.
103 
104  /// A Key represents an equivalence class of symbol names.
105  using Key = uintptr_t;
106 
107  /// Construct a key for the given symbol, or return an existing one if an
108  /// equivalent name has already been inserted. The symbol name must live
109  /// as long as the remapper.
110  ///
111  /// The result will be Key() if the name cannot be remapped (typically
112  /// because it is not a valid mangled name).
113  Key insert(StringRef FunctionName) {
114  return Canonicalizer.canonicalize(FunctionName);
115  }
116 
117  /// Map the given symbol name into the key for the corresponding equivalence
118  /// class.
119  ///
120  /// The result will typically be Key() if no equivalent symbol has been
121  /// inserted, but this is not guaranteed: a Key different from all keys ever
122  /// returned by \c insert may be returned instead.
123  Key lookup(StringRef FunctionName) {
124  return Canonicalizer.lookup(FunctionName);
125  }
126 
127 private:
128  ItaniumManglingCanonicalizer Canonicalizer;
129 };
130 
131 } // end namespace llvm
132 
133 #endif // LLVM_SUPPORT_SYMBOLREMAPPINGREADER_H
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Key insert(StringRef FunctionName)
Construct a key for the given symbol, or return an existing one if an equivalent name has already bee...
Key lookup(StringRef FunctionName)
Map the given symbol name into the key for the corresponding equivalence class.
SymbolRemappingParseError(StringRef File, int64_t Line, Twine Message)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
uintptr_t Key
A Key represents an equivalence class of symbol names.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void log(llvm::raw_ostream &OS) const override
Print an error message to an output stream.
Canonicalizer for mangled names.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:42
Base class for user error types.
Definition: Error.h:345
Reader for symbol remapping files.
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Definition: Endian.h:66
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:78