Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/SymbolTable.h
Line
Count
Source
1
//===- SymbolTable.h --------------------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLD_COFF_SYMBOL_TABLE_H
10
#define LLD_COFF_SYMBOL_TABLE_H
11
12
#include "InputFiles.h"
13
#include "LTO.h"
14
#include "llvm/ADT/CachedHashString.h"
15
#include "llvm/ADT/DenseMap.h"
16
#include "llvm/ADT/DenseMapInfo.h"
17
#include "llvm/Support/raw_ostream.h"
18
19
namespace llvm {
20
struct LTOCodeGenerator;
21
}
22
23
namespace lld {
24
namespace coff {
25
26
class Chunk;
27
class CommonChunk;
28
class Defined;
29
class DefinedAbsolute;
30
class DefinedRegular;
31
class DefinedRelative;
32
class Lazy;
33
class SectionChunk;
34
class Symbol;
35
36
// SymbolTable is a bucket of all known symbols, including defined,
37
// undefined, or lazy symbols (the last one is symbols in archive
38
// files whose archive members are not yet loaded).
39
//
40
// We put all symbols of all files to a SymbolTable, and the
41
// SymbolTable selects the "best" symbols if there are name
42
// conflicts. For example, obviously, a defined symbol is better than
43
// an undefined symbol. Or, if there's a conflict between a lazy and a
44
// undefined, it'll read an archive member to read a real definition
45
// to replace the lazy symbol. The logic is implemented in the
46
// add*() functions, which are called by input files as they are parsed.
47
// There is one add* function per symbol type.
48
class SymbolTable {
49
public:
50
  void addFile(InputFile *file);
51
52
  // Try to resolve any undefined symbols and update the symbol table
53
  // accordingly, then print an error message for any remaining undefined
54
  // symbols.
55
  void reportRemainingUndefines();
56
57
  void loadMinGWAutomaticImports();
58
  bool handleMinGWAutomaticImport(Symbol *sym, StringRef name);
59
60
  // Returns a list of chunks of selected symbols.
61
  std::vector<Chunk *> getChunks();
62
63
  // Returns a symbol for a given name. Returns a nullptr if not found.
64
  Symbol *find(StringRef name);
65
  Symbol *findUnderscore(StringRef name);
66
67
  // Occasionally we have to resolve an undefined symbol to its
68
  // mangled symbol. This function tries to find a mangled name
69
  // for U from the symbol table, and if found, set the symbol as
70
  // a weak alias for U.
71
  Symbol *findMangle(StringRef name);
72
73
  // Build a set of COFF objects representing the combined contents of
74
  // BitcodeFiles and add them to the symbol table. Called after all files are
75
  // added and before the writer writes results to a file.
76
  void addCombinedLTOObjects();
77
  std::vector<StringRef> compileBitcodeFiles();
78
79
  // Creates an Undefined symbol for a given name.
80
  Symbol *addUndefined(StringRef name);
81
82
  Symbol *addSynthetic(StringRef n, Chunk *c);
83
  Symbol *addAbsolute(StringRef n, uint64_t va);
84
85
  Symbol *addUndefined(StringRef name, InputFile *f, bool isWeakAlias);
86
  void addLazy(ArchiveFile *f, const Archive::Symbol &sym);
87
  Symbol *addAbsolute(StringRef n, COFFSymbolRef s);
88
  Symbol *addRegular(InputFile *f, StringRef n,
89
                     const llvm::object::coff_symbol_generic *s = nullptr,
90
                     SectionChunk *c = nullptr);
91
  std::pair<DefinedRegular *, bool>
92
  addComdat(InputFile *f, StringRef n,
93
            const llvm::object::coff_symbol_generic *s = nullptr);
94
  Symbol *addCommon(InputFile *f, StringRef n, uint64_t size,
95
                    const llvm::object::coff_symbol_generic *s = nullptr,
96
                    CommonChunk *c = nullptr);
97
  Symbol *addImportData(StringRef n, ImportFile *f);
98
  Symbol *addImportThunk(StringRef name, DefinedImportData *s,
99
                         uint16_t machine);
100
101
  void reportDuplicate(Symbol *existing, InputFile *newFile);
102
103
  // A list of chunks which to be added to .rdata.
104
  std::vector<Chunk *> localImportChunks;
105
106
  // Iterates symbols in non-determinstic hash table order.
107
125
  template <typename T> void forEachSymbol(T callback) {
108
125
    for (auto &pair : symMap)
109
1.61k
      callback(pair.second);
110
125
  }
Driver.cpp:void lld::coff::SymbolTable::forEachSymbol<lld::coff::LinkerDriver::maybeExportMinGWSymbols(llvm::opt::InputArgList const&)::$_7>(lld::coff::LinkerDriver::maybeExportMinGWSymbols(llvm::opt::InputArgList const&)::$_7)
Line
Count
Source
107
15
  template <typename T> void forEachSymbol(T callback) {
108
15
    for (auto &pair : symMap)
109
263
      callback(pair.second);
110
15
  }
PDB.cpp:void lld::coff::SymbolTable::forEachSymbol<(anonymous namespace)::PDBLinker::addObjectsToPDB()::$_3>((anonymous namespace)::PDBLinker::addObjectsToPDB()::$_3)
Line
Count
Source
107
110
  template <typename T> void forEachSymbol(T callback) {
108
110
    for (auto &pair : symMap)
109
1.34k
      callback(pair.second);
110
110
  }
111
112
private:
113
  /// Inserts symbol if not already present.
114
  std::pair<Symbol *, bool> insert(StringRef name);
115
  /// Same as insert(Name), but also sets isUsedInRegularObj.
116
  std::pair<Symbol *, bool> insert(StringRef name, InputFile *f);
117
118
  std::vector<Symbol *> getSymsWithPrefix(StringRef prefix);
119
120
  llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> symMap;
121
  std::unique_ptr<BitcodeCompiler> lto;
122
};
123
124
extern SymbolTable *symtab;
125
126
std::vector<std::string> getSymbolLocations(ObjFile *file, uint32_t symIndex);
127
128
} // namespace coff
129
} // namespace lld
130
131
#endif