Rafael Espindola | 9d06ab6 | 2015-09-22 00:01:39 +0000 | [diff] [blame] | 1 | //===- InputSection.h -------------------------------------------*- C++ -*-===// |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 2 | // |
| 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 Espindola | 9d06ab6 | 2015-09-22 00:01:39 +0000 | [diff] [blame] | 10 | #ifndef LLD_ELF_INPUT_SECTION_H |
| 11 | #define LLD_ELF_INPUT_SECTION_H |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 12 | |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame] | 13 | #include "Config.h" |
Rui Ueyama | 0fcdc73 | 2016-05-24 20:24:43 +0000 | [diff] [blame] | 14 | #include "Relocations.h" |
Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 15 | #include "Thunks.h" |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 16 | #include "lld/Core/LLVM.h" |
Rui Ueyama | b91bf1a | 2016-05-23 16:55:43 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseSet.h" |
Rui Ueyama | c00718f | 2016-02-23 03:34:37 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/TinyPtrVector.h" |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 19 | #include "llvm/Object/ELF.h" |
| 20 | |
| 21 | namespace lld { |
Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 22 | namespace elf { |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 23 | |
Rafael Espindola | 38c67a2 | 2016-04-15 14:41:56 +0000 | [diff] [blame] | 24 | class SymbolBody; |
| 25 | |
Rui Ueyama | 0b28952 | 2016-02-25 18:43:51 +0000 | [diff] [blame] | 26 | template <class ELFT> class ICF; |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 27 | template <class ELFT> class DefinedRegular; |
Eugene Leviant | 3e6b027 | 2016-07-28 19:24:13 +0000 | [diff] [blame] | 28 | template <class ELFT> class DefinedCommon; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 29 | template <class ELFT> class ObjectFile; |
Rafael Espindola | 832b93f | 2015-08-24 20:06:32 +0000 | [diff] [blame] | 30 | template <class ELFT> class OutputSection; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 31 | template <class ELFT> class OutputSectionBase; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 32 | |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 33 | // This corresponds to a section of an input file. |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 34 | template <class ELFT> class InputSectionBase { |
| 35 | protected: |
Rui Ueyama | 1d12ac1 | 2016-07-07 03:55:55 +0000 | [diff] [blame] | 36 | typedef typename ELFT::Chdr Elf_Chdr; |
Rafael Espindola | 197d6a8 | 2016-04-22 16:39:59 +0000 | [diff] [blame] | 37 | typedef typename ELFT::Rel Elf_Rel; |
| 38 | typedef typename ELFT::Rela Elf_Rela; |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 39 | typedef typename ELFT::Shdr Elf_Shdr; |
| 40 | typedef typename ELFT::Sym Elf_Sym; |
| 41 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 42 | const Elf_Shdr *Header; |
| 43 | |
| 44 | // The file this section is from. |
| 45 | ObjectFile<ELFT> *File; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 46 | |
George Rimar | 602fbee | 2016-06-24 11:18:44 +0000 | [diff] [blame] | 47 | // If a section is compressed, this vector has uncompressed section data. |
| 48 | SmallVector<char, 0> Uncompressed; |
| 49 | |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 50 | public: |
Simon Atanasyan | 85c6b44 | 2016-08-12 06:28:49 +0000 | [diff] [blame^] | 51 | enum Kind { |
| 52 | Regular, |
| 53 | EHFrame, |
| 54 | Merge, |
| 55 | MipsReginfo, |
| 56 | MipsOptions, |
| 57 | MipsAbiFlags, |
| 58 | Layout |
| 59 | }; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 60 | Kind SectionKind; |
| 61 | |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 62 | InputSectionBase() : Repl(this) {} |
| 63 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 64 | InputSectionBase(ObjectFile<ELFT> *File, const Elf_Shdr *Header, |
| 65 | Kind SectionKind); |
| 66 | OutputSectionBase<ELFT> *OutSec = nullptr; |
Rui Ueyama | 424b408 | 2016-06-17 01:18:46 +0000 | [diff] [blame] | 67 | uint32_t Alignment; |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 68 | |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame] | 69 | // Used for garbage collection. |
Rui Ueyama | 6a9ef85 | 2016-02-25 18:49:09 +0000 | [diff] [blame] | 70 | bool Live; |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame] | 71 | |
Rui Ueyama | 0b28952 | 2016-02-25 18:43:51 +0000 | [diff] [blame] | 72 | // This pointer points to the "real" instance of this instance. |
| 73 | // Usually Repl == this. However, if ICF merges two sections, |
| 74 | // Repl pointer of one section points to another section. So, |
| 75 | // if you need to get a pointer to this instance, do not use |
| 76 | // this but instead this->Repl. |
| 77 | InputSectionBase<ELFT> *Repl; |
| 78 | |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 79 | // Returns the size of this section (even if this is a common or BSS.) |
Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 80 | size_t getSize() const; |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 81 | |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 82 | static InputSectionBase<ELFT> Discarded; |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 83 | |
Rafael Espindola | 5d83ccd | 2015-08-13 19:18:30 +0000 | [diff] [blame] | 84 | StringRef getSectionName() const; |
Michael J. Spencer | 8039dae2 | 2015-07-29 00:30:10 +0000 | [diff] [blame] | 85 | const Elf_Shdr *getSectionHdr() const { return Header; } |
Rafael Espindola | e1901cc | 2015-09-24 15:11:50 +0000 | [diff] [blame] | 86 | ObjectFile<ELFT> *getFile() const { return File; } |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 87 | uintX_t getOffset(const DefinedRegular<ELFT> &Sym) const; |
Rafael Espindola | db9bf4d | 2015-11-11 16:50:37 +0000 | [diff] [blame] | 88 | |
| 89 | // Translate an offset in the input section to an offset in the output |
| 90 | // section. |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 91 | uintX_t getOffset(uintX_t Offset) const; |
Rafael Espindola | db9bf4d | 2015-11-11 16:50:37 +0000 | [diff] [blame] | 92 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 93 | ArrayRef<uint8_t> getSectionData() const; |
Rui Ueyama | 1250464 | 2015-10-27 21:51:13 +0000 | [diff] [blame] | 94 | |
George Rimar | 602fbee | 2016-06-24 11:18:44 +0000 | [diff] [blame] | 95 | void uncompress(); |
| 96 | |
Rafael Espindola | 22ef956 | 2016-04-13 01:40:19 +0000 | [diff] [blame] | 97 | void relocate(uint8_t *Buf, uint8_t *BufEnd); |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 98 | std::vector<Relocation<ELFT>> Relocations; |
George Rimar | 602fbee | 2016-06-24 11:18:44 +0000 | [diff] [blame] | 99 | |
| 100 | bool Compressed; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 103 | template <class ELFT> InputSectionBase<ELFT> InputSectionBase<ELFT>::Discarded; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 104 | |
Rui Ueyama | 3ea8727 | 2016-05-22 00:13:04 +0000 | [diff] [blame] | 105 | // SectionPiece represents a piece of splittable section contents. |
| 106 | struct SectionPiece { |
Rui Ueyama | 34dc99e | 2016-05-22 01:15:32 +0000 | [diff] [blame] | 107 | SectionPiece(size_t Off, ArrayRef<uint8_t> Data) |
Davide Italiano | e6c8fa4 | 2016-05-28 23:27:38 +0000 | [diff] [blame] | 108 | : InputOff(Off), Data((const uint8_t *)Data.data()), Size(Data.size()), |
Rui Ueyama | d884927 | 2016-05-25 16:37:01 +0000 | [diff] [blame] | 109 | Live(!Config->GcSections) {} |
| 110 | |
| 111 | ArrayRef<uint8_t> data() { return {Data, Size}; } |
| 112 | size_t size() const { return Size; } |
Rui Ueyama | 34dc99e | 2016-05-22 01:15:32 +0000 | [diff] [blame] | 113 | |
Rui Ueyama | 3ea8727 | 2016-05-22 00:13:04 +0000 | [diff] [blame] | 114 | size_t InputOff; |
| 115 | size_t OutputOff = -1; |
Rui Ueyama | d884927 | 2016-05-25 16:37:01 +0000 | [diff] [blame] | 116 | |
| 117 | private: |
| 118 | // We use bitfields because SplitInputSection is accessed by |
| 119 | // std::upper_bound very often. |
| 120 | // We want to save bits to make it cache friendly. |
Davide Italiano | e6c8fa4 | 2016-05-28 23:27:38 +0000 | [diff] [blame] | 121 | const uint8_t *Data; |
Rui Ueyama | d884927 | 2016-05-25 16:37:01 +0000 | [diff] [blame] | 122 | uint32_t Size : 31; |
| 123 | |
| 124 | public: |
| 125 | uint32_t Live : 1; |
Rui Ueyama | 3ea8727 | 2016-05-22 00:13:04 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 128 | // This corresponds to a SHF_MERGE section of an input file. |
Rafael Espindola | 6eae9f2 | 2016-07-21 13:32:37 +0000 | [diff] [blame] | 129 | template <class ELFT> class MergeInputSection : public InputSectionBase<ELFT> { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 130 | typedef typename ELFT::uint uintX_t; |
| 131 | typedef typename ELFT::Sym Elf_Sym; |
| 132 | typedef typename ELFT::Shdr Elf_Shdr; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 133 | |
| 134 | public: |
| 135 | MergeInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header); |
| 136 | static bool classof(const InputSectionBase<ELFT> *S); |
Rui Ueyama | b91bf1a | 2016-05-23 16:55:43 +0000 | [diff] [blame] | 137 | void splitIntoPieces(); |
| 138 | |
| 139 | // Mark the piece at a given offset live. Used by GC. |
| 140 | void markLiveAt(uintX_t Offset) { LiveOffsets.insert(Offset); } |
| 141 | |
| 142 | // Translate an offset in the input section to an offset |
| 143 | // in the output section. |
Rui Ueyama | 809d8e2 | 2016-06-23 04:33:42 +0000 | [diff] [blame] | 144 | uintX_t getOffset(uintX_t Offset) const; |
Rui Ueyama | b91bf1a | 2016-05-23 16:55:43 +0000 | [diff] [blame] | 145 | |
Rui Ueyama | 406b469 | 2016-05-27 14:39:13 +0000 | [diff] [blame] | 146 | void finalizePieces(); |
| 147 | |
Rafael Espindola | 6eae9f2 | 2016-07-21 13:32:37 +0000 | [diff] [blame] | 148 | // Splittable sections are handled as a sequence of data |
| 149 | // rather than a single large blob of data. |
| 150 | std::vector<SectionPiece> Pieces; |
| 151 | |
| 152 | // Returns the SectionPiece at a given input section offset. |
| 153 | SectionPiece *getSectionPiece(uintX_t Offset); |
| 154 | const SectionPiece *getSectionPiece(uintX_t Offset) const; |
| 155 | |
Rui Ueyama | b91bf1a | 2016-05-23 16:55:43 +0000 | [diff] [blame] | 156 | private: |
Rui Ueyama | d6bd137 | 2016-08-03 04:39:42 +0000 | [diff] [blame] | 157 | std::vector<SectionPiece> splitStrings(ArrayRef<uint8_t> A, size_t Size); |
| 158 | std::vector<SectionPiece> splitNonStrings(ArrayRef<uint8_t> A, size_t Size); |
| 159 | |
Rui Ueyama | 406b469 | 2016-05-27 14:39:13 +0000 | [diff] [blame] | 160 | llvm::DenseMap<uintX_t, uintX_t> OffsetMap; |
Rui Ueyama | b91bf1a | 2016-05-23 16:55:43 +0000 | [diff] [blame] | 161 | llvm::DenseSet<uintX_t> LiveOffsets; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 162 | }; |
| 163 | |
Rafael Espindola | 2deeb60 | 2016-07-21 20:18:30 +0000 | [diff] [blame] | 164 | struct EhSectionPiece : public SectionPiece { |
| 165 | EhSectionPiece(size_t Off, ArrayRef<uint8_t> Data, unsigned FirstRelocation) |
| 166 | : SectionPiece(Off, Data), FirstRelocation(FirstRelocation) {} |
| 167 | unsigned FirstRelocation; |
| 168 | }; |
| 169 | |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 170 | // This corresponds to a .eh_frame section of an input file. |
Rafael Espindola | 6eae9f2 | 2016-07-21 13:32:37 +0000 | [diff] [blame] | 171 | template <class ELFT> class EhInputSection : public InputSectionBase<ELFT> { |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 172 | public: |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 173 | typedef typename ELFT::Shdr Elf_Shdr; |
| 174 | typedef typename ELFT::uint uintX_t; |
Rui Ueyama | 0b9a903 | 2016-05-24 04:19:20 +0000 | [diff] [blame] | 175 | EhInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header); |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 176 | static bool classof(const InputSectionBase<ELFT> *S); |
Rui Ueyama | 88abd9b | 2016-05-22 23:53:00 +0000 | [diff] [blame] | 177 | void split(); |
Rafael Espindola | 2deeb60 | 2016-07-21 20:18:30 +0000 | [diff] [blame] | 178 | template <class RelTy> void split(ArrayRef<RelTy> Rels); |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 179 | |
Rafael Espindola | 6eae9f2 | 2016-07-21 13:32:37 +0000 | [diff] [blame] | 180 | // Splittable sections are handled as a sequence of data |
| 181 | // rather than a single large blob of data. |
Rafael Espindola | 2deeb60 | 2016-07-21 20:18:30 +0000 | [diff] [blame] | 182 | std::vector<EhSectionPiece> Pieces; |
Rafael Espindola | 6eae9f2 | 2016-07-21 13:32:37 +0000 | [diff] [blame] | 183 | |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 184 | // Relocation section that refer to this one. |
| 185 | const Elf_Shdr *RelocSection = nullptr; |
| 186 | }; |
| 187 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 188 | // This corresponds to a non SHF_MERGE section of an input file. |
| 189 | template <class ELFT> class InputSection : public InputSectionBase<ELFT> { |
Rui Ueyama | 0b28952 | 2016-02-25 18:43:51 +0000 | [diff] [blame] | 190 | friend ICF<ELFT>; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 191 | typedef InputSectionBase<ELFT> Base; |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 192 | typedef typename ELFT::Shdr Elf_Shdr; |
| 193 | typedef typename ELFT::Rela Elf_Rela; |
| 194 | typedef typename ELFT::Rel Elf_Rel; |
| 195 | typedef typename ELFT::Sym Elf_Sym; |
| 196 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 197 | |
| 198 | public: |
| 199 | InputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header); |
| 200 | |
| 201 | // Write this section to a mmap'ed file, assuming Buf is pointing to |
| 202 | // beginning of the output section. |
| 203 | void writeTo(uint8_t *Buf); |
| 204 | |
Michael J. Spencer | 67bc8d6 | 2015-08-27 23:15:56 +0000 | [diff] [blame] | 205 | // Relocation sections that refer to this one. |
Rui Ueyama | c00718f | 2016-02-23 03:34:37 +0000 | [diff] [blame] | 206 | llvm::TinyPtrVector<const Elf_Shdr *> RelocSections; |
Michael J. Spencer | 67bc8d6 | 2015-08-27 23:15:56 +0000 | [diff] [blame] | 207 | |
Rui Ueyama | edffd91 | 2015-10-14 21:00:23 +0000 | [diff] [blame] | 208 | // The offset from beginning of the output sections this section was assigned |
| 209 | // to. The writer sets a value. |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 210 | uint64_t OutSecOff = 0; |
Rui Ueyama | edffd91 | 2015-10-14 21:00:23 +0000 | [diff] [blame] | 211 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 212 | static bool classof(const InputSectionBase<ELFT> *S); |
George Rimar | 58941ee | 2016-02-25 08:23:37 +0000 | [diff] [blame] | 213 | |
| 214 | InputSectionBase<ELFT> *getRelocatedSection(); |
| 215 | |
Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 216 | // Register thunk related to the symbol. When the section is written |
| 217 | // to a mmap'ed file, target is requested to write an actual thunk code. |
Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 218 | // Now thunks is supported for MIPS and ARM target only. |
| 219 | void addThunk(const Thunk<ELFT> *T); |
Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 220 | |
| 221 | // The offset of synthetic thunk code from beginning of this section. |
| 222 | uint64_t getThunkOff() const; |
| 223 | |
| 224 | // Size of chunk with thunks code. |
| 225 | uint64_t getThunksSize() const; |
| 226 | |
Rui Ueyama | 2b6fb80 | 2016-04-28 18:42:04 +0000 | [diff] [blame] | 227 | template <class RelTy> |
| 228 | void relocateNonAlloc(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels); |
| 229 | |
George Rimar | 58941ee | 2016-02-25 08:23:37 +0000 | [diff] [blame] | 230 | private: |
Rui Ueyama | fc467e7 | 2016-03-13 05:06:50 +0000 | [diff] [blame] | 231 | template <class RelTy> |
Rafael Espindola | 0f7ccc3 | 2016-04-05 14:47:28 +0000 | [diff] [blame] | 232 | void copyRelocations(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels); |
Rui Ueyama | 0b28952 | 2016-02-25 18:43:51 +0000 | [diff] [blame] | 233 | |
| 234 | // Called by ICF to merge two input sections. |
| 235 | void replace(InputSection<ELFT> *Other); |
| 236 | |
| 237 | // Used by ICF. |
| 238 | uint64_t GroupId = 0; |
Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 239 | |
Peter Smith | fb05cd9 | 2016-07-08 16:10:27 +0000 | [diff] [blame] | 240 | llvm::TinyPtrVector<const Thunk<ELFT> *> Thunks; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 241 | }; |
| 242 | |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 243 | // MIPS .reginfo section provides information on the registers used by the code |
| 244 | // in the object file. Linker should collect this information and write a single |
| 245 | // .reginfo section in the output file. The output section contains a union of |
| 246 | // used registers masks taken from input .reginfo sections and final value |
| 247 | // of the `_gp` symbol. For details: Chapter 4 / "Register Information" at |
| 248 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
| 249 | template <class ELFT> |
| 250 | class MipsReginfoInputSection : public InputSectionBase<ELFT> { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 251 | typedef typename ELFT::Shdr Elf_Shdr; |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 252 | |
| 253 | public: |
Rui Ueyama | 70eed36 | 2016-01-06 22:42:43 +0000 | [diff] [blame] | 254 | MipsReginfoInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Hdr); |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 255 | static bool classof(const InputSectionBase<ELFT> *S); |
Rui Ueyama | 70eed36 | 2016-01-06 22:42:43 +0000 | [diff] [blame] | 256 | |
Simon Atanasyan | add74f3 | 2016-05-04 10:07:38 +0000 | [diff] [blame] | 257 | const llvm::object::Elf_Mips_RegInfo<ELFT> *Reginfo = nullptr; |
| 258 | }; |
| 259 | |
| 260 | template <class ELFT> |
| 261 | class MipsOptionsInputSection : public InputSectionBase<ELFT> { |
| 262 | typedef typename ELFT::Shdr Elf_Shdr; |
| 263 | |
| 264 | public: |
| 265 | MipsOptionsInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Hdr); |
| 266 | static bool classof(const InputSectionBase<ELFT> *S); |
| 267 | |
| 268 | const llvm::object::Elf_Mips_RegInfo<ELFT> *Reginfo = nullptr; |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 269 | }; |
| 270 | |
Simon Atanasyan | 85c6b44 | 2016-08-12 06:28:49 +0000 | [diff] [blame^] | 271 | template <class ELFT> |
| 272 | class MipsAbiFlagsInputSection : public InputSectionBase<ELFT> { |
| 273 | typedef typename ELFT::Shdr Elf_Shdr; |
| 274 | |
| 275 | public: |
| 276 | MipsAbiFlagsInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Hdr); |
| 277 | static bool classof(const InputSectionBase<ELFT> *S); |
| 278 | |
| 279 | const llvm::object::Elf_Mips_ABIFlags<ELFT> *Flags = nullptr; |
| 280 | }; |
| 281 | |
Rui Ueyama | ad10c3d | 2016-07-28 21:05:04 +0000 | [diff] [blame] | 282 | // Common symbols don't belong to any section. But it is easier for us |
| 283 | // to handle them as if they belong to some input section. So we defined |
| 284 | // this class. CommonInputSection is a virtual singleton class that |
| 285 | // "contains" all common symbols. |
Eugene Leviant | 3e6b027 | 2016-07-28 19:24:13 +0000 | [diff] [blame] | 286 | template <class ELFT> class CommonInputSection : public InputSection<ELFT> { |
| 287 | typedef typename ELFT::uint uintX_t; |
| 288 | |
| 289 | public: |
Rui Ueyama | 09d4f17 | 2016-07-29 03:39:44 +0000 | [diff] [blame] | 290 | CommonInputSection(std::vector<DefinedCommon<ELFT> *> Syms); |
Eugene Leviant | 3e6b027 | 2016-07-28 19:24:13 +0000 | [diff] [blame] | 291 | |
Rui Ueyama | ad10c3d | 2016-07-28 21:05:04 +0000 | [diff] [blame] | 292 | // The singleton instance of this class. |
| 293 | static CommonInputSection<ELFT> *X; |
| 294 | |
Eugene Leviant | 3e6b027 | 2016-07-28 19:24:13 +0000 | [diff] [blame] | 295 | private: |
Rui Ueyama | ad10c3d | 2016-07-28 21:05:04 +0000 | [diff] [blame] | 296 | static typename ELFT::Shdr Hdr; |
Eugene Leviant | 3e6b027 | 2016-07-28 19:24:13 +0000 | [diff] [blame] | 297 | }; |
| 298 | |
Rui Ueyama | ad10c3d | 2016-07-28 21:05:04 +0000 | [diff] [blame] | 299 | template <class ELFT> CommonInputSection<ELFT> *CommonInputSection<ELFT>::X; |
| 300 | template <class ELFT> typename ELFT::Shdr CommonInputSection<ELFT>::Hdr; |
| 301 | |
Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 302 | } // namespace elf |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 303 | } // namespace lld |
| 304 | |
| 305 | #endif |