Coverage Report

Created: 2017-09-19 22:28

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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 "Error.h"
12
#include "InputFiles.h"
13
#include "Memory.h"
14
#include "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
13
std::string lld::toString(coff::SymbolBody &B) {
24
13
  if (Optional<std::string> S = coff::demangle(B.getName()))
25
0
    return ("\"" + *S + "\" (" + B.getName() + ")").str();
26
13
  return B.getName();
27
13
}
28
29
namespace lld {
30
namespace coff {
31
32
697
StringRef SymbolBody::getName() {
33
697
  // COFF symbol names are read lazily for a performance reason.
34
697
  // Non-external symbol names are never used by the linker except for logging
35
697
  // or debugging. Their internal references are resolved not by name but by
36
697
  // symbol index. And because they are not external, no one can refer them by
37
697
  // name. Object files contain lots of non-external symbols, and creating
38
697
  // StringRefs for them (which involves lots of strlen() on the string table)
39
697
  // is a waste of time.
40
697
  if (
Name.empty()697
) {
41
210
    auto *D = cast<DefinedCOFF>(this);
42
210
    cast<ObjFile>(D->File)->getCOFFObj()->getSymbolName(D->Sym, Name);
43
210
  }
44
697
  return Name;
45
697
}
46
47
82
InputFile *SymbolBody::getFile() {
48
82
  if (auto *Sym = dyn_cast<DefinedCOFF>(this))
49
77
    return Sym->File;
50
5
  
if (auto *5
Sym5
= dyn_cast<Lazy>(this))
51
0
    return Sym->File;
52
5
  return nullptr;
53
5
}
54
55
812
bool SymbolBody::isLive() const {
56
812
  if (auto *R = dyn_cast<DefinedRegular>(this))
57
433
    return R->getChunk()->isLive();
58
379
  
if (auto *379
Imp379
= dyn_cast<DefinedImportData>(this))
59
12
    return Imp->File->Live;
60
367
  
if (auto *367
Imp367
= dyn_cast<DefinedImportThunk>(this))
61
18
    return Imp->WrappedSym->File->Live;
62
349
  // Assume any other kind of symbol is live.
63
349
  return true;
64
349
}
65
66
380
COFFSymbolRef DefinedCOFF::getCOFFSymbol() {
67
380
  size_t SymSize = cast<ObjFile>(File)->getCOFFObj()->getSymbolTableEntrySize();
68
380
  if (SymSize == sizeof(coff_symbol16))
69
380
    return COFFSymbolRef(reinterpret_cast<const coff_symbol16 *>(Sym));
70
380
  assert(SymSize == sizeof(coff_symbol32));
71
0
  return COFFSymbolRef(reinterpret_cast<const coff_symbol32 *>(Sym));
72
0
}
73
74
uint16_t DefinedAbsolute::OutputSectionIndex = 0;
75
76
63
static Chunk *makeImportThunk(DefinedImportData *S, uint16_t Machine) {
77
63
  if (Machine == AMD64)
78
46
    return make<ImportThunkChunkX64>(S);
79
17
  
if (17
Machine == I38617
)
80
12
    return make<ImportThunkChunkX86>(S);
81
5
  
if (5
Machine == ARM645
)
82
3
    return make<ImportThunkChunkARM64>(S);
83
5
  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
63
      Data(makeImportThunk(S, Machine)) {}
91
92
27
Defined *Undefined::getWeakAlias() {
93
27
  // A weak alias may be a weak alias to another symbol, so check recursively.
94
27
  for (SymbolBody *A = WeakAlias; 
A27
;
A = cast<Undefined>(A)->WeakAlias0
)
95
24
    
if (auto *24
D24
= dyn_cast<Defined>(A))
96
24
      return D;
97
3
  return nullptr;
98
27
}
99
} // namespace coff
100
} // namespace lld