Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/MarkLive.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- MarkLive.cpp -------------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements --gc-sections, which is a feature to remove unused
10
// sections from output. Unused sections are sections that are not reachable
11
// from known GC-root symbols or sections. Naturally the feature is
12
// implemented as a mark-sweep garbage collector.
13
//
14
// Here's how it works. Each InputSectionBase has a "Live" bit. The bit is off
15
// by default. Starting with GC-root symbols or sections, markLive function
16
// defined in this file visits all reachable sections to set their Live
17
// bits. Writer will then ignore sections whose Live bits are off, so that
18
// such sections are not included into output.
19
//
20
//===----------------------------------------------------------------------===//
21
22
#include "MarkLive.h"
23
#include "InputSection.h"
24
#include "LinkerScript.h"
25
#include "OutputSections.h"
26
#include "SymbolTable.h"
27
#include "Symbols.h"
28
#include "SyntheticSections.h"
29
#include "Target.h"
30
#include "lld/Common/Memory.h"
31
#include "lld/Common/Strings.h"
32
#include "llvm/ADT/STLExtras.h"
33
#include "llvm/Object/ELF.h"
34
#include <functional>
35
#include <vector>
36
37
using namespace llvm;
38
using namespace llvm::ELF;
39
using namespace llvm::object;
40
using namespace llvm::support::endian;
41
42
using namespace lld;
43
using namespace lld::elf;
44
45
namespace {
46
template <class ELFT> class MarkLive {
47
public:
48
111
  MarkLive(unsigned partition) : partition(partition) {}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::MarkLive(unsigned int)
Line
Count
Source
48
14
  MarkLive(unsigned partition) : partition(partition) {}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::MarkLive(unsigned int)
Line
Count
Source
48
2
  MarkLive(unsigned partition) : partition(partition) {}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::MarkLive(unsigned int)
Line
Count
Source
48
94
  MarkLive(unsigned partition) : partition(partition) {}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::MarkLive(unsigned int)
Line
Count
Source
48
1
  MarkLive(unsigned partition) : partition(partition) {}
49
50
  void run();
51
  void moveToMain();
52
53
private:
54
  void enqueue(InputSectionBase *sec, uint64_t offset);
55
  void markSymbol(Symbol *sym);
56
  void mark();
57
58
  template <class RelTy>
59
  void resolveReloc(InputSectionBase &sec, RelTy &rel, bool isLSDA);
60
61
  template <class RelTy>
62
  void scanEhFrameSection(EhInputSection &eh, ArrayRef<RelTy> rels);
63
64
  // The index of the partition that we are currently processing.
65
  unsigned partition;
66
67
  // A list of sections to visit.
68
  SmallVector<InputSection *, 256> queue;
69
70
  // There are normally few input sections whose names are valid C
71
  // identifiers, so we just store a std::vector instead of a multimap.
72
  DenseMap<StringRef, std::vector<InputSectionBase *>> cNamedSections;
73
};
74
} // namespace
75
76
template <class ELFT>
77
static uint64_t getAddend(InputSectionBase &sec,
78
15
                          const typename ELFT::Rel &rel) {
79
15
  return target->getImplicitAddend(sec.data().begin() + rel.r_offset,
80
15
                                   rel.getType(config->isMips64EL));
81
15
}
MarkLive.cpp:unsigned long long getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(lld::elf::InputSectionBase&, llvm::object::ELFType<(llvm::support::endianness)1, false>::Rel const&)
Line
Count
Source
78
15
                          const typename ELFT::Rel &rel) {
79
15
  return target->getImplicitAddend(sec.data().begin() + rel.r_offset,
80
15
                                   rel.getType(config->isMips64EL));
81
15
}
Unexecuted instantiation: MarkLive.cpp:unsigned long long getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(lld::elf::InputSectionBase&, llvm::object::ELFType<(llvm::support::endianness)0, false>::Rel const&)
Unexecuted instantiation: MarkLive.cpp:unsigned long long getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(lld::elf::InputSectionBase&, llvm::object::ELFType<(llvm::support::endianness)1, true>::Rel const&)
Unexecuted instantiation: MarkLive.cpp:unsigned long long getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(lld::elf::InputSectionBase&, llvm::object::ELFType<(llvm::support::endianness)0, true>::Rel const&)
82
83
template <class ELFT>
84
static uint64_t getAddend(InputSectionBase &sec,
85
47
                          const typename ELFT::Rela &rel) {
86
47
  return rel.r_addend;
87
47
}
Unexecuted instantiation: MarkLive.cpp:unsigned long long getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(lld::elf::InputSectionBase&, llvm::object::ELFType<(llvm::support::endianness)1, false>::Rela const&)
Unexecuted instantiation: MarkLive.cpp:unsigned long long getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(lld::elf::InputSectionBase&, llvm::object::ELFType<(llvm::support::endianness)0, false>::Rela const&)
MarkLive.cpp:unsigned long long getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(lld::elf::InputSectionBase&, llvm::object::ELFType<(llvm::support::endianness)1, true>::Rela const&)
Line
Count
Source
85
47
                          const typename ELFT::Rela &rel) {
86
47
  return rel.r_addend;
87
47
}
Unexecuted instantiation: MarkLive.cpp:unsigned long long getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(lld::elf::InputSectionBase&, llvm::object::ELFType<(llvm::support::endianness)0, true>::Rela const&)
88
89
template <class ELFT>
90
template <class RelTy>
91
void MarkLive<ELFT>::resolveReloc(InputSectionBase &sec, RelTy &rel,
92
137
                                  bool isLSDA) {
93
137
  Symbol &sym = sec.getFile<ELFT>()->getRelocTargetSym(rel);
94
137
95
137
  // If a symbol is referenced in a live section, it is used.
96
137
  sym.used = true;
97
137
98
137
  if (auto *d = dyn_cast<Defined>(&sym)) {
99
104
    auto *relSec = dyn_cast_or_null<InputSectionBase>(d->section);
100
104
    if (!relSec)
101
4
      return;
102
100
103
100
    uint64_t offset = d->value;
104
100
    if (d->isSection())
105
62
      offset += getAddend<ELFT>(sec, rel);
106
100
107
100
    if (!isLSDA || 
!(relSec->flags & SHF_EXECINSTR)10
)
108
91
      enqueue(relSec, offset);
109
100
    return;
110
100
  }
111
33
112
33
  if (auto *ss = dyn_cast<SharedSymbol>(&sym))
113
19
    if (!ss->isWeak())
114
15
      ss->getFile().isNeeded = true;
115
33
116
33
  for (InputSectionBase *sec : cNamedSections.lookup(sym.getName()))
117
7
    enqueue(sec, 0);
118
33
}
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::resolveReloc<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> const>(lld::elf::InputSectionBase&, llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> const&, bool)
MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::resolveReloc<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> const>(lld::elf::InputSectionBase&, llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> const&, bool)
Line
Count
Source
92
25
                                  bool isLSDA) {
93
25
  Symbol &sym = sec.getFile<ELFT>()->getRelocTargetSym(rel);
94
25
95
25
  // If a symbol is referenced in a live section, it is used.
96
25
  sym.used = true;
97
25
98
25
  if (auto *d = dyn_cast<Defined>(&sym)) {
99
25
    auto *relSec = dyn_cast_or_null<InputSectionBase>(d->section);
100
25
    if (!relSec)
101
0
      return;
102
25
103
25
    uint64_t offset = d->value;
104
25
    if (d->isSection())
105
15
      offset += getAddend<ELFT>(sec, rel);
106
25
107
25
    if (!isLSDA || 
!(relSec->flags & SHF_EXECINSTR)2
)
108
23
      enqueue(relSec, offset);
109
25
    return;
110
25
  }
111
0
112
0
  if (auto *ss = dyn_cast<SharedSymbol>(&sym))
113
0
    if (!ss->isWeak())
114
0
      ss->getFile().isNeeded = true;
115
0
116
0
  for (InputSectionBase *sec : cNamedSections.lookup(sym.getName()))
117
0
    enqueue(sec, 0);
118
0
}
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::resolveReloc<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> const>(lld::elf::InputSectionBase&, llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> const&, bool)
MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::resolveReloc<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> const>(lld::elf::InputSectionBase&, llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> const&, bool)
Line
Count
Source
92
1
                                  bool isLSDA) {
93
1
  Symbol &sym = sec.getFile<ELFT>()->getRelocTargetSym(rel);
94
1
95
1
  // If a symbol is referenced in a live section, it is used.
96
1
  sym.used = true;
97
1
98
1
  if (auto *d = dyn_cast<Defined>(&sym)) {
99
0
    auto *relSec = dyn_cast_or_null<InputSectionBase>(d->section);
100
0
    if (!relSec)
101
0
      return;
102
0
103
0
    uint64_t offset = d->value;
104
0
    if (d->isSection())
105
0
      offset += getAddend<ELFT>(sec, rel);
106
0
107
0
    if (!isLSDA || !(relSec->flags & SHF_EXECINSTR))
108
0
      enqueue(relSec, offset);
109
0
    return;
110
0
  }
111
1
112
1
  if (auto *ss = dyn_cast<SharedSymbol>(&sym))
113
0
    if (!ss->isWeak())
114
0
      ss->getFile().isNeeded = true;
115
1
116
1
  for (InputSectionBase *sec : cNamedSections.lookup(sym.getName()))
117
0
    enqueue(sec, 0);
118
1
}
MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::resolveReloc<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> const>(lld::elf::InputSectionBase&, llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> const&, bool)
Line
Count
Source
92
110
                                  bool isLSDA) {
93
110
  Symbol &sym = sec.getFile<ELFT>()->getRelocTargetSym(rel);
94
110
95
110
  // If a symbol is referenced in a live section, it is used.
96
110
  sym.used = true;
97
110
98
110
  if (auto *d = dyn_cast<Defined>(&sym)) {
99
79
    auto *relSec = dyn_cast_or_null<InputSectionBase>(d->section);
100
79
    if (!relSec)
101
4
      return;
102
75
103
75
    uint64_t offset = d->value;
104
75
    if (d->isSection())
105
47
      offset += getAddend<ELFT>(sec, rel);
106
75
107
75
    if (!isLSDA || 
!(relSec->flags & SHF_EXECINSTR)8
)
108
68
      enqueue(relSec, offset);
109
75
    return;
110
75
  }
111
31
112
31
  if (auto *ss = dyn_cast<SharedSymbol>(&sym))
113
19
    if (!ss->isWeak())
114
15
      ss->getFile().isNeeded = true;
115
31
116
31
  for (InputSectionBase *sec : cNamedSections.lookup(sym.getName()))
117
7
    enqueue(sec, 0);
118
31
}
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::resolveReloc<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> const>(lld::elf::InputSectionBase&, llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> const&, bool)
MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::resolveReloc<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> const>(lld::elf::InputSectionBase&, llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> const&, bool)
Line
Count
Source
92
1
                                  bool isLSDA) {
93
1
  Symbol &sym = sec.getFile<ELFT>()->getRelocTargetSym(rel);
94
1
95
1
  // If a symbol is referenced in a live section, it is used.
96
1
  sym.used = true;
97
1
98
1
  if (auto *d = dyn_cast<Defined>(&sym)) {
99
0
    auto *relSec = dyn_cast_or_null<InputSectionBase>(d->section);
100
0
    if (!relSec)
101
0
      return;
102
0
103
0
    uint64_t offset = d->value;
104
0
    if (d->isSection())
105
0
      offset += getAddend<ELFT>(sec, rel);
106
0
107
0
    if (!isLSDA || !(relSec->flags & SHF_EXECINSTR))
108
0
      enqueue(relSec, offset);
109
0
    return;
110
0
  }
111
1
112
1
  if (auto *ss = dyn_cast<SharedSymbol>(&sym))
113
0
    if (!ss->isWeak())
114
0
      ss->getFile().isNeeded = true;
115
1
116
1
  for (InputSectionBase *sec : cNamedSections.lookup(sym.getName()))
117
0
    enqueue(sec, 0);
118
1
}
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::resolveReloc<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> const>(lld::elf::InputSectionBase&, llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> const&, bool)
119
120
// The .eh_frame section is an unfortunate special case.
121
// The section is divided in CIEs and FDEs and the relocations it can have are
122
// * CIEs can refer to a personality function.
123
// * FDEs can refer to a LSDA
124
// * FDEs refer to the function they contain information about
125
// The last kind of relocation cannot keep the referred section alive, or they
126
// would keep everything alive in a common object file. In fact, each FDE is
127
// alive if the section it refers to is alive.
128
// To keep things simple, in here we just ignore the last relocation kind. The
129
// other two keep the referred section alive.
130
//
131
// A possible improvement would be to fully process .eh_frame in the middle of
132
// the gc pass. With that we would be able to also gc some sections holding
133
// LSDAs and personality functions if we found that they were unused.
134
template <class ELFT>
135
template <class RelTy>
136
void MarkLive<ELFT>::scanEhFrameSection(EhInputSection &eh,
137
7
                                        ArrayRef<RelTy> rels) {
138
23
  for (size_t i = 0, end = eh.pieces.size(); i < end; 
++i16
) {
139
16
    EhSectionPiece &piece = eh.pieces[i];
140
16
    size_t firstRelI = piece.firstRelocation;
141
16
    if (firstRelI == (unsigned)-1)
142
4
      continue;
143
12
144
12
    if (read32<ELFT::TargetEndianness>(piece.data().data() + 4) == 0) {
145
3
      // This is a CIE, we only need to worry about the first relocation. It is
146
3
      // known to point to the personality function.
147
3
      resolveReloc(eh, rels[firstRelI], false);
148
3
      continue;
149
3
    }
150
9
151
9
    // This is a FDE. The relocations point to the described function or to
152
9
    // a LSDA. We only need to keep the LSDA alive, so ignore anything that
153
9
    // points to executable sections.
154
9
    uint64_t pieceEnd = piece.inputOff + piece.size;
155
22
    for (size_t j = firstRelI, end2 = rels.size(); j < end2; 
++j13
)
156
13
      if (rels[j].r_offset < pieceEnd)
157
10
        resolveReloc(eh, rels[j], true);
158
9
  }
159
7
}
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::scanEhFrameSection<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> >(lld::elf::EhInputSection&, llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, true> >)
MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::scanEhFrameSection<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> >(lld::elf::EhInputSection&, llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, false>, false> >)
Line
Count
Source
137
2
                                        ArrayRef<RelTy> rels) {
138
6
  for (size_t i = 0, end = eh.pieces.size(); i < end; 
++i4
) {
139
4
    EhSectionPiece &piece = eh.pieces[i];
140
4
    size_t firstRelI = piece.firstRelocation;
141
4
    if (firstRelI == (unsigned)-1)
142
0
      continue;
143
4
144
4
    if (read32<ELFT::TargetEndianness>(piece.data().data() + 4) == 0) {
145
2
      // This is a CIE, we only need to worry about the first relocation. It is
146
2
      // known to point to the personality function.
147
2
      resolveReloc(eh, rels[firstRelI], false);
148
2
      continue;
149
2
    }
150
2
151
2
    // This is a FDE. The relocations point to the described function or to
152
2
    // a LSDA. We only need to keep the LSDA alive, so ignore anything that
153
2
    // points to executable sections.
154
2
    uint64_t pieceEnd = piece.inputOff + piece.size;
155
4
    for (size_t j = firstRelI, end2 = rels.size(); j < end2; 
++j2
)
156
2
      if (rels[j].r_offset < pieceEnd)
157
2
        resolveReloc(eh, rels[j], true);
158
2
  }
159
2
}
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::scanEhFrameSection<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> >(lld::elf::EhInputSection&, llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, true> >)
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::scanEhFrameSection<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> >(lld::elf::EhInputSection&, llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, false>, false> >)
MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::scanEhFrameSection<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> >(lld::elf::EhInputSection&, llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, true> >)
Line
Count
Source
137
5
                                        ArrayRef<RelTy> rels) {
138
17
  for (size_t i = 0, end = eh.pieces.size(); i < end; 
++i12
) {
139
12
    EhSectionPiece &piece = eh.pieces[i];
140
12
    size_t firstRelI = piece.firstRelocation;
141
12
    if (firstRelI == (unsigned)-1)
142
4
      continue;
143
8
144
8
    if (read32<ELFT::TargetEndianness>(piece.data().data() + 4) == 0) {
145
1
      // This is a CIE, we only need to worry about the first relocation. It is
146
1
      // known to point to the personality function.
147
1
      resolveReloc(eh, rels[firstRelI], false);
148
1
      continue;
149
1
    }
150
7
151
7
    // This is a FDE. The relocations point to the described function or to
152
7
    // a LSDA. We only need to keep the LSDA alive, so ignore anything that
153
7
    // points to executable sections.
154
7
    uint64_t pieceEnd = piece.inputOff + piece.size;
155
18
    for (size_t j = firstRelI, end2 = rels.size(); j < end2; 
++j11
)
156
11
      if (rels[j].r_offset < pieceEnd)
157
8
        resolveReloc(eh, rels[j], true);
158
7
  }
159
5
}
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::scanEhFrameSection<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> >(lld::elf::EhInputSection&, llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)1, true>, false> >)
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::scanEhFrameSection<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> >(lld::elf::EhInputSection&, llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, true> >)
Unexecuted instantiation: MarkLive.cpp:void (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::scanEhFrameSection<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> >(lld::elf::EhInputSection&, llvm::ArrayRef<llvm::object::Elf_Rel_Impl<llvm::object::ELFType<(llvm::support::endianness)0, true>, false> >)
160
161
// Some sections are used directly by the loader, so they should never be
162
// garbage-collected. This function returns true if a given section is such
163
// section.
164
477
static bool isReserved(InputSectionBase *sec) {
165
477
  switch (sec->type) {
166
477
  case SHT_FINI_ARRAY:
167
8
  case SHT_INIT_ARRAY:
168
8
  case SHT_NOTE:
169
8
  case SHT_PREINIT_ARRAY:
170
8
    return true;
171
469
  default:
172
469
    StringRef s = sec->name;
173
469
    return s.startswith(".ctors") || 
s.startswith(".dtors")467
||
174
469
           
s.startswith(".init")465
||
s.startswith(".fini")465
||
175
469
           
s.startswith(".jcr")465
;
176
477
  }
177
477
}
178
179
template <class ELFT>
180
266
void MarkLive<ELFT>::enqueue(InputSectionBase *sec, uint64_t offset) {
181
266
  // Skip over discarded sections. This in theory shouldn't happen, because
182
266
  // the ELF spec doesn't allow a relocation to point to a deduplicated
183
266
  // COMDAT section directly. Unfortunately this happens in practice (e.g.
184
266
  // .eh_frame) so we need to add a check.
185
266
  if (sec == &InputSection::discarded)
186
0
    return;
187
266
188
266
  // Usually, a whole section is marked as live or dead, but in mergeable
189
266
  // (splittable) sections, each piece of data has independent liveness bit.
190
266
  // So we explicitly tell it which offset is in use.
191
266
  if (auto *ms = dyn_cast<MergeInputSection>(sec))
192
9
    ms->getSectionPiece(offset)->live = true;
193
266
194
266
  // Set Sec->Partition to the meet (i.e. the "minimum") of Partition and
195
266
  // Sec->Partition in the following lattice: 1 < other < 0. If Sec->Partition
196
266
  // doesn't change, we don't need to do anything.
197
266
  if (sec->partition == 1 || 
sec->partition == partition213
)
198
56
    return;
199
210
  sec->partition = sec->partition ? 
13
:
partition207
;
200
210
201
210
  // Add input section to the queue.
202
210
  if (InputSection *s = dyn_cast<InputSection>(sec))
203
202
    queue.push_back(s);
204
210
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::enqueue(lld::elf::InputSectionBase*, unsigned long long)
Line
Count
Source
180
43
void MarkLive<ELFT>::enqueue(InputSectionBase *sec, uint64_t offset) {
181
43
  // Skip over discarded sections. This in theory shouldn't happen, because
182
43
  // the ELF spec doesn't allow a relocation to point to a deduplicated
183
43
  // COMDAT section directly. Unfortunately this happens in practice (e.g.
184
43
  // .eh_frame) so we need to add a check.
185
43
  if (sec == &InputSection::discarded)
186
0
    return;
187
43
188
43
  // Usually, a whole section is marked as live or dead, but in mergeable
189
43
  // (splittable) sections, each piece of data has independent liveness bit.
190
43
  // So we explicitly tell it which offset is in use.
191
43
  if (auto *ms = dyn_cast<MergeInputSection>(sec))
192
2
    ms->getSectionPiece(offset)->live = true;
193
43
194
43
  // Set Sec->Partition to the meet (i.e. the "minimum") of Partition and
195
43
  // Sec->Partition in the following lattice: 1 < other < 0. If Sec->Partition
196
43
  // doesn't change, we don't need to do anything.
197
43
  if (sec->partition == 1 || 
sec->partition == partition30
)
198
14
    return;
199
29
  sec->partition = sec->partition ? 
10
: partition;
200
29
201
29
  // Add input section to the queue.
202
29
  if (InputSection *s = dyn_cast<InputSection>(sec))
203
27
    queue.push_back(s);
204
29
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::enqueue(lld::elf::InputSectionBase*, unsigned long long)
Line
Count
Source
180
12
void MarkLive<ELFT>::enqueue(InputSectionBase *sec, uint64_t offset) {
181
12
  // Skip over discarded sections. This in theory shouldn't happen, because
182
12
  // the ELF spec doesn't allow a relocation to point to a deduplicated
183
12
  // COMDAT section directly. Unfortunately this happens in practice (e.g.
184
12
  // .eh_frame) so we need to add a check.
185
12
  if (sec == &InputSection::discarded)
186
0
    return;
187
12
188
12
  // Usually, a whole section is marked as live or dead, but in mergeable
189
12
  // (splittable) sections, each piece of data has independent liveness bit.
190
12
  // So we explicitly tell it which offset is in use.
191
12
  if (auto *ms = dyn_cast<MergeInputSection>(sec))
192
0
    ms->getSectionPiece(offset)->live = true;
193
12
194
12
  // Set Sec->Partition to the meet (i.e. the "minimum") of Partition and
195
12
  // Sec->Partition in the following lattice: 1 < other < 0. If Sec->Partition
196
12
  // doesn't change, we don't need to do anything.
197
12
  if (sec->partition == 1 || 
sec->partition == partition5
)
198
7
    return;
199
5
  sec->partition = sec->partition ? 
10
: partition;
200
5
201
5
  // Add input section to the queue.
202
5
  if (InputSection *s = dyn_cast<InputSection>(sec))
203
5
    queue.push_back(s);
204
5
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::enqueue(lld::elf::InputSectionBase*, unsigned long long)
Line
Count
Source
180
204
void MarkLive<ELFT>::enqueue(InputSectionBase *sec, uint64_t offset) {
181
204
  // Skip over discarded sections. This in theory shouldn't happen, because
182
204
  // the ELF spec doesn't allow a relocation to point to a deduplicated
183
204
  // COMDAT section directly. Unfortunately this happens in practice (e.g.
184
204
  // .eh_frame) so we need to add a check.
185
204
  if (sec == &InputSection::discarded)
186
0
    return;
187
204
188
204
  // Usually, a whole section is marked as live or dead, but in mergeable
189
204
  // (splittable) sections, each piece of data has independent liveness bit.
190
204
  // So we explicitly tell it which offset is in use.
191
204
  if (auto *ms = dyn_cast<MergeInputSection>(sec))
192
7
    ms->getSectionPiece(offset)->live = true;
193
204
194
204
  // Set Sec->Partition to the meet (i.e. the "minimum") of Partition and
195
204
  // Sec->Partition in the following lattice: 1 < other < 0. If Sec->Partition
196
204
  // doesn't change, we don't need to do anything.
197
204
  if (sec->partition == 1 || 
sec->partition == partition175
)
198
31
    return;
199
173
  sec->partition = sec->partition ? 
13
:
partition170
;
200
173
201
173
  // Add input section to the queue.
202
173
  if (InputSection *s = dyn_cast<InputSection>(sec))
203
167
    queue.push_back(s);
204
173
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::enqueue(lld::elf::InputSectionBase*, unsigned long long)
Line
Count
Source
180
7
void MarkLive<ELFT>::enqueue(InputSectionBase *sec, uint64_t offset) {
181
7
  // Skip over discarded sections. This in theory shouldn't happen, because
182
7
  // the ELF spec doesn't allow a relocation to point to a deduplicated
183
7
  // COMDAT section directly. Unfortunately this happens in practice (e.g.
184
7
  // .eh_frame) so we need to add a check.
185
7
  if (sec == &InputSection::discarded)
186
0
    return;
187
7
188
7
  // Usually, a whole section is marked as live or dead, but in mergeable
189
7
  // (splittable) sections, each piece of data has independent liveness bit.
190
7
  // So we explicitly tell it which offset is in use.
191
7
  if (auto *ms = dyn_cast<MergeInputSection>(sec))
192
0
    ms->getSectionPiece(offset)->live = true;
193
7
194
7
  // Set Sec->Partition to the meet (i.e. the "minimum") of Partition and
195
7
  // Sec->Partition in the following lattice: 1 < other < 0. If Sec->Partition
196
7
  // doesn't change, we don't need to do anything.
197
7
  if (sec->partition == 1 || 
sec->partition == partition3
)
198
4
    return;
199
3
  sec->partition = sec->partition ? 
10
: partition;
200
3
201
3
  // Add input section to the queue.
202
3
  if (InputSection *s = dyn_cast<InputSection>(sec))
203
3
    queue.push_back(s);
204
3
}
205
206
399
template <class ELFT> void MarkLive<ELFT>::markSymbol(Symbol *sym) {
207
399
  if (auto *d = dyn_cast_or_null<Defined>(sym))
208
142
    if (auto *isec = dyn_cast_or_null<InputSectionBase>(d->section))
209
138
      enqueue(isec, d->value);
210
399
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::markSymbol(lld::elf::Symbol*)
Line
Count
Source
206
35
template <class ELFT> void MarkLive<ELFT>::markSymbol(Symbol *sym) {
207
35
  if (auto *d = dyn_cast_or_null<Defined>(sym))
208
14
    if (auto *isec = dyn_cast_or_null<InputSectionBase>(d->section))
209
14
      enqueue(isec, d->value);
210
35
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::markSymbol(lld::elf::Symbol*)
Line
Count
Source
206
18
template <class ELFT> void MarkLive<ELFT>::markSymbol(Symbol *sym) {
207
18
  if (auto *d = dyn_cast_or_null<Defined>(sym))
208
12
    if (auto *isec = dyn_cast_or_null<InputSectionBase>(d->section))
209
12
      enqueue(isec, d->value);
210
18
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::markSymbol(lld::elf::Symbol*)
Line
Count
Source
206
336
template <class ELFT> void MarkLive<ELFT>::markSymbol(Symbol *sym) {
207
336
  if (auto *d = dyn_cast_or_null<Defined>(sym))
208
109
    if (auto *isec = dyn_cast_or_null<InputSectionBase>(d->section))
209
105
      enqueue(isec, d->value);
210
336
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::markSymbol(lld::elf::Symbol*)
Line
Count
Source
206
10
template <class ELFT> void MarkLive<ELFT>::markSymbol(Symbol *sym) {
207
10
  if (auto *d = dyn_cast_or_null<Defined>(sym))
208
7
    if (auto *isec = dyn_cast_or_null<InputSectionBase>(d->section))
209
7
      enqueue(isec, d->value);
210
10
}
211
212
// This is the main function of the garbage collector.
213
// Starting from GC-root sections, this function visits all reachable
214
// sections to set their "Live" bits.
215
103
template <class ELFT> void MarkLive<ELFT>::run() {
216
103
  // Add GC root symbols.
217
103
218
103
  // Preserve externally-visible symbols if the symbols defined by this
219
103
  // file can interrupt other ELF file's symbols at runtime.
220
285
  symtab->forEachSymbol([&](Symbol *sym) {
221
285
    if (sym->includeInDynsym() && 
sym->partition == partition158
)
222
115
      markSymbol(sym);
223
285
  });
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::run()::'lambda'(lld::elf::Symbol*)::operator()(lld::elf::Symbol*) const
Line
Count
Source
220
31
  symtab->forEachSymbol([&](Symbol *sym) {
221
31
    if (sym->includeInDynsym() && 
sym->partition == partition18
)
222
8
      markSymbol(sym);
223
31
  });
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::run()::'lambda'(lld::elf::Symbol*)::operator()(lld::elf::Symbol*) const
Line
Count
Source
220
14
  symtab->forEachSymbol([&](Symbol *sym) {
221
14
    if (sym->includeInDynsym() && 
sym->partition == partition12
)
222
12
      markSymbol(sym);
223
14
  });
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::run()::'lambda'(lld::elf::Symbol*)::operator()(lld::elf::Symbol*) const
Line
Count
Source
220
232
  symtab->forEachSymbol([&](Symbol *sym) {
221
232
    if (sym->includeInDynsym() && 
sym->partition == partition121
)
222
88
      markSymbol(sym);
223
232
  });
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::run()::'lambda'(lld::elf::Symbol*)::operator()(lld::elf::Symbol*) const
Line
Count
Source
220
8
  symtab->forEachSymbol([&](Symbol *sym) {
221
8
    if (sym->includeInDynsym() && 
sym->partition == partition7
)
222
7
      markSymbol(sym);
223
8
  });
224
103
225
103
  // If this isn't the main partition, that's all that we need to preserve.
226
103
  if (partition != 1) {
227
11
    mark();
228
11
    return;
229
11
  }
230
92
231
92
  markSymbol(symtab->find(config->entry));
232
92
  markSymbol(symtab->find(config->init));
233
92
  markSymbol(symtab->find(config->fini));
234
92
  for (StringRef s : config->undefined)
235
3
    markSymbol(symtab->find(s));
236
92
  for (StringRef s : script->referencedSymbols)
237
1
    markSymbol(symtab->find(s));
238
92
239
92
  // Preserve special sections and those which are specified in linker
240
92
  // script KEEP command.
241
495
  for (InputSectionBase *sec : inputSections) {
242
495
    // Mark .eh_frame sections as live because there are usually no relocations
243
495
    // that point to .eh_frames. Otherwise, the garbage collector would drop
244
495
    // all of them. We also want to preserve personality routines and LSDA
245
495
    // referenced by .eh_frame sections, so we scan them for that here.
246
495
    if (auto *eh = dyn_cast<EhInputSection>(sec)) {
247
9
      eh->markLive();
248
9
      if (!eh->numRelocations)
249
2
        continue;
250
7
251
7
      if (eh->areRelocsRela)
252
5
        scanEhFrameSection(*eh, eh->template relas<ELFT>());
253
2
      else
254
2
        scanEhFrameSection(*eh, eh->template rels<ELFT>());
255
7
    }
256
495
257
495
    
if (493
sec->flags & SHF_LINK_ORDER493
)
258
16
      continue;
259
477
260
477
    if (isReserved(sec) || 
script->shouldKeep(sec)465
) {
261
16
      enqueue(sec, 0);
262
461
    } else if (isValidCIdentifier(sec->name)) {
263
18
      cNamedSections[saver.save("__start_" + sec->name)].push_back(sec);
264
18
      cNamedSections[saver.save("__stop_" + sec->name)].push_back(sec);
265
18
    }
266
477
  }
267
92
268
92
  mark();
269
92
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::run()
Line
Count
Source
215
12
template <class ELFT> void MarkLive<ELFT>::run() {
216
12
  // Add GC root symbols.
217
12
218
12
  // Preserve externally-visible symbols if the symbols defined by this
219
12
  // file can interrupt other ELF file's symbols at runtime.
220
12
  symtab->forEachSymbol([&](Symbol *sym) {
221
12
    if (sym->includeInDynsym() && sym->partition == partition)
222
12
      markSymbol(sym);
223
12
  });
224
12
225
12
  // If this isn't the main partition, that's all that we need to preserve.
226
12
  if (partition != 1) {
227
3
    mark();
228
3
    return;
229
3
  }
230
9
231
9
  markSymbol(symtab->find(config->entry));
232
9
  markSymbol(symtab->find(config->init));
233
9
  markSymbol(symtab->find(config->fini));
234
9
  for (StringRef s : config->undefined)
235
0
    markSymbol(symtab->find(s));
236
9
  for (StringRef s : script->referencedSymbols)
237
0
    markSymbol(symtab->find(s));
238
9
239
9
  // Preserve special sections and those which are specified in linker
240
9
  // script KEEP command.
241
54
  for (InputSectionBase *sec : inputSections) {
242
54
    // Mark .eh_frame sections as live because there are usually no relocations
243
54
    // that point to .eh_frames. Otherwise, the garbage collector would drop
244
54
    // all of them. We also want to preserve personality routines and LSDA
245
54
    // referenced by .eh_frame sections, so we scan them for that here.
246
54
    if (auto *eh = dyn_cast<EhInputSection>(sec)) {
247
2
      eh->markLive();
248
2
      if (!eh->numRelocations)
249
0
        continue;
250
2
251
2
      if (eh->areRelocsRela)
252
0
        scanEhFrameSection(*eh, eh->template relas<ELFT>());
253
2
      else
254
2
        scanEhFrameSection(*eh, eh->template rels<ELFT>());
255
2
    }
256
54
257
54
    if (sec->flags & SHF_LINK_ORDER)
258
9
      continue;
259
45
260
45
    if (isReserved(sec) || script->shouldKeep(sec)) {
261
0
      enqueue(sec, 0);
262
45
    } else if (isValidCIdentifier(sec->name)) {
263
0
      cNamedSections[saver.save("__start_" + sec->name)].push_back(sec);
264
0
      cNamedSections[saver.save("__stop_" + sec->name)].push_back(sec);
265
0
    }
266
45
  }
267
9
268
9
  mark();
269
9
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::run()
Line
Count
Source
215
2
template <class ELFT> void MarkLive<ELFT>::run() {
216
2
  // Add GC root symbols.
217
2
218
2
  // Preserve externally-visible symbols if the symbols defined by this
219
2
  // file can interrupt other ELF file's symbols at runtime.
220
2
  symtab->forEachSymbol([&](Symbol *sym) {
221
2
    if (sym->includeInDynsym() && sym->partition == partition)
222
2
      markSymbol(sym);
223
2
  });
224
2
225
2
  // If this isn't the main partition, that's all that we need to preserve.
226
2
  if (partition != 1) {
227
0
    mark();
228
0
    return;
229
0
  }
230
2
231
2
  markSymbol(symtab->find(config->entry));
232
2
  markSymbol(symtab->find(config->init));
233
2
  markSymbol(symtab->find(config->fini));
234
2
  for (StringRef s : config->undefined)
235
0
    markSymbol(symtab->find(s));
236
2
  for (StringRef s : script->referencedSymbols)
237
0
    markSymbol(symtab->find(s));
238
2
239
2
  // Preserve special sections and those which are specified in linker
240
2
  // script KEEP command.
241
17
  for (InputSectionBase *sec : inputSections) {
242
17
    // Mark .eh_frame sections as live because there are usually no relocations
243
17
    // that point to .eh_frames. Otherwise, the garbage collector would drop
244
17
    // all of them. We also want to preserve personality routines and LSDA
245
17
    // referenced by .eh_frame sections, so we scan them for that here.
246
17
    if (auto *eh = dyn_cast<EhInputSection>(sec)) {
247
0
      eh->markLive();
248
0
      if (!eh->numRelocations)
249
0
        continue;
250
0
251
0
      if (eh->areRelocsRela)
252
0
        scanEhFrameSection(*eh, eh->template relas<ELFT>());
253
0
      else
254
0
        scanEhFrameSection(*eh, eh->template rels<ELFT>());
255
0
    }
256
17
257
17
    if (sec->flags & SHF_LINK_ORDER)
258
0
      continue;
259
17
260
17
    if (isReserved(sec) || script->shouldKeep(sec)) {
261
0
      enqueue(sec, 0);
262
17
    } else if (isValidCIdentifier(sec->name)) {
263
0
      cNamedSections[saver.save("__start_" + sec->name)].push_back(sec);
264
0
      cNamedSections[saver.save("__stop_" + sec->name)].push_back(sec);
265
0
    }
266
17
  }
267
2
268
2
  mark();
269
2
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::run()
Line
Count
Source
215
88
template <class ELFT> void MarkLive<ELFT>::run() {
216
88
  // Add GC root symbols.
217
88
218
88
  // Preserve externally-visible symbols if the symbols defined by this
219
88
  // file can interrupt other ELF file's symbols at runtime.
220
88
  symtab->forEachSymbol([&](Symbol *sym) {
221
88
    if (sym->includeInDynsym() && sym->partition == partition)
222
88
      markSymbol(sym);
223
88
  });
224
88
225
88
  // If this isn't the main partition, that's all that we need to preserve.
226
88
  if (partition != 1) {
227
8
    mark();
228
8
    return;
229
8
  }
230
80
231
80
  markSymbol(symtab->find(config->entry));
232
80
  markSymbol(symtab->find(config->init));
233
80
  markSymbol(symtab->find(config->fini));
234
80
  for (StringRef s : config->undefined)
235
3
    markSymbol(symtab->find(s));
236
80
  for (StringRef s : script->referencedSymbols)
237
1
    markSymbol(symtab->find(s));
238
80
239
80
  // Preserve special sections and those which are specified in linker
240
80
  // script KEEP command.
241
413
  for (InputSectionBase *sec : inputSections) {
242
413
    // Mark .eh_frame sections as live because there are usually no relocations
243
413
    // that point to .eh_frames. Otherwise, the garbage collector would drop
244
413
    // all of them. We also want to preserve personality routines and LSDA
245
413
    // referenced by .eh_frame sections, so we scan them for that here.
246
413
    if (auto *eh = dyn_cast<EhInputSection>(sec)) {
247
7
      eh->markLive();
248
7
      if (!eh->numRelocations)
249
2
        continue;
250
5
251
5
      if (eh->areRelocsRela)
252
5
        scanEhFrameSection(*eh, eh->template relas<ELFT>());
253
0
      else
254
0
        scanEhFrameSection(*eh, eh->template rels<ELFT>());
255
5
    }
256
413
257
413
    
if (411
sec->flags & SHF_LINK_ORDER411
)
258
7
      continue;
259
404
260
404
    if (isReserved(sec) || 
script->shouldKeep(sec)392
) {
261
16
      enqueue(sec, 0);
262
388
    } else if (isValidCIdentifier(sec->name)) {
263
18
      cNamedSections[saver.save("__start_" + sec->name)].push_back(sec);
264
18
      cNamedSections[saver.save("__stop_" + sec->name)].push_back(sec);
265
18
    }
266
404
  }
267
80
268
80
  mark();
269
80
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::run()
Line
Count
Source
215
1
template <class ELFT> void MarkLive<ELFT>::run() {
216
1
  // Add GC root symbols.
217
1
218
1
  // Preserve externally-visible symbols if the symbols defined by this
219
1
  // file can interrupt other ELF file's symbols at runtime.
220
1
  symtab->forEachSymbol([&](Symbol *sym) {
221
1
    if (sym->includeInDynsym() && sym->partition == partition)
222
1
      markSymbol(sym);
223
1
  });
224
1
225
1
  // If this isn't the main partition, that's all that we need to preserve.
226
1
  if (partition != 1) {
227
0
    mark();
228
0
    return;
229
0
  }
230
1
231
1
  markSymbol(symtab->find(config->entry));
232
1
  markSymbol(symtab->find(config->init));
233
1
  markSymbol(symtab->find(config->fini));
234
1
  for (StringRef s : config->undefined)
235
0
    markSymbol(symtab->find(s));
236
1
  for (StringRef s : script->referencedSymbols)
237
0
    markSymbol(symtab->find(s));
238
1
239
1
  // Preserve special sections and those which are specified in linker
240
1
  // script KEEP command.
241
11
  for (InputSectionBase *sec : inputSections) {
242
11
    // Mark .eh_frame sections as live because there are usually no relocations
243
11
    // that point to .eh_frames. Otherwise, the garbage collector would drop
244
11
    // all of them. We also want to preserve personality routines and LSDA
245
11
    // referenced by .eh_frame sections, so we scan them for that here.
246
11
    if (auto *eh = dyn_cast<EhInputSection>(sec)) {
247
0
      eh->markLive();
248
0
      if (!eh->numRelocations)
249
0
        continue;
250
0
251
0
      if (eh->areRelocsRela)
252
0
        scanEhFrameSection(*eh, eh->template relas<ELFT>());
253
0
      else
254
0
        scanEhFrameSection(*eh, eh->template rels<ELFT>());
255
0
    }
256
11
257
11
    if (sec->flags & SHF_LINK_ORDER)
258
0
      continue;
259
11
260
11
    if (isReserved(sec) || script->shouldKeep(sec)) {
261
0
      enqueue(sec, 0);
262
11
    } else if (isValidCIdentifier(sec->name)) {
263
0
      cNamedSections[saver.save("__start_" + sec->name)].push_back(sec);
264
0
      cNamedSections[saver.save("__stop_" + sec->name)].push_back(sec);
265
0
    }
266
11
  }
267
1
268
1
  mark();
269
1
}
270
271
111
template <class ELFT> void MarkLive<ELFT>::mark() {
272
111
  // Mark all reachable sections.
273
313
  while (!queue.empty()) {
274
202
    InputSectionBase &sec = *queue.pop_back_val();
275
202
276
202
    if (sec.areRelocsRela) {
277
73
      for (const typename ELFT::Rela &rel : sec.template relas<ELFT>())
278
102
        resolveReloc(sec, rel, false);
279
129
    } else {
280
129
      for (const typename ELFT::Rel &rel : sec.template rels<ELFT>())
281
22
        resolveReloc(sec, rel, false);
282
129
    }
283
202
284
202
    for (InputSectionBase *isec : sec.dependentSections)
285
14
      enqueue(isec, 0);
286
202
  }
287
111
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::mark()
Line
Count
Source
271
14
template <class ELFT> void MarkLive<ELFT>::mark() {
272
14
  // Mark all reachable sections.
273
41
  while (!queue.empty()) {
274
27
    InputSectionBase &sec = *queue.pop_back_val();
275
27
276
27
    if (sec.areRelocsRela) {
277
0
      for (const typename ELFT::Rela &rel : sec.template relas<ELFT>())
278
0
        resolveReloc(sec, rel, false);
279
27
    } else {
280
27
      for (const typename ELFT::Rel &rel : sec.template rels<ELFT>())
281
21
        resolveReloc(sec, rel, false);
282
27
    }
283
27
284
27
    for (InputSectionBase *isec : sec.dependentSections)
285
6
      enqueue(isec, 0);
286
27
  }
287
14
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::mark()
Line
Count
Source
271
2
template <class ELFT> void MarkLive<ELFT>::mark() {
272
2
  // Mark all reachable sections.
273
7
  while (!queue.empty()) {
274
5
    InputSectionBase &sec = *queue.pop_back_val();
275
5
276
5
    if (sec.areRelocsRela) {
277
0
      for (const typename ELFT::Rela &rel : sec.template relas<ELFT>())
278
0
        resolveReloc(sec, rel, false);
279
5
    } else {
280
5
      for (const typename ELFT::Rel &rel : sec.template rels<ELFT>())
281
1
        resolveReloc(sec, rel, false);
282
5
    }
283
5
284
5
    for (InputSectionBase *isec : sec.dependentSections)
285
0
      enqueue(isec, 0);
286
5
  }
287
2
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::mark()
Line
Count
Source
271
94
template <class ELFT> void MarkLive<ELFT>::mark() {
272
94
  // Mark all reachable sections.
273
261
  while (!queue.empty()) {
274
167
    InputSectionBase &sec = *queue.pop_back_val();
275
167
276
167
    if (sec.areRelocsRela) {
277
72
      for (const typename ELFT::Rela &rel : sec.template relas<ELFT>())
278
101
        resolveReloc(sec, rel, false);
279
95
    } else {
280
95
      for (const typename ELFT::Rel &rel : sec.template rels<ELFT>())
281
0
        resolveReloc(sec, rel, false);
282
95
    }
283
167
284
167
    for (InputSectionBase *isec : sec.dependentSections)
285
8
      enqueue(isec, 0);
286
167
  }
287
94
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::mark()
Line
Count
Source
271
1
template <class ELFT> void MarkLive<ELFT>::mark() {
272
1
  // Mark all reachable sections.
273
4
  while (!queue.empty()) {
274
3
    InputSectionBase &sec = *queue.pop_back_val();
275
3
276
3
    if (sec.areRelocsRela) {
277
1
      for (const typename ELFT::Rela &rel : sec.template relas<ELFT>())
278
1
        resolveReloc(sec, rel, false);
279
2
    } else {
280
2
      for (const typename ELFT::Rel &rel : sec.template rels<ELFT>())
281
0
        resolveReloc(sec, rel, false);
282
2
    }
283
3
284
3
    for (InputSectionBase *isec : sec.dependentSections)
285
0
      enqueue(isec, 0);
286
3
  }
287
1
}
288
289
// Move the sections for some symbols to the main partition, specifically ifuncs
290
// (because they can result in an IRELATIVE being added to the main partition's
291
// GOT, which means that the ifunc must be available when the main partition is
292
// loaded) and TLS symbols (because we only know how to correctly process TLS
293
// relocations for the main partition).
294
8
template <class ELFT> void MarkLive<ELFT>::moveToMain() {
295
8
  for (InputFile *file : objectFiles)
296
8
    for (Symbol *s : file->getSymbols())
297
63
      if (auto *d = dyn_cast<Defined>(s))
298
51
        if ((d->type == STT_GNU_IFUNC || 
d->type == STT_TLS49
) &&
d->section4
&&
299
51
            
d->section->isLive()4
)
300
4
          markSymbol(s);
301
8
302
8
  mark();
303
8
}
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >::moveToMain()
Line
Count
Source
294
2
template <class ELFT> void MarkLive<ELFT>::moveToMain() {
295
2
  for (InputFile *file : objectFiles)
296
2
    for (Symbol *s : file->getSymbols())
297
18
      if (auto *d = dyn_cast<Defined>(s))
298
16
        if ((d->type == STT_GNU_IFUNC || d->type == STT_TLS) && 
d->section0
&&
299
16
            
d->section->isLive()0
)
300
0
          markSymbol(s);
301
2
302
2
  mark();
303
2
}
Unexecuted instantiation: MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >::moveToMain()
MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >::moveToMain()
Line
Count
Source
294
6
template <class ELFT> void MarkLive<ELFT>::moveToMain() {
295
6
  for (InputFile *file : objectFiles)
296
6
    for (Symbol *s : file->getSymbols())
297
45
      if (auto *d = dyn_cast<Defined>(s))
298
35
        if ((d->type == STT_GNU_IFUNC || 
d->type == STT_TLS33
) &&
d->section4
&&
299
35
            
d->section->isLive()4
)
300
4
          markSymbol(s);
301
6
302
6
  mark();
303
6
}
Unexecuted instantiation: MarkLive.cpp:(anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >::moveToMain()
304
305
// Before calling this function, Live bits are off for all
306
// input sections. This function make some or all of them on
307
// so that they are emitted to the output file.
308
2.75k
template <class ELFT> void elf::markLive() {
309
2.75k
  // If -gc-sections is not given, no sections are removed.
310
2.75k
  if (!config->gcSections) {
311
2.66k
    for (InputSectionBase *sec : inputSections)
312
339k
      sec->markLive();
313
2.66k
314
2.66k
    // If a DSO defines a symbol referenced in a regular object, it is needed.
315
16.7k
    symtab->forEachSymbol([](Symbol *sym) {
316
16.7k
      if (auto *s = dyn_cast<SharedSymbol>(sym))
317
765
        if (s->isUsedInRegularObj && 
!s->isWeak()409
)
318
388
          s->getFile().isNeeded = true;
319
16.7k
    });
void lld::elf::markLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >()::'lambda'(lld::elf::Symbol*)::operator()(lld::elf::Symbol*) const
Line
Count
Source
315
1.21k
    symtab->forEachSymbol([](Symbol *sym) {
316
1.21k
      if (auto *s = dyn_cast<SharedSymbol>(sym))
317
122
        if (s->isUsedInRegularObj && 
!s->isWeak()82
)
318
75
          s->getFile().isNeeded = true;
319
1.21k
    });
void lld::elf::markLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >()::'lambda'(lld::elf::Symbol*)::operator()(lld::elf::Symbol*) const
Line
Count
Source
315
588
    symtab->forEachSymbol([](Symbol *sym) {
316
588
      if (auto *s = dyn_cast<SharedSymbol>(sym))
317
107
        if (s->isUsedInRegularObj && 
!s->isWeak()38
)
318
38
          s->getFile().isNeeded = true;
319
588
    });
void lld::elf::markLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >()::'lambda'(lld::elf::Symbol*)::operator()(lld::elf::Symbol*) const
Line
Count
Source
315
4.64k
    symtab->forEachSymbol([](Symbol *sym) {
316
4.64k
      if (auto *s = dyn_cast<SharedSymbol>(sym))
317
508
        if (s->isUsedInRegularObj && 
!s->isWeak()274
)
318
260
          s->getFile().isNeeded = true;
319
4.64k
    });
void lld::elf::markLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >()::'lambda'(lld::elf::Symbol*)::operator()(lld::elf::Symbol*) const
Line
Count
Source
315
10.3k
    symtab->forEachSymbol([](Symbol *sym) {
316
10.3k
      if (auto *s = dyn_cast<SharedSymbol>(sym))
317
28
        if (s->isUsedInRegularObj && 
!s->isWeak()15
)
318
15
          s->getFile().isNeeded = true;
319
10.3k
    });
320
2.66k
    return;
321
2.66k
  }
322
92
323
92
  // Otheriwse, do mark-sweep GC.
324
92
  //
325
92
  // The -gc-sections option works only for SHF_ALLOC sections
326
92
  // (sections that are memory-mapped at runtime). So we can
327
92
  // unconditionally make non-SHF_ALLOC sections alive except
328
92
  // SHF_LINK_ORDER and SHT_REL/SHT_RELA sections.
329
92
  //
330
92
  // Usually, non-SHF_ALLOC sections are not removed even if they are
331
92
  // unreachable through relocations because reachability is not
332
92
  // a good signal whether they are garbage or not (e.g. there is
333
92
  // usually no section referring to a .comment section, but we
334
92
  // want to keep it.).
335
92
  //
336
92
  // Note on SHF_LINK_ORDER: Such sections contain metadata and they
337
92
  // have a reverse dependency on the InputSection they are linked with.
338
92
  // We are able to garbage collect them.
339
92
  //
340
92
  // Note on SHF_REL{,A}: Such sections reach here only when -r
341
92
  // or -emit-reloc were given. And they are subject of garbage
342
92
  // collection because, if we remove a text section, we also
343
92
  // remove its relocation section.
344
495
  
for (InputSectionBase *sec : inputSections)92
{
345
495
    bool isAlloc = (sec->flags & SHF_ALLOC);
346
495
    bool isLinkOrder = (sec->flags & SHF_LINK_ORDER);
347
495
    bool isRel = (sec->type == SHT_REL || sec->type == SHT_RELA);
348
495
349
495
    if (!isAlloc && 
!isLinkOrder132
&&
!isRel130
)
350
124
      sec->markLive();
351
495
  }
352
92
353
92
  // Follow the graph to mark all live sections.
354
195
  for (unsigned curPart = 1; curPart <= partitions.size(); 
++curPart103
)
355
103
    MarkLive<ELFT>(curPart).run();
356
92
357
92
  // If we have multiple partitions, some sections need to live in the main
358
92
  // partition even if they were allocated to a loadable partition. Move them
359
92
  // there now.
360
92
  if (partitions.size() != 1)
361
8
    MarkLive<ELFT>(1).moveToMain();
362
92
363
92
  // Report garbage-collected sections.
364
92
  if (config->printGcSections)
365
6
    for (InputSectionBase *sec : inputSections)
366
28
      if (!sec->isLive())
367
16
        message("removing unused section " + toString(sec));
368
92
}
void lld::elf::markLive<llvm::object::ELFType<(llvm::support::endianness)1, false> >()
Line
Count
Source
308
376
template <class ELFT> void elf::markLive() {
309
376
  // If -gc-sections is not given, no sections are removed.
310
376
  if (!config->gcSections) {
311
367
    for (InputSectionBase *sec : inputSections)
312
1.68k
      sec->markLive();
313
367
314
367
    // If a DSO defines a symbol referenced in a regular object, it is needed.
315
367
    symtab->forEachSymbol([](Symbol *sym) {
316
367
      if (auto *s = dyn_cast<SharedSymbol>(sym))
317
367
        if (s->isUsedInRegularObj && !s->isWeak())
318
367
          s->getFile().isNeeded = true;
319
367
    });
320
367
    return;
321
367
  }
322
9
323
9
  // Otheriwse, do mark-sweep GC.
324
9
  //
325
9
  // The -gc-sections option works only for SHF_ALLOC sections
326
9
  // (sections that are memory-mapped at runtime). So we can
327
9
  // unconditionally make non-SHF_ALLOC sections alive except
328
9
  // SHF_LINK_ORDER and SHT_REL/SHT_RELA sections.
329
9
  //
330
9
  // Usually, non-SHF_ALLOC sections are not removed even if they are
331
9
  // unreachable through relocations because reachability is not
332
9
  // a good signal whether they are garbage or not (e.g. there is
333
9
  // usually no section referring to a .comment section, but we
334
9
  // want to keep it.).
335
9
  //
336
9
  // Note on SHF_LINK_ORDER: Such sections contain metadata and they
337
9
  // have a reverse dependency on the InputSection they are linked with.
338
9
  // We are able to garbage collect them.
339
9
  //
340
9
  // Note on SHF_REL{,A}: Such sections reach here only when -r
341
9
  // or -emit-reloc were given. And they are subject of garbage
342
9
  // collection because, if we remove a text section, we also
343
9
  // remove its relocation section.
344
54
  
for (InputSectionBase *sec : inputSections)9
{
345
54
    bool isAlloc = (sec->flags & SHF_ALLOC);
346
54
    bool isLinkOrder = (sec->flags & SHF_LINK_ORDER);
347
54
    bool isRel = (sec->type == SHT_REL || sec->type == SHT_RELA);
348
54
349
54
    if (!isAlloc && 
!isLinkOrder12
&&
!isRel12
)
350
12
      sec->markLive();
351
54
  }
352
9
353
9
  // Follow the graph to mark all live sections.
354
21
  for (unsigned curPart = 1; curPart <= partitions.size(); 
++curPart12
)
355
12
    MarkLive<ELFT>(curPart).run();
356
9
357
9
  // If we have multiple partitions, some sections need to live in the main
358
9
  // partition even if they were allocated to a loadable partition. Move them
359
9
  // there now.
360
9
  if (partitions.size() != 1)
361
2
    MarkLive<ELFT>(1).moveToMain();
362
9
363
9
  // Report garbage-collected sections.
364
9
  if (config->printGcSections)
365
0
    for (InputSectionBase *sec : inputSections)
366
0
      if (!sec->isLive())
367
0
        message("removing unused section " + toString(sec));
368
9
}
void lld::elf::markLive<llvm::object::ELFType<(llvm::support::endianness)0, false> >()
Line
Count
Source
308
157
template <class ELFT> void elf::markLive() {
309
157
  // If -gc-sections is not given, no sections are removed.
310
157
  if (!config->gcSections) {
311
155
    for (InputSectionBase *sec : inputSections)
312
1.09k
      sec->markLive();
313
155
314
155
    // If a DSO defines a symbol referenced in a regular object, it is needed.
315
155
    symtab->forEachSymbol([](Symbol *sym) {
316
155
      if (auto *s = dyn_cast<SharedSymbol>(sym))
317
155
        if (s->isUsedInRegularObj && !s->isWeak())
318
155
          s->getFile().isNeeded = true;
319
155
    });
320
155
    return;
321
155
  }
322
2
323
2
  // Otheriwse, do mark-sweep GC.
324
2
  //
325
2
  // The -gc-sections option works only for SHF_ALLOC sections
326
2
  // (sections that are memory-mapped at runtime). So we can
327
2
  // unconditionally make non-SHF_ALLOC sections alive except
328
2
  // SHF_LINK_ORDER and SHT_REL/SHT_RELA sections.
329
2
  //
330
2
  // Usually, non-SHF_ALLOC sections are not removed even if they are
331
2
  // unreachable through relocations because reachability is not
332
2
  // a good signal whether they are garbage or not (e.g. there is
333
2
  // usually no section referring to a .comment section, but we
334
2
  // want to keep it.).
335
2
  //
336
2
  // Note on SHF_LINK_ORDER: Such sections contain metadata and they
337
2
  // have a reverse dependency on the InputSection they are linked with.
338
2
  // We are able to garbage collect them.
339
2
  //
340
2
  // Note on SHF_REL{,A}: Such sections reach here only when -r
341
2
  // or -emit-reloc were given. And they are subject of garbage
342
2
  // collection because, if we remove a text section, we also
343
2
  // remove its relocation section.
344
17
  
for (InputSectionBase *sec : inputSections)2
{
345
17
    bool isAlloc = (sec->flags & SHF_ALLOC);
346
17
    bool isLinkOrder = (sec->flags & SHF_LINK_ORDER);
347
17
    bool isRel = (sec->type == SHT_REL || sec->type == SHT_RELA);
348
17
349
17
    if (!isAlloc && 
!isLinkOrder2
&&
!isRel2
)
350
2
      sec->markLive();
351
17
  }
352
2
353
2
  // Follow the graph to mark all live sections.
354
4
  for (unsigned curPart = 1; curPart <= partitions.size(); 
++curPart2
)
355
2
    MarkLive<ELFT>(curPart).run();
356
2
357
2
  // If we have multiple partitions, some sections need to live in the main
358
2
  // partition even if they were allocated to a loadable partition. Move them
359
2
  // there now.
360
2
  if (partitions.size() != 1)
361
0
    MarkLive<ELFT>(1).moveToMain();
362
2
363
2
  // Report garbage-collected sections.
364
2
  if (config->printGcSections)
365
0
    for (InputSectionBase *sec : inputSections)
366
0
      if (!sec->isLive())
367
0
        message("removing unused section " + toString(sec));
368
2
}
void lld::elf::markLive<llvm::object::ELFType<(llvm::support::endianness)1, true> >()
Line
Count
Source
308
2.11k
template <class ELFT> void elf::markLive() {
309
2.11k
  // If -gc-sections is not given, no sections are removed.
310
2.11k
  if (!config->gcSections) {
311
2.03k
    for (InputSectionBase *sec : inputSections)
312
336k
      sec->markLive();
313
2.03k
314
2.03k
    // If a DSO defines a symbol referenced in a regular object, it is needed.
315
2.03k
    symtab->forEachSymbol([](Symbol *sym) {
316
2.03k
      if (auto *s = dyn_cast<SharedSymbol>(sym))
317
2.03k
        if (s->isUsedInRegularObj && !s->isWeak())
318
2.03k
          s->getFile().isNeeded = true;
319
2.03k
    });
320
2.03k
    return;
321
2.03k
  }
322
80
323
80
  // Otheriwse, do mark-sweep GC.
324
80
  //
325
80
  // The -gc-sections option works only for SHF_ALLOC sections
326
80
  // (sections that are memory-mapped at runtime). So we can
327
80
  // unconditionally make non-SHF_ALLOC sections alive except
328
80
  // SHF_LINK_ORDER and SHT_REL/SHT_RELA sections.
329
80
  //
330
80
  // Usually, non-SHF_ALLOC sections are not removed even if they are
331
80
  // unreachable through relocations because reachability is not
332
80
  // a good signal whether they are garbage or not (e.g. there is
333
80
  // usually no section referring to a .comment section, but we
334
80
  // want to keep it.).
335
80
  //
336
80
  // Note on SHF_LINK_ORDER: Such sections contain metadata and they
337
80
  // have a reverse dependency on the InputSection they are linked with.
338
80
  // We are able to garbage collect them.
339
80
  //
340
80
  // Note on SHF_REL{,A}: Such sections reach here only when -r
341
80
  // or -emit-reloc were given. And they are subject of garbage
342
80
  // collection because, if we remove a text section, we also
343
80
  // remove its relocation section.
344
413
  
for (InputSectionBase *sec : inputSections)80
{
345
413
    bool isAlloc = (sec->flags & SHF_ALLOC);
346
413
    bool isLinkOrder = (sec->flags & SHF_LINK_ORDER);
347
413
    bool isRel = (sec->type == SHT_REL || sec->type == SHT_RELA);
348
413
349
413
    if (!isAlloc && 
!isLinkOrder117
&&
!isRel115
)
350
109
      sec->markLive();
351
413
  }
352
80
353
80
  // Follow the graph to mark all live sections.
354
168
  for (unsigned curPart = 1; curPart <= partitions.size(); 
++curPart88
)
355
88
    MarkLive<ELFT>(curPart).run();
356
80
357
80
  // If we have multiple partitions, some sections need to live in the main
358
80
  // partition even if they were allocated to a loadable partition. Move them
359
80
  // there now.
360
80
  if (partitions.size() != 1)
361
6
    MarkLive<ELFT>(1).moveToMain();
362
80
363
80
  // Report garbage-collected sections.
364
80
  if (config->printGcSections)
365
6
    for (InputSectionBase *sec : inputSections)
366
28
      if (!sec->isLive())
367
16
        message("removing unused section " + toString(sec));
368
80
}
void lld::elf::markLive<llvm::object::ELFType<(llvm::support::endianness)0, true> >()
Line
Count
Source
308
108
template <class ELFT> void elf::markLive() {
309
108
  // If -gc-sections is not given, no sections are removed.
310
108
  if (!config->gcSections) {
311
107
    for (InputSectionBase *sec : inputSections)
312
501
      sec->markLive();
313
107
314
107
    // If a DSO defines a symbol referenced in a regular object, it is needed.
315
107
    symtab->forEachSymbol([](Symbol *sym) {
316
107
      if (auto *s = dyn_cast<SharedSymbol>(sym))
317
107
        if (s->isUsedInRegularObj && !s->isWeak())
318
107
          s->getFile().isNeeded = true;
319
107
    });
320
107
    return;
321
107
  }
322
1
323
1
  // Otheriwse, do mark-sweep GC.
324
1
  //
325
1
  // The -gc-sections option works only for SHF_ALLOC sections
326
1
  // (sections that are memory-mapped at runtime). So we can
327
1
  // unconditionally make non-SHF_ALLOC sections alive except
328
1
  // SHF_LINK_ORDER and SHT_REL/SHT_RELA sections.
329
1
  //
330
1
  // Usually, non-SHF_ALLOC sections are not removed even if they are
331
1
  // unreachable through relocations because reachability is not
332
1
  // a good signal whether they are garbage or not (e.g. there is
333
1
  // usually no section referring to a .comment section, but we
334
1
  // want to keep it.).
335
1
  //
336
1
  // Note on SHF_LINK_ORDER: Such sections contain metadata and they
337
1
  // have a reverse dependency on the InputSection they are linked with.
338
1
  // We are able to garbage collect them.
339
1
  //
340
1
  // Note on SHF_REL{,A}: Such sections reach here only when -r
341
1
  // or -emit-reloc were given. And they are subject of garbage
342
1
  // collection because, if we remove a text section, we also
343
1
  // remove its relocation section.
344
11
  
for (InputSectionBase *sec : inputSections)1
{
345
11
    bool isAlloc = (sec->flags & SHF_ALLOC);
346
11
    bool isLinkOrder = (sec->flags & SHF_LINK_ORDER);
347
11
    bool isRel = (sec->type == SHT_REL || sec->type == SHT_RELA);
348
11
349
11
    if (!isAlloc && 
!isLinkOrder1
&&
!isRel1
)
350
1
      sec->markLive();
351
11
  }
352
1
353
1
  // Follow the graph to mark all live sections.
354
2
  for (unsigned curPart = 1; curPart <= partitions.size(); 
++curPart1
)
355
1
    MarkLive<ELFT>(curPart).run();
356
1
357
1
  // If we have multiple partitions, some sections need to live in the main
358
1
  // partition even if they were allocated to a loadable partition. Move them
359
1
  // there now.
360
1
  if (partitions.size() != 1)
361
0
    MarkLive<ELFT>(1).moveToMain();
362
1
363
1
  // Report garbage-collected sections.
364
1
  if (config->printGcSections)
365
0
    for (InputSectionBase *sec : inputSections)
366
0
      if (!sec->isLive())
367
0
        message("removing unused section " + toString(sec));
368
1
}
369
370
template void elf::markLive<ELF32LE>();
371
template void elf::markLive<ELF32BE>();
372
template void elf::markLive<ELF64LE>();
373
template void elf::markLive<ELF64BE>();