2015-09-22 08:01:39 +08:00
|
|
|
//===- InputSection.h -------------------------------------------*- C++ -*-===//
|
2015-07-25 05:03:07 +08:00
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-09-22 08:01:39 +08:00
|
|
|
#ifndef LLD_ELF_INPUT_SECTION_H
|
|
|
|
#define LLD_ELF_INPUT_SECTION_H
|
2015-07-25 05:03:07 +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
|
|
|
#include "Config.h"
|
2016-05-25 04:24:43 +08:00
|
|
|
#include "Relocations.h"
|
2016-07-09 00:10:27 +08:00
|
|
|
#include "Thunks.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "lld/Core/LLVM.h"
|
2016-05-24 00:55:43 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2016-02-23 11:34:37 +08:00
|
|
|
#include "llvm/ADT/TinyPtrVector.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
|
|
|
|
namespace lld {
|
2016-02-28 08:25:54 +08:00
|
|
|
namespace elf {
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-08-31 21:28:33 +08:00
|
|
|
class DefinedCommon;
|
2016-04-15 22:41:56 +08:00
|
|
|
class SymbolBody;
|
2016-10-06 02:40:00 +08:00
|
|
|
struct SectionPiece;
|
2016-04-15 22:41:56 +08:00
|
|
|
|
2016-02-26 02:43:51 +08:00
|
|
|
template <class ELFT> class ICF;
|
2016-04-04 22:04:16 +08:00
|
|
|
template <class ELFT> class DefinedRegular;
|
2015-07-25 05:03:07 +08:00
|
|
|
template <class ELFT> class ObjectFile;
|
2015-08-25 04:06:32 +08:00
|
|
|
template <class ELFT> class OutputSection;
|
2016-11-10 07:23:45 +08:00
|
|
|
class OutputSectionBase;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-09-01 17:55:57 +08:00
|
|
|
// We need non-template input section class to store symbol layout
|
|
|
|
// in linker script parser structures, where we do not have ELFT
|
|
|
|
// template parameter. For each scripted output section symbol we
|
|
|
|
// store pointer to preceding InputSectionData object or nullptr,
|
|
|
|
// if symbol should be placed at the very beginning of the output
|
|
|
|
// section
|
|
|
|
class InputSectionData {
|
|
|
|
public:
|
2016-11-10 17:48:29 +08:00
|
|
|
enum Kind { Regular, EHFrame, Merge, Synthetic, };
|
2016-09-01 17:55:57 +08:00
|
|
|
|
|
|
|
// The garbage collector sets sections' Live bits.
|
|
|
|
// If GC is disabled, all sections are considered live by default.
|
2016-09-12 21:13:53 +08:00
|
|
|
InputSectionData(Kind SectionKind, StringRef Name, ArrayRef<uint8_t> Data,
|
|
|
|
bool Compressed, bool Live)
|
2016-09-08 22:06:08 +08:00
|
|
|
: SectionKind(SectionKind), Live(Live), Compressed(Compressed),
|
2016-09-12 21:13:53 +08:00
|
|
|
Name(Name), Data(Data) {}
|
2016-09-01 17:55:57 +08:00
|
|
|
|
2016-09-08 20:33:41 +08:00
|
|
|
private:
|
|
|
|
unsigned SectionKind : 3;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Kind kind() const { return (Kind)SectionKind; }
|
|
|
|
|
2016-10-20 13:23:23 +08:00
|
|
|
unsigned Live : 1; // for garbage collection
|
2016-09-08 20:33:41 +08:00
|
|
|
unsigned Compressed : 1;
|
|
|
|
uint32_t Alignment;
|
2016-09-08 22:06:08 +08:00
|
|
|
StringRef Name;
|
2016-09-12 21:13:53 +08:00
|
|
|
ArrayRef<uint8_t> Data;
|
|
|
|
|
2016-10-26 08:54:03 +08:00
|
|
|
template <typename T> llvm::ArrayRef<T> getDataAs() const {
|
|
|
|
size_t S = Data.size();
|
|
|
|
assert(S % sizeof(T) == 0);
|
|
|
|
return llvm::makeArrayRef<T>((const T *)Data.data(), S / sizeof(T));
|
|
|
|
}
|
|
|
|
|
2016-09-08 04:41:19 +08:00
|
|
|
std::vector<Relocation> Relocations;
|
2016-09-01 17:55:57 +08:00
|
|
|
};
|
|
|
|
|
2015-09-22 08:16:19 +08:00
|
|
|
// This corresponds to a section of an input file.
|
2016-09-01 17:55:57 +08:00
|
|
|
template <class ELFT> class InputSectionBase : public InputSectionData {
|
2015-10-20 05:00:02 +08:00
|
|
|
protected:
|
2016-07-07 11:55:55 +08:00
|
|
|
typedef typename ELFT::Chdr Elf_Chdr;
|
2016-04-23 00:39:59 +08:00
|
|
|
typedef typename ELFT::Rel Elf_Rel;
|
|
|
|
typedef typename ELFT::Rela Elf_Rela;
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-10-20 05:00:02 +08:00
|
|
|
|
|
|
|
// The file this section is from.
|
|
|
|
ObjectFile<ELFT> *File;
|
2015-08-14 06:21:37 +08:00
|
|
|
|
2016-10-26 20:36:56 +08:00
|
|
|
public:
|
2016-10-26 08:54:03 +08:00
|
|
|
// These corresponds to the fields in Elf_Shdr.
|
|
|
|
uintX_t Flags;
|
2016-11-01 17:17:50 +08:00
|
|
|
uintX_t Offset = 0;
|
2016-10-26 08:54:03 +08:00
|
|
|
uintX_t Entsize;
|
|
|
|
uint32_t Type;
|
|
|
|
uint32_t Link;
|
|
|
|
uint32_t Info;
|
|
|
|
|
2016-09-08 22:06:08 +08:00
|
|
|
InputSectionBase()
|
2016-09-12 21:13:53 +08:00
|
|
|
: InputSectionData(Regular, "", ArrayRef<uint8_t>(), false, false),
|
2016-11-10 22:53:24 +08:00
|
|
|
Repl(this) {
|
|
|
|
NumRelocations = 0;
|
|
|
|
AreRelocsRela = false;
|
|
|
|
}
|
2016-04-04 22:04:16 +08:00
|
|
|
|
2015-10-20 05:00:02 +08:00
|
|
|
InputSectionBase(ObjectFile<ELFT> *File, const Elf_Shdr *Header,
|
2016-09-08 22:06:08 +08:00
|
|
|
StringRef Name, Kind SectionKind);
|
2016-10-26 08:54:03 +08:00
|
|
|
InputSectionBase(ObjectFile<ELFT> *File, uintX_t Flags, uint32_t Type,
|
|
|
|
uintX_t Entsize, uint32_t Link, uint32_t Info,
|
|
|
|
uintX_t Addralign, ArrayRef<uint8_t> Data, StringRef Name,
|
|
|
|
Kind SectionKind);
|
2016-11-10 07:23:45 +08:00
|
|
|
OutputSectionBase *OutSec = nullptr;
|
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-11-10 22:53:24 +08:00
|
|
|
// Relocations that refer to this section.
|
|
|
|
const Elf_Rel *FirstRelocation = nullptr;
|
|
|
|
unsigned NumRelocations : 31;
|
|
|
|
unsigned AreRelocsRela : 1;
|
|
|
|
ArrayRef<Elf_Rel> rels() const {
|
|
|
|
assert(!AreRelocsRela);
|
|
|
|
return llvm::makeArrayRef(FirstRelocation, NumRelocations);
|
|
|
|
}
|
|
|
|
ArrayRef<Elf_Rela> relas() const {
|
|
|
|
assert(AreRelocsRela);
|
|
|
|
return llvm::makeArrayRef(static_cast<const Elf_Rela *>(FirstRelocation),
|
|
|
|
NumRelocations);
|
|
|
|
}
|
|
|
|
|
2016-02-26 02:43:51 +08:00
|
|
|
// This pointer points to the "real" instance of this instance.
|
|
|
|
// Usually Repl == this. However, if ICF merges two sections,
|
|
|
|
// Repl pointer of one section points to another section. So,
|
|
|
|
// if you need to get a pointer to this instance, do not use
|
|
|
|
// this but instead this->Repl.
|
|
|
|
InputSectionBase<ELFT> *Repl;
|
|
|
|
|
2016-11-08 22:47:16 +08:00
|
|
|
// Returns the size of this section (even if this is a common or BSS.)
|
|
|
|
size_t getSize() const;
|
|
|
|
|
2015-09-24 23:11:50 +08:00
|
|
|
ObjectFile<ELFT> *getFile() const { return File; }
|
2016-11-09 22:39:20 +08:00
|
|
|
llvm::object::ELFFile<ELFT> getObj() const { return File->getObj(); }
|
2016-06-23 12:33:42 +08:00
|
|
|
uintX_t getOffset(const DefinedRegular<ELFT> &Sym) const;
|
2016-10-10 17:39:26 +08:00
|
|
|
InputSectionBase *getLinkOrderDep() const;
|
2015-11-12 00:50:37 +08:00
|
|
|
// Translate an offset in the input section to an offset in the output
|
|
|
|
// section.
|
2016-06-23 12:33:42 +08:00
|
|
|
uintX_t getOffset(uintX_t Offset) const;
|
2015-11-12 00:50:37 +08:00
|
|
|
|
2016-06-24 19:18:44 +08:00
|
|
|
void uncompress();
|
|
|
|
|
2016-04-13 09:40:19 +08:00
|
|
|
void relocate(uint8_t *Buf, uint8_t *BufEnd);
|
2016-10-13 06:36:31 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::pair<ArrayRef<uint8_t>, uint64_t>
|
|
|
|
getElfCompressedData(ArrayRef<uint8_t> Data);
|
|
|
|
|
|
|
|
std::pair<ArrayRef<uint8_t>, uint64_t>
|
|
|
|
getRawCompressedData(ArrayRef<uint8_t> Data);
|
2015-10-20 05:00:02 +08:00
|
|
|
};
|
|
|
|
|
2016-05-22 08:13:04 +08:00
|
|
|
// SectionPiece represents a piece of splittable section contents.
|
2016-10-20 18:55:58 +08:00
|
|
|
// We allocate a lot of these and binary search on them. This means that they
|
|
|
|
// have to be as compact as possible, which is why we don't store the size (can
|
|
|
|
// be found by looking at the next one) and put the hash in a side table.
|
2016-05-22 08:13:04 +08:00
|
|
|
struct SectionPiece {
|
2016-10-20 18:55:58 +08:00
|
|
|
SectionPiece(size_t Off, bool Live = false)
|
|
|
|
: InputOff(Off), OutputOff(-1), Live(Live || !Config->GcSections) {}
|
2016-05-22 09:15:32 +08:00
|
|
|
|
2016-05-22 08:13:04 +08:00
|
|
|
size_t InputOff;
|
2016-10-20 18:55:58 +08:00
|
|
|
ssize_t OutputOff : 8 * sizeof(ssize_t) - 1;
|
2016-10-20 23:59:08 +08:00
|
|
|
size_t Live : 1;
|
2016-05-22 08:13:04 +08:00
|
|
|
};
|
2016-10-20 18:55:58 +08:00
|
|
|
static_assert(sizeof(SectionPiece) == 2 * sizeof(size_t),
|
|
|
|
"SectionPiece is too big");
|
2016-05-22 08:13:04 +08:00
|
|
|
|
2015-10-20 05:00:02 +08:00
|
|
|
// This corresponds to a SHF_MERGE section of an input file.
|
2016-07-21 21:32:37 +08:00
|
|
|
template <class ELFT> class MergeInputSection : public InputSectionBase<ELFT> {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
2015-10-20 05:00:02 +08:00
|
|
|
|
|
|
|
public:
|
2016-09-08 22:06:08 +08:00
|
|
|
MergeInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header,
|
|
|
|
StringRef Name);
|
2016-10-27 02:44:57 +08:00
|
|
|
static bool classof(const InputSectionData *S);
|
2016-05-24 00:55:43 +08:00
|
|
|
void splitIntoPieces();
|
|
|
|
|
|
|
|
// Mark the piece at a given offset live. Used by GC.
|
2016-10-20 07:13:40 +08:00
|
|
|
void markLiveAt(uintX_t Offset) {
|
2016-10-26 20:36:56 +08:00
|
|
|
assert(this->Flags & llvm::ELF::SHF_ALLOC);
|
2016-10-20 07:13:40 +08:00
|
|
|
LiveOffsets.insert(Offset);
|
|
|
|
}
|
2016-05-24 00:55:43 +08:00
|
|
|
|
|
|
|
// Translate an offset in the input section to an offset
|
|
|
|
// in the output section.
|
2016-06-23 12:33:42 +08:00
|
|
|
uintX_t getOffset(uintX_t Offset) const;
|
2016-05-24 00:55:43 +08:00
|
|
|
|
Avoid doing binary search.
MergedInputSection::getOffset is the busiest function in LLD if string
merging is enabled and input files have lots of mergeable sections.
It is usually the case when creating executable with debug info,
so it is pretty common.
The reason why it is slow is because it has to do faily complex
computations. For non-mergeable sections, section contents are
contiguous in output, so in order to compute an output offset,
we only have to add the output section's base address to an input
offset. But for mergeable strings, section contents are split for
merging, so they are not contigous. We've got to do some lookups.
We used to do binary search on the list of section pieces.
It is slow because I think it's hostile to branch prediction.
This patch replaces it with hash table lookup. Seems it's working
pretty well. Below is "perf stat -r10" output when linking clang
with debug info. In this case this patch speeds up about 4%.
Before:
6584.153205 task-clock (msec) # 1.001 CPUs utilized ( +- 0.09% )
238 context-switches # 0.036 K/sec ( +- 6.59% )
0 cpu-migrations # 0.000 K/sec ( +- 50.92% )
1,067,675 page-faults # 0.162 M/sec ( +- 0.15% )
18,369,931,470 cycles # 2.790 GHz ( +- 0.09% )
9,640,680,143 stalled-cycles-frontend # 52.48% frontend cycles idle ( +- 0.18% )
<not supported> stalled-cycles-backend
21,206,747,787 instructions # 1.15 insns per cycle
# 0.45 stalled cycles per insn ( +- 0.04% )
3,817,398,032 branches # 579.786 M/sec ( +- 0.04% )
132,787,249 branch-misses # 3.48% of all branches ( +- 0.02% )
6.579106511 seconds time elapsed ( +- 0.09% )
After:
6312.317533 task-clock (msec) # 1.001 CPUs utilized ( +- 0.19% )
221 context-switches # 0.035 K/sec ( +- 4.11% )
1 cpu-migrations # 0.000 K/sec ( +- 45.21% )
1,280,775 page-faults # 0.203 M/sec ( +- 0.37% )
17,611,539,150 cycles # 2.790 GHz ( +- 0.19% )
10,285,148,569 stalled-cycles-frontend # 58.40% frontend cycles idle ( +- 0.30% )
<not supported> stalled-cycles-backend
18,794,779,900 instructions # 1.07 insns per cycle
# 0.55 stalled cycles per insn ( +- 0.03% )
3,287,450,865 branches # 520.799 M/sec ( +- 0.03% )
72,259,605 branch-misses # 2.20% of all branches ( +- 0.01% )
6.307411828 seconds time elapsed ( +- 0.19% )
Differential Revision: http://reviews.llvm.org/D20645
llvm-svn: 270999
2016-05-27 22:39:13 +08:00
|
|
|
void finalizePieces();
|
|
|
|
|
2016-07-21 21:32:37 +08:00
|
|
|
// Splittable sections are handled as a sequence of data
|
|
|
|
// rather than a single large blob of data.
|
|
|
|
std::vector<SectionPiece> Pieces;
|
2016-10-20 18:55:58 +08:00
|
|
|
ArrayRef<uint8_t> getData(std::vector<SectionPiece>::const_iterator I) const;
|
|
|
|
std::vector<uint32_t> Hashes;
|
2016-07-21 21:32:37 +08:00
|
|
|
|
|
|
|
// Returns the SectionPiece at a given input section offset.
|
|
|
|
SectionPiece *getSectionPiece(uintX_t Offset);
|
|
|
|
const SectionPiece *getSectionPiece(uintX_t Offset) const;
|
|
|
|
|
2016-05-24 00:55:43 +08:00
|
|
|
private:
|
2016-08-03 12:39:42 +08:00
|
|
|
std::vector<SectionPiece> splitStrings(ArrayRef<uint8_t> A, size_t Size);
|
|
|
|
std::vector<SectionPiece> splitNonStrings(ArrayRef<uint8_t> A, size_t Size);
|
|
|
|
|
Avoid doing binary search.
MergedInputSection::getOffset is the busiest function in LLD if string
merging is enabled and input files have lots of mergeable sections.
It is usually the case when creating executable with debug info,
so it is pretty common.
The reason why it is slow is because it has to do faily complex
computations. For non-mergeable sections, section contents are
contiguous in output, so in order to compute an output offset,
we only have to add the output section's base address to an input
offset. But for mergeable strings, section contents are split for
merging, so they are not contigous. We've got to do some lookups.
We used to do binary search on the list of section pieces.
It is slow because I think it's hostile to branch prediction.
This patch replaces it with hash table lookup. Seems it's working
pretty well. Below is "perf stat -r10" output when linking clang
with debug info. In this case this patch speeds up about 4%.
Before:
6584.153205 task-clock (msec) # 1.001 CPUs utilized ( +- 0.09% )
238 context-switches # 0.036 K/sec ( +- 6.59% )
0 cpu-migrations # 0.000 K/sec ( +- 50.92% )
1,067,675 page-faults # 0.162 M/sec ( +- 0.15% )
18,369,931,470 cycles # 2.790 GHz ( +- 0.09% )
9,640,680,143 stalled-cycles-frontend # 52.48% frontend cycles idle ( +- 0.18% )
<not supported> stalled-cycles-backend
21,206,747,787 instructions # 1.15 insns per cycle
# 0.45 stalled cycles per insn ( +- 0.04% )
3,817,398,032 branches # 579.786 M/sec ( +- 0.04% )
132,787,249 branch-misses # 3.48% of all branches ( +- 0.02% )
6.579106511 seconds time elapsed ( +- 0.09% )
After:
6312.317533 task-clock (msec) # 1.001 CPUs utilized ( +- 0.19% )
221 context-switches # 0.035 K/sec ( +- 4.11% )
1 cpu-migrations # 0.000 K/sec ( +- 45.21% )
1,280,775 page-faults # 0.203 M/sec ( +- 0.37% )
17,611,539,150 cycles # 2.790 GHz ( +- 0.19% )
10,285,148,569 stalled-cycles-frontend # 58.40% frontend cycles idle ( +- 0.30% )
<not supported> stalled-cycles-backend
18,794,779,900 instructions # 1.07 insns per cycle
# 0.55 stalled cycles per insn ( +- 0.03% )
3,287,450,865 branches # 520.799 M/sec ( +- 0.03% )
72,259,605 branch-misses # 2.20% of all branches ( +- 0.01% )
6.307411828 seconds time elapsed ( +- 0.19% )
Differential Revision: http://reviews.llvm.org/D20645
llvm-svn: 270999
2016-05-27 22:39:13 +08:00
|
|
|
llvm::DenseMap<uintX_t, uintX_t> OffsetMap;
|
2016-05-24 00:55:43 +08:00
|
|
|
llvm::DenseSet<uintX_t> LiveOffsets;
|
2015-10-20 05:00:02 +08:00
|
|
|
};
|
|
|
|
|
2016-07-22 04:18:30 +08:00
|
|
|
struct EhSectionPiece : public SectionPiece {
|
|
|
|
EhSectionPiece(size_t Off, ArrayRef<uint8_t> Data, unsigned FirstRelocation)
|
2016-10-20 18:55:58 +08:00
|
|
|
: SectionPiece(Off, false), Data(Data.data()), Size(Data.size()),
|
2016-10-06 02:40:00 +08:00
|
|
|
FirstRelocation(FirstRelocation) {}
|
|
|
|
const uint8_t *Data;
|
2016-10-20 18:55:58 +08:00
|
|
|
uint32_t Size;
|
|
|
|
uint32_t size() const { return Size; }
|
|
|
|
|
|
|
|
ArrayRef<uint8_t> data() { return {Data, Size}; }
|
2016-07-22 04:18:30 +08:00
|
|
|
unsigned FirstRelocation;
|
|
|
|
};
|
|
|
|
|
2015-11-12 03:54:14 +08:00
|
|
|
// This corresponds to a .eh_frame section of an input file.
|
2016-07-21 21:32:37 +08:00
|
|
|
template <class ELFT> class EhInputSection : public InputSectionBase<ELFT> {
|
2015-11-12 03:54:14 +08:00
|
|
|
public:
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
2016-09-08 22:06:08 +08:00
|
|
|
EhInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header, StringRef Name);
|
2016-10-27 02:44:57 +08:00
|
|
|
static bool classof(const InputSectionData *S);
|
2016-05-23 07:53:00 +08:00
|
|
|
void split();
|
2016-07-22 04:18:30 +08:00
|
|
|
template <class RelTy> void split(ArrayRef<RelTy> Rels);
|
2015-11-12 03:54:14 +08:00
|
|
|
|
2016-07-21 21:32:37 +08:00
|
|
|
// Splittable sections are handled as a sequence of data
|
|
|
|
// rather than a single large blob of data.
|
2016-07-22 04:18:30 +08:00
|
|
|
std::vector<EhSectionPiece> Pieces;
|
2015-11-12 03:54:14 +08:00
|
|
|
};
|
|
|
|
|
2015-10-20 05:00:02 +08:00
|
|
|
// This corresponds to a non SHF_MERGE section of an input file.
|
|
|
|
template <class ELFT> class InputSection : public InputSectionBase<ELFT> {
|
2016-02-26 02:43:51 +08:00
|
|
|
friend ICF<ELFT>;
|
2015-10-20 05:00:02 +08:00
|
|
|
typedef InputSectionBase<ELFT> Base;
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::Rela Elf_Rela;
|
|
|
|
typedef typename ELFT::Rel Elf_Rel;
|
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
2016-11-10 17:48:29 +08:00
|
|
|
typedef InputSectionData::Kind Kind;
|
2015-10-20 05:00:02 +08:00
|
|
|
|
|
|
|
public:
|
2016-11-10 00:55:07 +08:00
|
|
|
InputSection();
|
2016-10-26 08:54:03 +08:00
|
|
|
InputSection(uintX_t Flags, uint32_t Type, uintX_t Addralign,
|
2016-11-10 17:48:29 +08:00
|
|
|
ArrayRef<uint8_t> Data, StringRef Name,
|
|
|
|
Kind K = InputSectionData::Regular);
|
2016-09-08 22:06:08 +08:00
|
|
|
InputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header, StringRef Name);
|
2015-10-20 05:00:02 +08:00
|
|
|
|
2016-11-10 00:55:07 +08:00
|
|
|
static InputSection<ELFT> Discarded;
|
|
|
|
|
2015-10-20 05:00:02 +08:00
|
|
|
// Write this section to a mmap'ed file, assuming Buf is pointing to
|
|
|
|
// beginning of the output section.
|
2016-11-08 22:47:16 +08:00
|
|
|
void writeTo(uint8_t *Buf);
|
2015-10-20 05:00:02 +08:00
|
|
|
|
2015-10-15 05:00:23 +08:00
|
|
|
// The offset from beginning of the output sections this section was assigned
|
|
|
|
// to. The writer sets a value.
|
2015-10-15 09:58:40 +08:00
|
|
|
uint64_t OutSecOff = 0;
|
2015-10-15 05:00:23 +08:00
|
|
|
|
2016-10-10 18:10:27 +08:00
|
|
|
// InputSection that is dependent on us (reverse dependency for GC)
|
|
|
|
InputSectionBase<ELFT> *DependentSection = nullptr;
|
|
|
|
|
2016-10-27 02:44:57 +08:00
|
|
|
static bool classof(const InputSectionData *S);
|
2016-02-25 16:23:37 +08:00
|
|
|
|
|
|
|
InputSectionBase<ELFT> *getRelocatedSection();
|
|
|
|
|
2016-04-01 05:26:23 +08:00
|
|
|
// Register thunk related to the symbol. When the section is written
|
|
|
|
// to a mmap'ed file, target is requested to write an actual thunk code.
|
2016-07-09 00:10:27 +08:00
|
|
|
// Now thunks is supported for MIPS and ARM target only.
|
|
|
|
void addThunk(const Thunk<ELFT> *T);
|
2016-04-01 05:26:23 +08:00
|
|
|
|
|
|
|
// The offset of synthetic thunk code from beginning of this section.
|
|
|
|
uint64_t getThunkOff() const;
|
|
|
|
|
|
|
|
// Size of chunk with thunks code.
|
|
|
|
uint64_t getThunksSize() const;
|
|
|
|
|
2016-04-29 02:42:04 +08:00
|
|
|
template <class RelTy>
|
|
|
|
void relocateNonAlloc(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);
|
|
|
|
|
2016-02-25 16:23:37 +08:00
|
|
|
private:
|
2016-03-13 13:06:50 +08:00
|
|
|
template <class RelTy>
|
2016-04-05 22:47:28 +08:00
|
|
|
void copyRelocations(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);
|
2016-02-26 02:43:51 +08:00
|
|
|
|
|
|
|
// Called by ICF to merge two input sections.
|
|
|
|
void replace(InputSection<ELFT> *Other);
|
|
|
|
|
|
|
|
// Used by ICF.
|
|
|
|
uint64_t GroupId = 0;
|
2016-04-01 05:26:23 +08:00
|
|
|
|
2016-07-09 00:10:27 +08:00
|
|
|
llvm::TinyPtrVector<const Thunk<ELFT> *> Thunks;
|
2015-07-25 05:03:07 +08:00
|
|
|
};
|
|
|
|
|
2016-11-10 00:55:07 +08:00
|
|
|
template <class ELFT> InputSection<ELFT> InputSection<ELFT>::Discarded;
|
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
} // namespace elf
|
2015-07-25 05:03:07 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|