Coverage Report

Created: 2018-06-25 02:00

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/Symbols.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Symbols.cpp --------------------------------------------------------===//
2
//
3
//                             The LLVM Linker
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#include "Symbols.h"
11
#include "InputFiles.h"
12
#include "lld/Common/ErrorHandler.h"
13
#include "lld/Common/Memory.h"
14
#include "lld/Common/Strings.h"
15
#include "llvm/ADT/STLExtras.h"
16
#include "llvm/Support/Debug.h"
17
#include "llvm/Support/raw_ostream.h"
18
19
using namespace llvm;
20
using namespace llvm::object;
21
22
// Returns a symbol name for an error message.
23
33
std::string lld::toString(coff::Symbol &B) {
24
33
  if (Optional<std::string> S = lld::demangleMSVC(B.getName()))
25
0
    return ("\"" + *S + "\" (" + B.getName() + ")").str();
26
33
  return B.getName();
27
33
}
28
29
namespace lld {
30
namespace coff {
31
32
1.24k
StringRef Symbol::getName() {
33
1.24k
  // COFF symbol names are read lazily for a performance reason.
34
1.24k
  // Non-external symbol names are never used by the linker except for logging
35
1.24k
  // or debugging. Their internal references are resolved not by name but by
36
1.24k
  // symbol index. And because they are not external, no one can refer them by
37
1.24k
  // name. Object files contain lots of non-external symbols, and creating
38
1.24k
  // StringRefs for them (which involves lots of strlen() on the string table)
39
1.24k
  // is a waste of time.
40
1.24k
  if (Name.empty()) {
41
242
    auto *D = cast<DefinedCOFF>(this);
42
242
    cast<ObjFile>(D->File)->getCOFFObj()->getSymbolName(D->Sym, Name);
43
242
  }
44
1.24k
  return Name;
45
1.24k
}
46
47
141
InputFile *Symbol::getFile() {
48
141
  if (auto *Sym = dyn_cast<DefinedCOFF>(this))
49
136
    return Sym->File;
50
5
  if (auto *Sym = dyn_cast<Lazy>(this))
51
0
    return Sym->File;
52
5
  return nullptr;
53
5
}
54
55
932
bool Symbol::isLive() const {
56
932
  if (auto *R = dyn_cast<DefinedRegular>(this))
57
218
    return R->getChunk()->isLive();
58
714
  if (auto *Imp = dyn_cast<DefinedImportData>(this))
59
11
    return Imp->File->Live;
60
703
  if (auto *Imp = dyn_cast<DefinedImportThunk>(this))
61
11
    return Imp->WrappedSym->File->ThunkLive;
62
692
  // Assume any other kind of symbol is live.
63
692
  return true;
64
692
}
65
66
515
COFFSymbolRef DefinedCOFF::getCOFFSymbol() {
67
515
  size_t SymSize = cast<ObjFile>(File)->getCOFFObj()->getSymbolTableEntrySize();
68
515
  if (SymSize == sizeof(coff_symbol16))
69
515
    return COFFSymbolRef(reinterpret_cast<const coff_symbol16 *>(Sym));
70
0
  assert(SymSize == sizeof(coff_symbol32));
71
0
  return COFFSymbolRef(reinterpret_cast<const coff_symbol32 *>(Sym));
72
0
}
73
74
uint16_t DefinedAbsolute::NumOutputSections;
75
76
75
static Chunk *makeImportThunk(DefinedImportData *S, uint16_t Machine) {
77
75
  if (Machine == AMD64)
78
52
    return make<ImportThunkChunkX64>(S);
79
23
  if (Machine == I386)
80
18
    return make<ImportThunkChunkX86>(S);
81
5
  if (Machine == ARM64)
82
3
    return make<ImportThunkChunkARM64>(S);
83
2
  assert(Machine == ARMNT);
84
2
  return make<ImportThunkChunkARM>(S);
85
2
}
86
87
DefinedImportThunk::DefinedImportThunk(StringRef Name, DefinedImportData *S,
88
                                       uint16_t Machine)
89
    : Defined(DefinedImportThunkKind, Name), WrappedSym(S),
90
75
      Data(makeImportThunk(S, Machine)) {}
91
92
60
Defined *Undefined::getWeakAlias() {
93
60
  // A weak alias may be a weak alias to another symbol, so check recursively.
94
60
  for (Symbol *A = WeakAlias; A; 
A = cast<Undefined>(A)->WeakAlias0
)
95
28
    if (auto *D = dyn_cast<Defined>(A))
96
28
      return D;
97
60
  
return nullptr32
;
98
60
}
99
} // namespace coff
100
} // namespace lld