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-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;
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> 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:
|
|
|
|
enum Kind { Regular, EHFrame, Merge, MipsReginfo, MipsOptions, MipsAbiFlags };
|
|
|
|
|
|
|
|
// The garbage collector sets sections' Live bits.
|
|
|
|
// If GC is disabled, all sections are considered live by default.
|
|
|
|
InputSectionData(Kind SectionKind, bool Compressed, bool Live)
|
|
|
|
: SectionKind(SectionKind), Live(Live), Compressed(Compressed) {}
|
|
|
|
|
2016-09-08 20:33:41 +08:00
|
|
|
private:
|
|
|
|
unsigned SectionKind : 3;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Kind kind() const { return (Kind)SectionKind; }
|
|
|
|
|
2016-09-01 17:55:57 +08:00
|
|
|
// Used for garbage collection.
|
2016-09-08 20:33:41 +08:00
|
|
|
unsigned Live : 1;
|
|
|
|
|
|
|
|
unsigned Compressed : 1;
|
|
|
|
|
|
|
|
uint32_t Alignment;
|
2016-09-01 17:55:57 +08:00
|
|
|
|
|
|
|
// If a section is compressed, this vector has uncompressed section data.
|
|
|
|
SmallVector<char, 0> Uncompressed;
|
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
|
|
|
const Elf_Shdr *Header;
|
|
|
|
|
|
|
|
// The file this section is from.
|
|
|
|
ObjectFile<ELFT> *File;
|
2015-08-14 06:21:37 +08:00
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
public:
|
2016-09-01 17:55:57 +08:00
|
|
|
InputSectionBase() : InputSectionData(Regular, false, false), Repl(this) {}
|
2016-04-04 22:04:16 +08:00
|
|
|
|
2015-10-20 05:00:02 +08:00
|
|
|
InputSectionBase(ObjectFile<ELFT> *File, const Elf_Shdr *Header,
|
|
|
|
Kind SectionKind);
|
|
|
|
OutputSectionBase<ELFT> *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-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;
|
|
|
|
|
2015-09-22 08:16:19 +08:00
|
|
|
// Returns the size of this section (even if this is a common or BSS.)
|
2016-04-01 05:26:23 +08:00
|
|
|
size_t getSize() const;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-04-04 22:04:16 +08:00
|
|
|
static InputSectionBase<ELFT> Discarded;
|
2015-08-14 06:21:37 +08:00
|
|
|
|
|
|
|
StringRef getSectionName() const;
|
|
|
|
const Elf_Shdr *getSectionHdr() const { return Header; }
|
2015-09-24 23:11:50 +08:00
|
|
|
ObjectFile<ELFT> *getFile() const { return File; }
|
2016-06-23 12:33:42 +08:00
|
|
|
uintX_t getOffset(const DefinedRegular<ELFT> &Sym) 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
|
|
|
|
2015-10-20 05:00:02 +08:00
|
|
|
ArrayRef<uint8_t> getSectionData() const;
|
2015-10-28 05:51:13 +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);
|
2015-10-20 05:00:02 +08:00
|
|
|
};
|
|
|
|
|
2016-04-04 22:04:16 +08:00
|
|
|
template <class ELFT> InputSectionBase<ELFT> InputSectionBase<ELFT>::Discarded;
|
2015-10-20 05:00:02 +08:00
|
|
|
|
2016-05-22 08:13:04 +08:00
|
|
|
// SectionPiece represents a piece of splittable section contents.
|
|
|
|
struct SectionPiece {
|
2016-05-22 09:15:32 +08:00
|
|
|
SectionPiece(size_t Off, ArrayRef<uint8_t> Data)
|
2016-05-29 07:27:38 +08:00
|
|
|
: InputOff(Off), Data((const uint8_t *)Data.data()), Size(Data.size()),
|
2016-05-26 00:37:01 +08:00
|
|
|
Live(!Config->GcSections) {}
|
|
|
|
|
|
|
|
ArrayRef<uint8_t> data() { return {Data, Size}; }
|
|
|
|
size_t size() const { return Size; }
|
2016-05-22 09:15:32 +08:00
|
|
|
|
2016-05-22 08:13:04 +08:00
|
|
|
size_t InputOff;
|
|
|
|
size_t OutputOff = -1;
|
2016-05-26 00:37:01 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
// We use bitfields because SplitInputSection is accessed by
|
|
|
|
// std::upper_bound very often.
|
|
|
|
// We want to save bits to make it cache friendly.
|
2016-05-29 07:27:38 +08:00
|
|
|
const uint8_t *Data;
|
2016-05-26 00:37:01 +08:00
|
|
|
uint32_t Size : 31;
|
|
|
|
|
|
|
|
public:
|
|
|
|
uint32_t Live : 1;
|
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:
|
|
|
|
MergeInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header);
|
|
|
|
static bool classof(const InputSectionBase<ELFT> *S);
|
2016-05-24 00:55:43 +08:00
|
|
|
void splitIntoPieces();
|
|
|
|
|
|
|
|
// Mark the piece at a given offset live. Used by GC.
|
|
|
|
void markLiveAt(uintX_t Offset) { LiveOffsets.insert(Offset); }
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
: SectionPiece(Off, Data), FirstRelocation(FirstRelocation) {}
|
|
|
|
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-05-24 12:19:20 +08:00
|
|
|
EhInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header);
|
2015-11-12 03:54:14 +08:00
|
|
|
static bool classof(const InputSectionBase<ELFT> *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;
|
2016-07-21 21:32:37 +08:00
|
|
|
|
2015-11-12 03:54:14 +08:00
|
|
|
// Relocation section that refer to this one.
|
|
|
|
const Elf_Shdr *RelocSection = nullptr;
|
|
|
|
};
|
|
|
|
|
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;
|
2015-10-20 05:00:02 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
InputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header);
|
|
|
|
|
|
|
|
// Write this section to a mmap'ed file, assuming Buf is pointing to
|
|
|
|
// beginning of the output section.
|
|
|
|
void writeTo(uint8_t *Buf);
|
|
|
|
|
2015-08-28 07:15:56 +08:00
|
|
|
// Relocation sections that refer to this one.
|
2016-02-23 11:34:37 +08:00
|
|
|
llvm::TinyPtrVector<const Elf_Shdr *> RelocSections;
|
2015-08-28 07:15:56 +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
|
|
|
|
2015-10-20 05:00:02 +08:00
|
|
|
static bool classof(const InputSectionBase<ELFT> *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
|
|
|
};
|
|
|
|
|
2015-12-20 18:57:34 +08:00
|
|
|
// MIPS .reginfo section provides information on the registers used by the code
|
|
|
|
// in the object file. Linker should collect this information and write a single
|
|
|
|
// .reginfo section in the output file. The output section contains a union of
|
|
|
|
// used registers masks taken from input .reginfo sections and final value
|
|
|
|
// of the `_gp` symbol. For details: Chapter 4 / "Register Information" at
|
|
|
|
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
|
|
|
|
template <class ELFT>
|
|
|
|
class MipsReginfoInputSection : public InputSectionBase<ELFT> {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
2015-12-20 18:57:34 +08:00
|
|
|
|
|
|
|
public:
|
2016-01-07 06:42:43 +08:00
|
|
|
MipsReginfoInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Hdr);
|
2015-12-20 18:57:34 +08:00
|
|
|
static bool classof(const InputSectionBase<ELFT> *S);
|
2016-01-07 06:42:43 +08:00
|
|
|
|
2016-05-04 18:07:38 +08:00
|
|
|
const llvm::object::Elf_Mips_RegInfo<ELFT> *Reginfo = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
class MipsOptionsInputSection : public InputSectionBase<ELFT> {
|
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MipsOptionsInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Hdr);
|
|
|
|
static bool classof(const InputSectionBase<ELFT> *S);
|
|
|
|
|
|
|
|
const llvm::object::Elf_Mips_RegInfo<ELFT> *Reginfo = nullptr;
|
2015-12-20 18:57:34 +08:00
|
|
|
};
|
|
|
|
|
2016-08-12 14:28:49 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class MipsAbiFlagsInputSection : public InputSectionBase<ELFT> {
|
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MipsAbiFlagsInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Hdr);
|
|
|
|
static bool classof(const InputSectionBase<ELFT> *S);
|
|
|
|
|
|
|
|
const llvm::object::Elf_Mips_ABIFlags<ELFT> *Flags = nullptr;
|
|
|
|
};
|
|
|
|
|
2016-07-29 05:05:04 +08:00
|
|
|
// Common symbols don't belong to any section. But it is easier for us
|
|
|
|
// to handle them as if they belong to some input section. So we defined
|
|
|
|
// this class. CommonInputSection is a virtual singleton class that
|
|
|
|
// "contains" all common symbols.
|
2016-07-29 03:24:13 +08:00
|
|
|
template <class ELFT> class CommonInputSection : public InputSection<ELFT> {
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
|
|
|
|
|
|
|
public:
|
2016-08-31 21:28:33 +08:00
|
|
|
CommonInputSection(std::vector<DefinedCommon *> Syms);
|
2016-07-29 03:24:13 +08:00
|
|
|
|
2016-07-29 05:05:04 +08:00
|
|
|
// The singleton instance of this class.
|
|
|
|
static CommonInputSection<ELFT> *X;
|
|
|
|
|
2016-07-29 03:24:13 +08:00
|
|
|
private:
|
2016-07-29 05:05:04 +08:00
|
|
|
static typename ELFT::Shdr Hdr;
|
2016-07-29 03:24:13 +08:00
|
|
|
};
|
|
|
|
|
2016-07-29 05:05:04 +08:00
|
|
|
template <class ELFT> CommonInputSection<ELFT> *CommonInputSection<ELFT>::X;
|
|
|
|
template <class ELFT> typename ELFT::Shdr CommonInputSection<ELFT>::Hdr;
|
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
} // namespace elf
|
2015-07-25 05:03:07 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|