Coverage Report

Created: 2018-10-23 15:26

/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
102
std::string lld::toString(coff::Symbol &B) {
24
102
  if (Optional<std::string> S = lld::demangleMSVC(B.getName()))
25
6
    return ("\"" + *S + "\" (" + B.getName() + ")").str();
26
96
  return B.getName();
27
96
}
28
29
namespace lld {
30
namespace coff {
31
32
1.95k
StringRef Symbol::getName() {
33
1.95k
  // COFF symbol names are read lazily for a performance reason.
34
1.95k
  // Non-external symbol names are never used by the linker except for logging
35
1.95k
  // or debugging. Their internal references are resolved not by name but by
36
1.95k
  // symbol index. And because they are not external, no one can refer them by
37
1.95k
  // name. Object files contain lots of non-external symbols, and creating
38
1.95k
  // StringRefs for them (which involves lots of strlen() on the string table)
39
1.95k
  // is a waste of time.
40
1.95k
  if (Name.empty()) {
41
263
    auto *D = cast<DefinedCOFF>(this);
42
263
    cast<ObjFile>(D->File)->getCOFFObj()->getSymbolName(D->Sym, Name);
43
263
  }
44
1.95k
  return Name;
45
1.95k
}
46
47
180
InputFile *Symbol::getFile() {
48
180
  if (auto *Sym = dyn_cast<DefinedCOFF>(this))
49
175
    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
1.32k
bool Symbol::isLive() const {
56
1.32k
  if (auto *R = dyn_cast<DefinedRegular>(this))
57
268
    return R->getChunk()->Live;
58
1.05k
  if (auto *Imp = dyn_cast<DefinedImportData>(this))
59
14
    return Imp->File->Live;
60
1.03k
  if (auto *Imp = dyn_cast<DefinedImportThunk>(this))
61
14
    return Imp->WrappedSym->File->ThunkLive;
62
1.02k
  // Assume any other kind of symbol is live.
63
1.02k
  return true;
64
1.02k
}
65
66
// MinGW specific.
67
8
void Symbol::replaceKeepingName(Symbol *Other, size_t Size) {
68
8
  StringRef OrigName = Name;
69
8
  memcpy(this, Other, Size);
70
8
  Name = OrigName;
71
8
}
72
73
581
COFFSymbolRef DefinedCOFF::getCOFFSymbol() {
74
581
  size_t SymSize = cast<ObjFile>(File)->getCOFFObj()->getSymbolTableEntrySize();
75
581
  if (SymSize == sizeof(coff_symbol16))
76
581
    return COFFSymbolRef(reinterpret_cast<const coff_symbol16 *>(Sym));
77
0
  assert(SymSize == sizeof(coff_symbol32));
78
0
  return COFFSymbolRef(reinterpret_cast<const coff_symbol32 *>(Sym));
79
0
}
80
81
uint16_t DefinedAbsolute::NumOutputSections;
82
83
88
static Chunk *makeImportThunk(DefinedImportData *S, uint16_t Machine) {
84
88
  if (Machine == AMD64)
85
64
    return make<ImportThunkChunkX64>(S);
86
24
  if (Machine == I386)
87
18
    return make<ImportThunkChunkX86>(S);
88
6
  if (Machine == ARM64)
89
4
    return make<ImportThunkChunkARM64>(S);
90
2
  assert(Machine == ARMNT);
91
2
  return make<ImportThunkChunkARM>(S);
92
2
}
93
94
DefinedImportThunk::DefinedImportThunk(StringRef Name, DefinedImportData *S,
95
                                       uint16_t Machine)
96
    : Defined(DefinedImportThunkKind, Name), WrappedSym(S),
97
88
      Data(makeImportThunk(S, Machine)) {}
98
99
84
Defined *Undefined::getWeakAlias() {
100
84
  // A weak alias may be a weak alias to another symbol, so check recursively.
101
84
  for (Symbol *A = WeakAlias; A; 
A = cast<Undefined>(A)->WeakAlias0
)
102
33
    if (auto *D = dyn_cast<Defined>(A))
103
33
      return D;
104
84
  
return nullptr51
;
105
84
}
106
} // namespace coff
107
} // namespace lld