ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
//===- MarkLive.cpp -------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements --gc-sections, which is a feature to remove unused
|
|
|
|
// sections from output. Unused sections are sections that are not reachable
|
|
|
|
// from known GC-root symbols or sections. Naturally the feature is
|
|
|
|
// implemented as a mark-sweep garbage collector.
|
|
|
|
//
|
|
|
|
// Here's how it works. Each InputSectionBase has a "Live" bit. The bit is off
|
|
|
|
// by default. Starting with GC-root symbols or sections, markLive function
|
|
|
|
// defined in this file visits all reachable sections to set their Live
|
|
|
|
// bits. Writer will then ignore sections whose Live bits are off, so that
|
2016-01-06 00:35:46 +08:00
|
|
|
// such sections are not included into output.
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "InputSection.h"
|
2016-02-23 15:47:54 +08:00
|
|
|
#include "LinkerScript.h"
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
#include "OutputSections.h"
|
|
|
|
#include "SymbolTable.h"
|
|
|
|
#include "Symbols.h"
|
2016-04-27 07:52:44 +08:00
|
|
|
#include "Target.h"
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
#include "Writer.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::ELF;
|
|
|
|
using namespace llvm::object;
|
|
|
|
|
|
|
|
using namespace lld;
|
2016-02-28 08:25:54 +08:00
|
|
|
using namespace lld::elf;
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
|
2016-04-27 07:52:44 +08:00
|
|
|
// A resolved relocation. The Sec and Offset fields are set if the relocation
|
|
|
|
// was resolved to an offset within a section.
|
|
|
|
template <class ELFT>
|
|
|
|
struct ResolvedReloc {
|
|
|
|
InputSectionBase<ELFT> *Sec;
|
|
|
|
typename ELFT::uint Offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
static typename ELFT::uint getAddend(InputSectionBase<ELFT> *Sec,
|
|
|
|
const typename ELFT::Rel &Rel) {
|
|
|
|
return Target->getImplicitAddend(Sec->getSectionData().begin(),
|
|
|
|
Rel.getType(Config->Mips64EL));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
static typename ELFT::uint getAddend(InputSectionBase<ELFT> *Sec,
|
|
|
|
const typename ELFT::Rela &Rel) {
|
|
|
|
return Rel.r_addend;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT, class RelT>
|
|
|
|
static ResolvedReloc<ELFT> resolveReloc(InputSection<ELFT> *Sec, RelT &Rel) {
|
|
|
|
SymbolBody &B = Sec->getFile()->getRelocTargetSym(Rel);
|
|
|
|
auto *D = dyn_cast<DefinedRegular<ELFT>>(&B);
|
|
|
|
if (!D || !D->Section)
|
|
|
|
return {nullptr, 0};
|
|
|
|
typename ELFT::uint Offset = D->Value;
|
|
|
|
if (D->isSection())
|
|
|
|
Offset += getAddend(Sec, Rel);
|
|
|
|
return {D->Section->Repl, Offset};
|
|
|
|
}
|
|
|
|
|
2016-01-06 00:35:46 +08:00
|
|
|
// Calls Fn for each section that Sec refers to via relocations.
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
template <class ELFT>
|
2016-04-27 07:52:44 +08:00
|
|
|
static void forEachSuccessor(InputSection<ELFT> *Sec,
|
|
|
|
std::function<void(ResolvedReloc<ELFT>)> Fn) {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Rel Elf_Rel;
|
|
|
|
typedef typename ELFT::Rela Elf_Rela;
|
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
2015-10-28 05:51:13 +08:00
|
|
|
|
2016-04-23 00:39:59 +08:00
|
|
|
ELFFile<ELFT> &Obj = Sec->getFile()->getObj();
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
for (const Elf_Shdr *RelSec : Sec->RelocSections) {
|
2015-10-28 05:51:13 +08:00
|
|
|
if (RelSec->sh_type == SHT_RELA) {
|
2016-04-27 07:52:44 +08:00
|
|
|
for (const Elf_Rela &RI : Obj.relas(RelSec))
|
|
|
|
Fn(resolveReloc(Sec, RI));
|
2015-10-28 05:51:13 +08:00
|
|
|
} else {
|
2016-04-27 07:52:44 +08:00
|
|
|
for (const Elf_Rel &RI : Obj.rels(RelSec))
|
|
|
|
Fn(resolveReloc(Sec, RI));
|
2015-10-28 05:51:13 +08:00
|
|
|
}
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sections listed below are special because they are used by the loader
|
|
|
|
// just by being in an ELF file. They should not be garbage-collected.
|
|
|
|
template <class ELFT> static bool isReserved(InputSectionBase<ELFT> *Sec) {
|
|
|
|
switch (Sec->getSectionHdr()->sh_type) {
|
|
|
|
case SHT_FINI_ARRAY:
|
|
|
|
case SHT_INIT_ARRAY:
|
|
|
|
case SHT_NOTE:
|
|
|
|
case SHT_PREINIT_ARRAY:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
StringRef S = Sec->getSectionName();
|
2016-02-25 16:40:26 +08:00
|
|
|
|
|
|
|
// We do not want to reclaim sections if they can be referred
|
|
|
|
// by __start_* and __stop_* symbols.
|
|
|
|
if (isValidCIdentifier(S))
|
|
|
|
return true;
|
|
|
|
|
2015-12-24 17:52:11 +08:00
|
|
|
return S.startswith(".ctors") || S.startswith(".dtors") ||
|
|
|
|
S.startswith(".init") || S.startswith(".fini") ||
|
2015-11-10 01:44:10 +08:00
|
|
|
S.startswith(".jcr");
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-24 17:50:22 +08:00
|
|
|
// This is the main function of the garbage collector.
|
|
|
|
// Starting from GC-root sections, this function visits all reachable
|
|
|
|
// sections to set their "Live" bits.
|
2016-02-28 08:25:54 +08:00
|
|
|
template <class ELFT> void elf::markLive(SymbolTable<ELFT> *Symtab) {
|
2016-04-23 06:09:35 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-11-13 03:42:43 +08:00
|
|
|
SmallVector<InputSection<ELFT> *, 256> Q;
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
|
2016-04-27 07:52:44 +08:00
|
|
|
auto Enqueue = [&](ResolvedReloc<ELFT> R) {
|
|
|
|
if (!R.Sec)
|
2016-04-23 06:09:35 +08:00
|
|
|
return;
|
2016-04-27 07:52:44 +08:00
|
|
|
if (auto *MS = dyn_cast<MergeInputSection<ELFT>>(R.Sec)) {
|
2016-04-23 06:09:35 +08:00
|
|
|
std::pair<std::pair<uintX_t, uintX_t> *, uintX_t> T =
|
2016-04-27 07:52:44 +08:00
|
|
|
MS->getRangeAndSize(R.Offset);
|
2016-04-23 06:09:35 +08:00
|
|
|
T.first->second = 0;
|
|
|
|
}
|
2016-04-27 07:52:44 +08:00
|
|
|
if (R.Sec->Live)
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
return;
|
2016-04-27 07:52:44 +08:00
|
|
|
R.Sec->Live = true;
|
|
|
|
if (InputSection<ELFT> *S = dyn_cast<InputSection<ELFT>>(R.Sec))
|
2015-11-13 03:42:43 +08:00
|
|
|
Q.push_back(S);
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
auto MarkSymbol = [&](SymbolBody *Sym) {
|
|
|
|
if (Sym)
|
2016-04-15 22:41:56 +08:00
|
|
|
if (auto *D = dyn_cast<DefinedRegular<ELFT>>(Sym))
|
2016-04-27 07:52:44 +08:00
|
|
|
Enqueue({D->Section, D->Value});
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add GC root symbols.
|
2016-04-15 22:41:56 +08:00
|
|
|
if (Config->EntrySym)
|
|
|
|
MarkSymbol(Config->EntrySym->Body);
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
MarkSymbol(Symtab->find(Config->Init));
|
|
|
|
MarkSymbol(Symtab->find(Config->Fini));
|
|
|
|
for (StringRef S : Config->Undefined)
|
|
|
|
MarkSymbol(Symtab->find(S));
|
|
|
|
|
|
|
|
// Preserve externally-visible symbols if the symbols defined by this
|
2016-01-06 00:35:46 +08:00
|
|
|
// file can interrupt other ELF file's symbols at runtime.
|
2016-04-27 00:26:45 +08:00
|
|
|
for (const Symbol *S : Symtab->getSymbols())
|
|
|
|
if (S->includeInDynsym())
|
|
|
|
MarkSymbol(S->Body);
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
|
2016-02-23 15:47:54 +08:00
|
|
|
// Preserve special sections and those which are specified in linker
|
|
|
|
// script KEEP command.
|
2015-12-24 18:14:05 +08:00
|
|
|
for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab->getObjectFiles())
|
|
|
|
for (InputSectionBase<ELFT> *Sec : F->getSections())
|
2016-04-04 22:04:16 +08:00
|
|
|
if (Sec && Sec != &InputSection<ELFT>::Discarded)
|
2016-04-21 04:13:41 +08:00
|
|
|
if (isReserved(Sec) || Script<ELFT>::X->shouldKeep(Sec))
|
2016-04-27 07:52:44 +08:00
|
|
|
Enqueue({Sec, 0});
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
|
|
|
|
// Mark all reachable sections.
|
|
|
|
while (!Q.empty())
|
2015-11-13 03:42:43 +08:00
|
|
|
forEachSuccessor<ELFT>(Q.pop_back_val(), Enqueue);
|
ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.
In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.
This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.
It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.
http://reviews.llvm.org/D13950
llvm-svn: 251043
2015-10-23 02:49:53 +08:00
|
|
|
}
|
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
template void elf::markLive<ELF32LE>(SymbolTable<ELF32LE> *);
|
|
|
|
template void elf::markLive<ELF32BE>(SymbolTable<ELF32BE> *);
|
|
|
|
template void elf::markLive<ELF64LE>(SymbolTable<ELF64LE> *);
|
|
|
|
template void elf::markLive<ELF64BE>(SymbolTable<ELF64BE> *);
|