Coverage Report

Created: 2018-08-19 14:04

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