Coverage Report

Created: 2019-01-18 03:29

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