Coverage Report

Created: 2018-10-20 12:32

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/MarkLive.cpp
Line
Count
Source
1
//===- MarkLive.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 "Chunks.h"
11
#include "Symbols.h"
12
#include "lld/Common/Timer.h"
13
#include "llvm/ADT/STLExtras.h"
14
#include <vector>
15
16
namespace lld {
17
namespace coff {
18
19
static Timer GCTimer("GC", Timer::root());
20
21
// Set live bit on for each reachable chunk. Unmarked (unreachable)
22
// COMDAT chunks will be ignored by Writer, so they will be excluded
23
// from the final output.
24
360
void markLive(ArrayRef<Chunk *> Chunks) {
25
360
  ScopedTimer T(GCTimer);
26
360
27
360
  // We build up a worklist of sections which have been marked as live. We only
28
360
  // push into the worklist when we discover an unmarked section, and we mark
29
360
  // as we push, so sections never appear twice in the list.
30
360
  SmallVector<SectionChunk *, 256> Worklist;
31
360
32
360
  // COMDAT section chunks are dead by default. Add non-COMDAT chunks.
33
360
  for (Chunk *C : Chunks)
34
1.34k
    if (auto *SC = dyn_cast<SectionChunk>(C))
35
1.33k
      if (SC->Live)
36
1.12k
        Worklist.push_back(SC);
37
360
38
1.06k
  auto Enqueue = [&](SectionChunk *C) {
39
1.06k
    if (C->Live)
40
860
      return;
41
208
    C->Live = true;
42
208
    Worklist.push_back(C);
43
208
  };
44
360
45
1.20k
  auto AddSym = [&](Symbol *B) {
46
1.20k
    if (auto *Sym = dyn_cast<DefinedRegular>(B))
47
1.02k
      Enqueue(Sym->getChunk());
48
184
    else if (auto *Sym = dyn_cast<DefinedImportData>(B))
49
12
      Sym->File->Live = true;
50
172
    else if (auto *Sym = dyn_cast<DefinedImportThunk>(B))
51
72
      Sym->WrappedSym->File->Live = Sym->WrappedSym->File->ThunkLive = true;
52
1.20k
  };
53
360
54
360
  // Add GC root chunks.
55
360
  for (Symbol *B : Config->GCRoot)
56
522
    AddSym(B);
57
360
58
1.68k
  while (!Worklist.empty()) {
59
1.32k
    SectionChunk *SC = Worklist.pop_back_val();
60
1.32k
    assert(SC->Live && "We mark as live when pushing onto the worklist!");
61
1.32k
62
1.32k
    // Mark all symbols listed in the relocation table for this section.
63
1.32k
    for (Symbol *B : SC->symbols())
64
688
      if (B)
65
683
        AddSym(B);
66
1.32k
67
1.32k
    // Mark associative sections if any.
68
1.32k
    for (SectionChunk *C : SC->children())
69
47
      Enqueue(C);
70
1.32k
  }
71
360
}
72
73
}
74
}