Coverage Report

Created: 2018-06-18 20:01

/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
298
void markLive(ArrayRef<Chunk *> Chunks) {
25
298
  ScopedTimer T(GCTimer);
26
298
27
298
  // We build up a worklist of sections which have been marked as live. We only
28
298
  // push into the worklist when we discover an unmarked section, and we mark
29
298
  // as we push, so sections never appear twice in the list.
30
298
  SmallVector<SectionChunk *, 256> Worklist;
31
298
32
298
  // COMDAT section chunks are dead by default. Add non-COMDAT chunks.
33
298
  for (Chunk *C : Chunks)
34
948
    if (auto *SC = dyn_cast<SectionChunk>(C))
35
937
      if (SC->isLive())
36
744
        Worklist.push_back(SC);
37
298
38
862
  auto Enqueue = [&](SectionChunk *C) {
39
862
    if (C->isLive())
40
673
      return;
41
189
    C->markLive();
42
189
    Worklist.push_back(C);
43
189
  };
44
298
45
954
  auto AddSym = [&](Symbol *B) {
46
954
    if (auto *Sym = dyn_cast<DefinedRegular>(B))
47
822
      Enqueue(Sym->getChunk());
48
132
    else if (auto *Sym = dyn_cast<DefinedImportData>(B))
49
4
      Sym->File->Live = true;
50
128
    else if (auto *Sym = dyn_cast<DefinedImportThunk>(B))
51
62
      Sym->WrappedSym->File->Live = Sym->WrappedSym->File->ThunkLive = true;
52
954
  };
53
298
54
298
  // Add GC root chunks.
55
298
  for (Symbol *B : Config->GCRoot)
56
448
    AddSym(B);
57
298
58
1.23k
  while (!Worklist.empty()) {
59
933
    SectionChunk *SC = Worklist.pop_back_val();
60
933
    assert(SC->isLive() && "We mark as live when pushing onto the worklist!");
61
933
62
933
    // Mark all symbols listed in the relocation table for this section.
63
933
    for (Symbol *B : SC->symbols())
64
506
      if (B)
65
506
        AddSym(B);
66
933
67
933
    // Mark associative sections if any.
68
933
    for (SectionChunk *C : SC->children())
69
40
      Enqueue(C);
70
933
  }
71
298
}
72
73
}
74
}