blob: 4453da8394e30b7f51d6e404b59ade56e3195344 [file] [log] [blame]
Rafael Espindola9d06ab62015-09-22 00:01:39 +00001//===- InputSection.h -------------------------------------------*- C++ -*-===//
Michael J. Spencer84487f12015-07-24 21:03:07 +00002//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Rafael Espindola9d06ab62015-09-22 00:01:39 +000010#ifndef LLD_ELF_INPUT_SECTION_H
11#define LLD_ELF_INPUT_SECTION_H
Michael J. Spencer84487f12015-07-24 21:03:07 +000012
Rui Ueyamac4aaed92015-10-22 18:49:53 +000013#include "Config.h"
Rui Ueyama0fcdc732016-05-24 20:24:43 +000014#include "Relocations.h"
Peter Smithfb05cd92016-07-08 16:10:27 +000015#include "Thunks.h"
Rui Ueyama3f851702017-10-02 21:00:41 +000016#include "lld/Common/LLVM.h"
Rui Ueyama8f687f72016-12-19 03:14:16 +000017#include "llvm/ADT/CachedHashString.h"
Rui Ueyamab91bf1a2016-05-23 16:55:43 +000018#include "llvm/ADT/DenseSet.h"
Rui Ueyamac00718f2016-02-23 03:34:37 +000019#include "llvm/ADT/TinyPtrVector.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000020#include "llvm/Object/ELF.h"
Kamil Rytarowskie739e492017-05-24 18:31:48 +000021#include "llvm/Support/Threading.h"
Rui Ueyama77f2a872016-11-18 05:05:43 +000022#include <mutex>
Michael J. Spencer84487f12015-07-24 21:03:07 +000023
24namespace lld {
Rafael Espindolae0df00b2016-02-28 00:25:54 +000025namespace elf {
Michael J. Spencer84487f12015-07-24 21:03:07 +000026
Rafael Espindolae7553e42016-08-31 13:28:33 +000027class DefinedCommon;
Rafael Espindola38c67a22016-04-15 14:41:56 +000028class SymbolBody;
Rafael Espindola32aca872016-10-05 18:40:00 +000029struct SectionPiece;
Rafael Espindola38c67a22016-04-15 14:41:56 +000030
Rui Ueyama80474a22017-02-28 19:29:55 +000031class DefinedRegular;
Rafael Espindola5c02b742017-03-06 21:17:18 +000032class SyntheticSection;
Rafael Espindola66b4e212017-02-23 22:06:28 +000033template <class ELFT> class EhFrameSection;
Rafael Espindola6119b862017-03-06 20:23:56 +000034class MergeSyntheticSection;
Rui Ueyama709fb2bb12017-07-26 22:13:32 +000035template <class ELFT> class ObjFile;
Rafael Espindola24e6f362017-02-24 15:07:30 +000036class OutputSection;
Michael J. Spencer84487f12015-07-24 21:03:07 +000037
Rafael Espindola5616adf2017-03-08 22:36:28 +000038// This is the base class of all sections that lld handles. Some are sections in
39// input files, some are sections in the produced output file and some exist
40// just as a convenience for implementing special ways of combining some
41// sections.
42class SectionBase {
Eugene Leviant97403d12016-09-01 09:55:57 +000043public:
Rafael Espindola5616adf2017-03-08 22:36:28 +000044 enum Kind { Regular, EHFrame, Merge, Synthetic, Output };
Eugene Leviant97403d12016-09-01 09:55:57 +000045
Rafael Espindola16853bb2016-09-08 12:33:41 +000046 Kind kind() const { return (Kind)SectionKind; }
Rafael Espindolac404d502017-02-23 02:32:18 +000047
48 StringRef Name;
49
50 unsigned SectionKind : 3;
51
Rafael Espindola5616adf2017-03-08 22:36:28 +000052 // The next two bit fields are only used by InputSectionBase, but we
53 // put them here so the struct packs better.
54
Rafael Espindolac404d502017-02-23 02:32:18 +000055 // The garbage collector sets sections' Live bits.
56 // If GC is disabled, all sections are considered live by default.
Rui Ueyamae8936bc2017-10-08 01:55:29 +000057 unsigned Live : 1;
Rafael Espindolac404d502017-02-23 02:32:18 +000058
Rui Ueyamae8936bc2017-10-08 01:55:29 +000059 // True if this section has already been placed to a linker script
60 // output section. This is needed because, in a linker script, you
61 // can refer to the same section more than once. For example, in
62 // the following linker script,
63 //
64 // .foo : { *(.text) }
65 // .bar : { *(.text) }
66 //
67 // .foo takes all .text sections, and .bar becomes empty. To achieve
68 // this, we need to memorize whether a section has been placed or
69 // not for each input section.
70 unsigned Assigned : 1;
Rafael Espindolac404d502017-02-23 02:32:18 +000071
Rafael Espindola0e090522016-10-26 00:54:03 +000072 // These corresponds to the fields in Elf_Shdr.
Rui Ueyamae8936bc2017-10-08 01:55:29 +000073 uint32_t Alignment;
Rafael Espindolab4c9b812017-02-23 02:28:28 +000074 uint64_t Flags;
Rafael Espindolab4c9b812017-02-23 02:28:28 +000075 uint64_t Entsize;
Rafael Espindola0e090522016-10-26 00:54:03 +000076 uint32_t Type;
77 uint32_t Link;
78 uint32_t Info;
79
Rafael Espindola5616adf2017-03-08 22:36:28 +000080 OutputSection *getOutputSection();
81 const OutputSection *getOutputSection() const {
82 return const_cast<SectionBase *>(this)->getOutputSection();
83 }
84
85 // Translate an offset in the input section to an offset in the output
86 // section.
87 uint64_t getOffset(uint64_t Offset) const;
88
89 uint64_t getOffset(const DefinedRegular &Sym) const;
90
91protected:
92 SectionBase(Kind SectionKind, StringRef Name, uint64_t Flags,
93 uint64_t Entsize, uint64_t Alignment, uint32_t Type,
94 uint32_t Info, uint32_t Link)
95 : Name(Name), SectionKind(SectionKind), Alignment(Alignment),
96 Flags(Flags), Entsize(Entsize), Type(Type), Link(Link), Info(Info) {
97 Live = false;
98 Assigned = false;
99 }
100};
101
102// This corresponds to a section of an input file.
103class InputSectionBase : public SectionBase {
104public:
Rafael Espindola042a3f22016-09-08 14:06:08 +0000105 InputSectionBase()
Rafael Espindola5616adf2017-03-08 22:36:28 +0000106 : SectionBase(Regular, "", /*Flags*/ 0, /*Entsize*/ 0, /*Alignment*/ 0,
107 /*Type*/ 0,
108 /*Info*/ 0, /*Link*/ 0),
109 Repl(this) {
Rafael Espindola9f0c4bb2016-11-10 14:53:24 +0000110 NumRelocations = 0;
111 AreRelocsRela = false;
112 }
Rafael Espindolaccfe3cb2016-04-04 14:04:16 +0000113
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000114 template <class ELFT>
Rui Ueyama709fb2bb12017-07-26 22:13:32 +0000115 InputSectionBase(ObjFile<ELFT> *File, const typename ELFT::Shdr *Header,
Rafael Espindola042a3f22016-09-08 14:06:08 +0000116 StringRef Name, Kind SectionKind);
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000117
118 InputSectionBase(InputFile *File, uint64_t Flags, uint32_t Type,
119 uint64_t Entsize, uint32_t Link, uint32_t Info,
Rafael Espindolafcd208f2017-03-08 19:35:29 +0000120 uint32_t Alignment, ArrayRef<uint8_t> Data, StringRef Name,
Rafael Espindola0e090522016-10-26 00:54:03 +0000121 Kind SectionKind);
Rafael Espindoladb5e56f2017-05-31 20:17:44 +0000122
Rui Ueyama124bedb2017-10-10 03:22:29 +0000123 static bool classof(const SectionBase *S) { return S->kind() != Output; }
124
125 // The file which contains this section. It's dynamic type is always
126 // ObjFile<ELFT>, but in order to avoid ELFT, we use InputFile as
127 // its static type.
128 InputFile *File;
129
130 template <class ELFT> ObjFile<ELFT> *getFile() const {
131 return cast_or_null<ObjFile<ELFT>>(File);
132 }
133
134 ArrayRef<uint8_t> Data;
135 uint64_t getOffsetInFile() const;
136
137 static InputSectionBase Discarded;
138
Rafael Espindoladb5e56f2017-05-31 20:17:44 +0000139 // Input sections are part of an output section. Special sections
140 // like .eh_frame and merge sections are first combined into a
141 // synthetic section that is then added to an output section. In all
142 // cases this points one level up.
143 SectionBase *Parent = nullptr;
Rui Ueyamac4aaed92015-10-22 18:49:53 +0000144
Rafael Espindola9f0c4bb2016-11-10 14:53:24 +0000145 // Relocations that refer to this section.
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000146 const void *FirstRelocation = nullptr;
Rafael Espindola9f0c4bb2016-11-10 14:53:24 +0000147 unsigned NumRelocations : 31;
148 unsigned AreRelocsRela : 1;
Rui Ueyama124bedb2017-10-10 03:22:29 +0000149
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000150 template <class ELFT> ArrayRef<typename ELFT::Rel> rels() const {
Rafael Espindola9f0c4bb2016-11-10 14:53:24 +0000151 assert(!AreRelocsRela);
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000152 return llvm::makeArrayRef(
153 static_cast<const typename ELFT::Rel *>(FirstRelocation),
154 NumRelocations);
Rafael Espindola9f0c4bb2016-11-10 14:53:24 +0000155 }
Rui Ueyama124bedb2017-10-10 03:22:29 +0000156
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000157 template <class ELFT> ArrayRef<typename ELFT::Rela> relas() const {
Rafael Espindola9f0c4bb2016-11-10 14:53:24 +0000158 assert(AreRelocsRela);
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000159 return llvm::makeArrayRef(
160 static_cast<const typename ELFT::Rela *>(FirstRelocation),
161 NumRelocations);
Rafael Espindola9f0c4bb2016-11-10 14:53:24 +0000162 }
163
Rui Ueyama0b289522016-02-25 18:43:51 +0000164 // This pointer points to the "real" instance of this instance.
165 // Usually Repl == this. However, if ICF merges two sections,
166 // Repl pointer of one section points to another section. So,
167 // if you need to get a pointer to this instance, do not use
168 // this but instead this->Repl.
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000169 InputSectionBase *Repl;
Rui Ueyama0b289522016-02-25 18:43:51 +0000170
George Rimar647c1682017-02-17 19:34:05 +0000171 // InputSections that are dependent on us (reverse dependency for GC)
Rui Ueyama05433432017-10-11 04:01:13 +0000172 llvm::TinyPtrVector<InputSection *> DependentSections;
George Rimar647c1682017-02-17 19:34:05 +0000173
Rafael Espindola1a541122016-11-08 14:47:16 +0000174 // Returns the size of this section (even if this is a common or BSS.)
Rafael Espindola76b6bd32017-03-08 15:44:30 +0000175 size_t getSize() const;
Rafael Espindola1a541122016-11-08 14:47:16 +0000176
Rafael Espindolab47c6e52017-05-31 19:09:52 +0000177 InputSection *getLinkOrderDep() const;
Rafael Espindoladb9bf4d2015-11-11 16:50:37 +0000178
Rui Ueyamaf987fe72017-10-10 03:40:57 +0000179 // Compilers emit zlib-compressed debug sections if the -gz option
180 // is given. This function checks if this section is compressed, and
181 // if so, decompress in memory.
Shoaib Meenai50d7b362017-10-04 00:19:41 +0000182 void maybeUncompress();
George Rimar602fbee2016-06-24 11:18:44 +0000183
Rui Ueyamada06bfb2016-11-25 18:51:53 +0000184 // Returns a source location string. Used to construct an error message.
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000185 template <class ELFT> std::string getLocation(uint64_t Offset);
Rui Ueyamab8760202017-03-30 19:13:47 +0000186 template <class ELFT> std::string getSrcMsg(uint64_t Offset);
187 template <class ELFT> std::string getObjMsg(uint64_t Offset);
Rui Ueyamada06bfb2016-11-25 18:51:53 +0000188
Rui Ueyamaf987fe72017-10-10 03:40:57 +0000189 // Each section knows how to relocate itself. These functions apply
190 // relocations, assuming that Buf points to this section's copy in
191 // the mmap'ed output buffer.
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000192 template <class ELFT> void relocate(uint8_t *Buf, uint8_t *BufEnd);
Rafael Espindolaa6465bb2017-05-18 16:45:36 +0000193 void relocateAlloc(uint8_t *Buf, uint8_t *BufEnd);
Rafael Espindolac404d502017-02-23 02:32:18 +0000194
Rui Ueyamaf987fe72017-10-10 03:40:57 +0000195 // The native ELF reloc data type is not very convenient to handle.
196 // So we convert ELF reloc records to our own records in Relocations.cpp.
197 // This vector contains such "cooked" relocations.
Rafael Espindolac404d502017-02-23 02:32:18 +0000198 std::vector<Relocation> Relocations;
199
200 template <typename T> llvm::ArrayRef<T> getDataAs() const {
201 size_t S = Data.size();
202 assert(S % sizeof(T) == 0);
203 return llvm::makeArrayRef<T>((const T *)Data.data(), S / sizeof(T));
204 }
Rui Ueyama314a0052017-08-17 00:27:55 +0000205
206private:
207 // A pointer that owns uncompressed data if a section is compressed by zlib.
208 // Since the feature is not used often, this is usually a nullptr.
Rafael Espindola17e93d22017-09-06 22:16:32 +0000209 std::unique_ptr<char[]> UncompressBuf;
Rafael Espindolac159c962015-10-19 21:00:02 +0000210};
211
Rui Ueyama3ea87272016-05-22 00:13:04 +0000212// SectionPiece represents a piece of splittable section contents.
Rafael Espindola113860b2016-10-20 10:55:58 +0000213// We allocate a lot of these and binary search on them. This means that they
214// have to be as compact as possible, which is why we don't store the size (can
215// be found by looking at the next one) and put the hash in a side table.
Rui Ueyama3ea87272016-05-22 00:13:04 +0000216struct SectionPiece {
Rui Ueyama95bf5092017-10-21 23:20:13 +0000217 SectionPiece(size_t Off, uint32_t Hash, bool Live)
218 : InputOff(Off), Hash(Hash), OutputOff(-1),
219 Live(Live || !Config->GcSections) {}
Rui Ueyama34dc99e2016-05-22 01:15:32 +0000220
Rui Ueyama95bf5092017-10-21 23:20:13 +0000221 uint32_t InputOff;
222 uint32_t Hash;
Konstantin Zhuravlyov70abb6e2017-10-23 19:31:31 +0000223 int64_t OutputOff : 63;
Rui Ueyama95bf5092017-10-21 23:20:13 +0000224 uint64_t Live : 1;
Rui Ueyama3ea87272016-05-22 00:13:04 +0000225};
Rui Ueyama95bf5092017-10-21 23:20:13 +0000226
227static_assert(sizeof(SectionPiece) == 16, "SectionPiece is too big");
Rui Ueyama3ea87272016-05-22 00:13:04 +0000228
Rafael Espindolac159c962015-10-19 21:00:02 +0000229// This corresponds to a SHF_MERGE section of an input file.
Rafael Espindola6119b862017-03-06 20:23:56 +0000230class MergeInputSection : public InputSectionBase {
Rafael Espindolac159c962015-10-19 21:00:02 +0000231public:
Rafael Espindola6119b862017-03-06 20:23:56 +0000232 template <class ELFT>
Rui Ueyama709fb2bb12017-07-26 22:13:32 +0000233 MergeInputSection(ObjFile<ELFT> *F, const typename ELFT::Shdr *Header,
Rafael Espindola042a3f22016-09-08 14:06:08 +0000234 StringRef Name);
Rui Ueyama43ca7162017-10-01 23:46:31 +0000235 static bool classof(const SectionBase *S) { return S->kind() == Merge; }
Rui Ueyamab91bf1a2016-05-23 16:55:43 +0000236 void splitIntoPieces();
237
238 // Mark the piece at a given offset live. Used by GC.
Rafael Espindola6119b862017-03-06 20:23:56 +0000239 void markLiveAt(uint64_t Offset) {
Rafael Espindola1854a8e2016-10-26 12:36:56 +0000240 assert(this->Flags & llvm::ELF::SHF_ALLOC);
Rafael Espindola116d83f2016-10-19 23:13:40 +0000241 LiveOffsets.insert(Offset);
242 }
Rui Ueyamab91bf1a2016-05-23 16:55:43 +0000243
244 // Translate an offset in the input section to an offset
245 // in the output section.
Rafael Espindola6119b862017-03-06 20:23:56 +0000246 uint64_t getOffset(uint64_t Offset) const;
Rui Ueyamab91bf1a2016-05-23 16:55:43 +0000247
Rafael Espindola6eae9f22016-07-21 13:32:37 +0000248 // Splittable sections are handled as a sequence of data
249 // rather than a single large blob of data.
250 std::vector<SectionPiece> Pieces;
Rui Ueyamac8e68842016-12-06 02:19:30 +0000251
252 // Returns I'th piece's data. This function is very hot when
253 // string merging is enabled, so we want to inline.
254 LLVM_ATTRIBUTE_ALWAYS_INLINE
255 llvm::CachedHashStringRef getData(size_t I) const {
256 size_t Begin = Pieces[I].InputOff;
Rui Ueyama95bf5092017-10-21 23:20:13 +0000257 size_t End =
258 (Pieces.size() - 1 == I) ? Data.size() : Pieces[I + 1].InputOff;
259 return {toStringRef(Data.slice(Begin, End - Begin)), Pieces[I].Hash};
Rui Ueyamac8e68842016-12-06 02:19:30 +0000260 }
Rafael Espindola6eae9f22016-07-21 13:32:37 +0000261
262 // Returns the SectionPiece at a given input section offset.
Rafael Espindola6119b862017-03-06 20:23:56 +0000263 SectionPiece *getSectionPiece(uint64_t Offset);
264 const SectionPiece *getSectionPiece(uint64_t Offset) const;
Rafael Espindola6eae9f22016-07-21 13:32:37 +0000265
Rafael Espindoladb5e56f2017-05-31 20:17:44 +0000266 SyntheticSection *getParent() const;
Rafael Espindola9e9754b2017-02-03 13:06:18 +0000267
Rui Ueyamab91bf1a2016-05-23 16:55:43 +0000268private:
Rui Ueyamae8a077b2016-11-26 15:15:11 +0000269 void splitStrings(ArrayRef<uint8_t> A, size_t Size);
270 void splitNonStrings(ArrayRef<uint8_t> A, size_t Size);
Rui Ueyamad6bd1372016-08-03 04:39:42 +0000271
Rafael Espindola6119b862017-03-06 20:23:56 +0000272 llvm::DenseSet<uint64_t> LiveOffsets;
Rafael Espindolac159c962015-10-19 21:00:02 +0000273};
274
Rui Ueyamae084aac2017-09-18 23:07:21 +0000275struct EhSectionPiece {
NAKAMURA Takumi169dbde2017-09-20 08:03:18 +0000276 EhSectionPiece(size_t Off, InputSectionBase *Sec, uint32_t Size,
277 unsigned FirstRelocation)
278 : InputOff(Off), Sec(Sec), Size(Size), FirstRelocation(FirstRelocation) {}
Rafael Espindola113860b2016-10-20 10:55:58 +0000279
NAKAMURA Takumi169dbde2017-09-20 08:03:18 +0000280 ArrayRef<uint8_t> data() { return {Sec->Data.data() + this->InputOff, Size}; }
281
282 size_t InputOff;
283 ssize_t OutputOff = -1;
284 InputSectionBase *Sec;
Rui Ueyamae084aac2017-09-18 23:07:21 +0000285 uint32_t Size;
NAKAMURA Takumi169dbde2017-09-20 08:03:18 +0000286 unsigned FirstRelocation;
Rafael Espindola2deeb602016-07-21 20:18:30 +0000287};
288
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000289// This corresponds to a .eh_frame section of an input file.
Rafael Espindola5c02b742017-03-06 21:17:18 +0000290class EhInputSection : public InputSectionBase {
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000291public:
Rafael Espindola5c02b742017-03-06 21:17:18 +0000292 template <class ELFT>
Rui Ueyama709fb2bb12017-07-26 22:13:32 +0000293 EhInputSection(ObjFile<ELFT> *F, const typename ELFT::Shdr *Header,
Rafael Espindola5c02b742017-03-06 21:17:18 +0000294 StringRef Name);
Rui Ueyama43ca7162017-10-01 23:46:31 +0000295 static bool classof(const SectionBase *S) { return S->kind() == EHFrame; }
Rafael Espindola5c02b742017-03-06 21:17:18 +0000296 template <class ELFT> void split();
297 template <class ELFT, class RelTy> void split(ArrayRef<RelTy> Rels);
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000298
Rafael Espindola6eae9f22016-07-21 13:32:37 +0000299 // Splittable sections are handled as a sequence of data
300 // rather than a single large blob of data.
Rafael Espindola2deeb602016-07-21 20:18:30 +0000301 std::vector<EhSectionPiece> Pieces;
Rafael Espindoladb5e56f2017-05-31 20:17:44 +0000302
303 SyntheticSection *getParent() const;
Rafael Espindola0c6a4f12015-11-11 19:54:14 +0000304};
305
Rafael Espindola798ad9a2017-02-24 13:06:59 +0000306// This is a section that is added directly to an output section
307// instead of needing special combination via a synthetic section. This
308// includes all input sections with the exceptions of SHF_MERGE and
309// .eh_frame. It also includes the synthetic sections themselves.
Rafael Espindola774ea7d2017-02-23 16:49:07 +0000310class InputSection : public InputSectionBase {
Rafael Espindolac159c962015-10-19 21:00:02 +0000311public:
Rafael Espindolafcd208f2017-03-08 19:35:29 +0000312 InputSection(uint64_t Flags, uint32_t Type, uint32_t Alignment,
Rafael Espindolac404d502017-02-23 02:32:18 +0000313 ArrayRef<uint8_t> Data, StringRef Name, Kind K = Regular);
Rafael Espindola774ea7d2017-02-23 16:49:07 +0000314 template <class ELFT>
Rui Ueyama709fb2bb12017-07-26 22:13:32 +0000315 InputSection(ObjFile<ELFT> *F, const typename ELFT::Shdr *Header,
Rafael Espindola774ea7d2017-02-23 16:49:07 +0000316 StringRef Name);
Rafael Espindolac159c962015-10-19 21:00:02 +0000317
318 // Write this section to a mmap'ed file, assuming Buf is pointing to
319 // beginning of the output section.
Rafael Espindola774ea7d2017-02-23 16:49:07 +0000320 template <class ELFT> void writeTo(uint8_t *Buf);
Rafael Espindolac159c962015-10-19 21:00:02 +0000321
Rafael Espindoladb5e56f2017-05-31 20:17:44 +0000322 OutputSection *getParent() const;
323
Rui Ueyamaedffd912015-10-14 21:00:23 +0000324 // The offset from beginning of the output sections this section was assigned
325 // to. The writer sets a value.
Rui Ueyama55c3f892015-10-15 01:58:40 +0000326 uint64_t OutSecOff = 0;
Rui Ueyamaedffd912015-10-14 21:00:23 +0000327
Rafael Espindola5616adf2017-03-08 22:36:28 +0000328 static bool classof(const SectionBase *S);
George Rimar58941ee2016-02-25 08:23:37 +0000329
George Rimar1ec03e42017-03-21 09:13:27 +0000330 InputSectionBase *getRelocatedSection();
George Rimar58941ee2016-02-25 08:23:37 +0000331
Rafael Espindola774ea7d2017-02-23 16:49:07 +0000332 template <class ELFT, class RelTy>
Rui Ueyama2b6fb802016-04-28 18:42:04 +0000333 void relocateNonAlloc(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);
334
Rui Ueyamabd1f0632016-11-20 02:39:59 +0000335 // Used by ICF.
Rui Ueyamafcd3fa82016-12-05 18:11:35 +0000336 uint32_t Class[2] = {0, 0};
Rui Ueyama0b289522016-02-25 18:43:51 +0000337
338 // Called by ICF to merge two input sections.
Rafael Espindola774ea7d2017-02-23 16:49:07 +0000339 void replace(InputSection *Other);
Rui Ueyama0b289522016-02-25 18:43:51 +0000340
Rui Ueyamabd1f0632016-11-20 02:39:59 +0000341private:
Rafael Espindola774ea7d2017-02-23 16:49:07 +0000342 template <class ELFT, class RelTy>
Rui Ueyamabd1f0632016-11-20 02:39:59 +0000343 void copyRelocations(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);
George Rimar3b189d12017-05-29 08:37:50 +0000344
Rui Ueyamaf08b38c2017-06-09 03:19:08 +0000345 template <class ELFT> void copyShtGroup(uint8_t *Buf);
Michael J. Spencer84487f12015-07-24 21:03:07 +0000346};
347
Rui Ueyama536a2672017-02-27 02:32:08 +0000348// The list of all input sections.
349extern std::vector<InputSectionBase *> InputSections;
350
George Rimard6bcde32017-08-04 10:25:29 +0000351// Builds section order for handling --symbol-ordering-file.
George Rimar696a7f92017-09-19 09:20:54 +0000352llvm::DenseMap<SectionBase *, int> buildSectionOrder();
George Rimard6bcde32017-08-04 10:25:29 +0000353
Rafael Espindolae0df00b2016-02-28 00:25:54 +0000354} // namespace elf
Rui Ueyamace039262017-01-06 10:04:08 +0000355
Rafael Espindolab4c9b812017-02-23 02:28:28 +0000356std::string toString(const elf::InputSectionBase *);
Michael J. Spencer84487f12015-07-24 21:03:07 +0000357} // namespace lld
358
359#endif