Coverage Report

Created: 2017-09-19 22:28

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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 "llvm/ADT/STLExtras.h"
13
#include <vector>
14
15
namespace lld {
16
namespace coff {
17
18
// Set live bit on for each reachable chunk. Unmarked (unreachable)
19
// COMDAT chunks will be ignored by Writer, so they will be excluded
20
// from the final output.
21
249
void markLive(const std::vector<Chunk *> &Chunks) {
22
249
  // We build up a worklist of sections which have been marked as live. We only
23
249
  // push into the worklist when we discover an unmarked section, and we mark
24
249
  // as we push, so sections never appear twice in the list.
25
249
  SmallVector<SectionChunk *, 256> Worklist;
26
249
27
249
  // COMDAT section chunks are dead by default. Add non-COMDAT chunks.
28
249
  for (Chunk *C : Chunks)
29
715
    
if (auto *715
SC715
= dyn_cast<SectionChunk>(C))
30
705
      
if (705
SC->isLive()705
)
31
641
        Worklist.push_back(SC);
32
249
33
671
  auto Enqueue = [&](SectionChunk *C) {
34
671
    if (C->isLive())
35
622
      return;
36
49
    C->markLive();
37
49
    Worklist.push_back(C);
38
49
  };
39
249
40
770
  auto AddSym = [&](SymbolBody *B) {
41
770
    if (auto *Sym = dyn_cast<DefinedRegular>(B))
42
662
      Enqueue(Sym->getChunk());
43
108
    else 
if (auto *108
Sym108
= dyn_cast<DefinedImportData>(B))
44
3
      Sym->File->Live = true;
45
105
    else 
if (auto *105
Sym105
= dyn_cast<DefinedImportThunk>(B))
46
63
      Sym->WrappedSym->File->Live = true;
47
770
  };
48
249
49
249
  // Add GC root chunks.
50
249
  for (SymbolBody *B : Config->GCRoot)
51
345
    AddSym(B);
52
249
53
939
  while (
!Worklist.empty()939
) {
54
690
    SectionChunk *SC = Worklist.pop_back_val();
55
690
56
690
    // If this section was discarded, there are relocations referring to
57
690
    // discarded sections. Ignore these sections to avoid crashing. They will be
58
690
    // diagnosed during relocation processing.
59
690
    if (SC->isDiscarded())
60
1
      continue;
61
689
62
690
    assert(SC->isLive() && "We mark as live when pushing onto the worklist!");
63
689
64
689
    // Mark all symbols listed in the relocation table for this section.
65
689
    for (SymbolBody *B : SC->symbols())
66
425
      AddSym(B);
67
689
68
689
    // Mark associative sections if any.
69
689
    for (SectionChunk *C : SC->children())
70
9
      Enqueue(C);
71
690
  }
72
249
}
73
74
}
75
}