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" |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 14 | #include "lld/Core/LLVM.h" |
Rui Ueyama | b91bf1a | 2016-05-23 16:55:43 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/DenseSet.h" |
Rui Ueyama | c00718f | 2016-02-23 03:34:37 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/TinyPtrVector.h" |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 17 | #include "llvm/Object/ELF.h" |
| 18 | |
| 19 | namespace lld { |
Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 20 | namespace elf { |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 21 | |
Rafael Espindola | 38c67a2 | 2016-04-15 14:41:56 +0000 | [diff] [blame] | 22 | class SymbolBody; |
| 23 | |
Rui Ueyama | 0b28952 | 2016-02-25 18:43:51 +0000 | [diff] [blame] | 24 | template <class ELFT> class ICF; |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 25 | template <class ELFT> class DefinedRegular; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 26 | template <class ELFT> class ObjectFile; |
Rafael Espindola | 832b93f | 2015-08-24 20:06:32 +0000 | [diff] [blame] | 27 | template <class ELFT> class OutputSection; |
Rui Ueyama | c7cc6ec | 2015-10-15 22:27:29 +0000 | [diff] [blame] | 28 | template <class ELFT> class OutputSectionBase; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 29 | |
Rafael Espindola | 22ef956 | 2016-04-13 01:40:19 +0000 | [diff] [blame] | 30 | enum RelExpr { |
| 31 | R_ABS, |
| 32 | R_GOT, |
Rafael Espindola | 3f5d634 | 2016-04-18 12:07:13 +0000 | [diff] [blame] | 33 | R_GOTONLY_PC, |
| 34 | R_GOTREL, |
| 35 | R_GOT_FROM_END, |
Rafael Espindola | de2c76e | 2016-05-04 14:38:55 +0000 | [diff] [blame] | 36 | R_GOT_OFF, |
Rafael Espindola | 22ef956 | 2016-04-13 01:40:19 +0000 | [diff] [blame] | 37 | R_GOT_PAGE_PC, |
| 38 | R_GOT_PC, |
Rafael Espindola | ebb04b9 | 2016-05-04 14:44:22 +0000 | [diff] [blame] | 39 | R_HINT, |
Rafael Espindola | 22ef956 | 2016-04-13 01:40:19 +0000 | [diff] [blame] | 40 | R_MIPS_GOT_LOCAL, |
Simon Atanasyan | 4e3a15c | 2016-05-15 18:13:50 +0000 | [diff] [blame] | 41 | R_MIPS_GOT_LOCAL_PAGE, |
Rafael Espindola | 3f5d634 | 2016-04-18 12:07:13 +0000 | [diff] [blame] | 42 | R_NEG_TLS, |
Rafael Espindola | 22ef956 | 2016-04-13 01:40:19 +0000 | [diff] [blame] | 43 | R_PAGE_PC, |
| 44 | R_PC, |
| 45 | R_PLT, |
| 46 | R_PLT_PC, |
| 47 | R_PPC_OPD, |
| 48 | R_PPC_PLT_OPD, |
| 49 | R_PPC_TOC, |
| 50 | R_RELAX_TLS_GD_TO_IE, |
Rafael Espindola | 22ef956 | 2016-04-13 01:40:19 +0000 | [diff] [blame] | 51 | R_RELAX_TLS_GD_TO_LE, |
| 52 | R_RELAX_TLS_IE_TO_LE, |
| 53 | R_RELAX_TLS_LD_TO_LE, |
| 54 | R_SIZE, |
| 55 | R_THUNK, |
Rafael Espindola | 3f5d634 | 2016-04-18 12:07:13 +0000 | [diff] [blame] | 56 | R_TLS, |
Rafael Espindola | 22ef956 | 2016-04-13 01:40:19 +0000 | [diff] [blame] | 57 | R_TLSGD, |
| 58 | R_TLSGD_PC, |
| 59 | R_TLSLD, |
| 60 | R_TLSLD_PC |
| 61 | }; |
| 62 | |
Rafael Espindola | c6b17bd | 2016-04-20 17:30:22 +0000 | [diff] [blame] | 63 | inline bool refersToGotEntry(RelExpr Expr) { |
Simon Atanasyan | 4e3a15c | 2016-05-15 18:13:50 +0000 | [diff] [blame] | 64 | return Expr == R_GOT || Expr == R_GOT_OFF || Expr == R_MIPS_GOT_LOCAL || |
| 65 | Expr == R_MIPS_GOT_LOCAL_PAGE || Expr == R_GOT_PAGE_PC || |
Rafael Espindola | a85efd9 | 2016-04-30 01:15:17 +0000 | [diff] [blame] | 66 | Expr == R_GOT_PC || Expr == R_GOT_FROM_END || Expr == R_TLSGD || |
| 67 | Expr == R_TLSGD_PC; |
Rafael Espindola | c6b17bd | 2016-04-20 17:30:22 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Rafael Espindola | 22ef956 | 2016-04-13 01:40:19 +0000 | [diff] [blame] | 70 | struct Relocation { |
| 71 | RelExpr Expr; |
| 72 | uint32_t Type; |
| 73 | uint64_t Offset; |
| 74 | uint64_t Addend; |
| 75 | SymbolBody *Sym; |
| 76 | }; |
| 77 | |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 78 | // This corresponds to a section of an input file. |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 79 | template <class ELFT> class InputSectionBase { |
| 80 | protected: |
Rafael Espindola | 197d6a8 | 2016-04-22 16:39:59 +0000 | [diff] [blame] | 81 | typedef typename ELFT::Rel Elf_Rel; |
| 82 | typedef typename ELFT::Rela Elf_Rela; |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 83 | typedef typename ELFT::Shdr Elf_Shdr; |
| 84 | typedef typename ELFT::Sym Elf_Sym; |
| 85 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 86 | const Elf_Shdr *Header; |
| 87 | |
| 88 | // The file this section is from. |
| 89 | ObjectFile<ELFT> *File; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Simon Atanasyan | add74f3 | 2016-05-04 10:07:38 +0000 | [diff] [blame] | 92 | enum Kind { Regular, EHFrame, Merge, MipsReginfo, MipsOptions }; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 93 | Kind SectionKind; |
| 94 | |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 95 | InputSectionBase() : Repl(this) {} |
| 96 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 97 | InputSectionBase(ObjectFile<ELFT> *File, const Elf_Shdr *Header, |
| 98 | Kind SectionKind); |
| 99 | OutputSectionBase<ELFT> *OutSec = nullptr; |
Rui Ueyama | 6a9ef85 | 2016-02-25 18:49:09 +0000 | [diff] [blame] | 100 | uint32_t Align; |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 101 | |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame] | 102 | // Used for garbage collection. |
Rui Ueyama | 6a9ef85 | 2016-02-25 18:49:09 +0000 | [diff] [blame] | 103 | bool Live; |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame] | 104 | |
Rui Ueyama | 0b28952 | 2016-02-25 18:43:51 +0000 | [diff] [blame] | 105 | // This pointer points to the "real" instance of this instance. |
| 106 | // Usually Repl == this. However, if ICF merges two sections, |
| 107 | // Repl pointer of one section points to another section. So, |
| 108 | // if you need to get a pointer to this instance, do not use |
| 109 | // this but instead this->Repl. |
| 110 | InputSectionBase<ELFT> *Repl; |
| 111 | |
Rafael Espindola | 7167585 | 2015-09-22 00:16:19 +0000 | [diff] [blame] | 112 | // 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] | 113 | size_t getSize() const; |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 114 | |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 115 | static InputSectionBase<ELFT> Discarded; |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 116 | |
Rafael Espindola | 5d83ccd | 2015-08-13 19:18:30 +0000 | [diff] [blame] | 117 | StringRef getSectionName() const; |
Michael J. Spencer | 8039dae2 | 2015-07-29 00:30:10 +0000 | [diff] [blame] | 118 | const Elf_Shdr *getSectionHdr() const { return Header; } |
Rafael Espindola | e1901cc | 2015-09-24 15:11:50 +0000 | [diff] [blame] | 119 | ObjectFile<ELFT> *getFile() const { return File; } |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 120 | uintX_t getOffset(const DefinedRegular<ELFT> &Sym); |
Rafael Espindola | db9bf4d | 2015-11-11 16:50:37 +0000 | [diff] [blame] | 121 | |
| 122 | // Translate an offset in the input section to an offset in the output |
| 123 | // section. |
| 124 | uintX_t getOffset(uintX_t Offset); |
| 125 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 126 | ArrayRef<uint8_t> getSectionData() const; |
Rui Ueyama | 1250464 | 2015-10-27 21:51:13 +0000 | [diff] [blame] | 127 | |
Rafael Espindola | 22ef956 | 2016-04-13 01:40:19 +0000 | [diff] [blame] | 128 | void relocate(uint8_t *Buf, uint8_t *BufEnd); |
| 129 | std::vector<Relocation> Relocations; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
Rafael Espindola | ccfe3cb | 2016-04-04 14:04:16 +0000 | [diff] [blame] | 132 | template <class ELFT> InputSectionBase<ELFT> InputSectionBase<ELFT>::Discarded; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 133 | |
Rui Ueyama | 3ea8727 | 2016-05-22 00:13:04 +0000 | [diff] [blame] | 134 | // SectionPiece represents a piece of splittable section contents. |
| 135 | struct SectionPiece { |
Rui Ueyama | 34dc99e | 2016-05-22 01:15:32 +0000 | [diff] [blame] | 136 | SectionPiece(size_t Off, ArrayRef<uint8_t> Data) |
| 137 | : InputOff(Off), Data(Data), Live(!Config->GcSections) {} |
| 138 | size_t size() const { return Data.size(); } |
| 139 | |
Rui Ueyama | 3ea8727 | 2016-05-22 00:13:04 +0000 | [diff] [blame] | 140 | size_t InputOff; |
| 141 | size_t OutputOff = -1; |
Rui Ueyama | 34dc99e | 2016-05-22 01:15:32 +0000 | [diff] [blame] | 142 | ArrayRef<uint8_t> Data; // slice of the input section |
Rui Ueyama | 3ea8727 | 2016-05-22 00:13:04 +0000 | [diff] [blame] | 143 | bool Live; |
| 144 | }; |
| 145 | |
Rui Ueyama | 5a32c76 | 2016-01-06 03:16:23 +0000 | [diff] [blame] | 146 | // Usually sections are copied to the output as atomic chunks of data, |
| 147 | // but some special types of sections are split into small pieces of data |
| 148 | // and each piece is copied to a different place in the output. |
| 149 | // This class represents such special sections. |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 150 | template <class ELFT> class SplitInputSection : public InputSectionBase<ELFT> { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 151 | typedef typename ELFT::Shdr Elf_Shdr; |
| 152 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 153 | |
| 154 | public: |
| 155 | SplitInputSection(ObjectFile<ELFT> *File, const Elf_Shdr *Header, |
| 156 | typename InputSectionBase<ELFT>::Kind SectionKind); |
Rui Ueyama | 5a32c76 | 2016-01-06 03:16:23 +0000 | [diff] [blame] | 157 | |
Rui Ueyama | 3ea8727 | 2016-05-22 00:13:04 +0000 | [diff] [blame] | 158 | // Splittable sections are handled as a sequence of data |
| 159 | // rather than a single large blob of data. |
| 160 | std::vector<SectionPiece> Pieces; |
Rui Ueyama | 5a32c76 | 2016-01-06 03:16:23 +0000 | [diff] [blame] | 161 | |
Rui Ueyama | 34dc99e | 2016-05-22 01:15:32 +0000 | [diff] [blame] | 162 | // Returns the SectionPiece at a given input section offset. |
Rui Ueyama | 90fa372 | 2016-05-22 00:41:38 +0000 | [diff] [blame] | 163 | SectionPiece *getSectionPiece(uintX_t Offset); |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 164 | }; |
| 165 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 166 | // This corresponds to a SHF_MERGE section of an input file. |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 167 | template <class ELFT> class MergeInputSection : public SplitInputSection<ELFT> { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 168 | typedef typename ELFT::uint uintX_t; |
| 169 | typedef typename ELFT::Sym Elf_Sym; |
| 170 | typedef typename ELFT::Shdr Elf_Shdr; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 171 | |
| 172 | public: |
| 173 | MergeInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header); |
| 174 | static bool classof(const InputSectionBase<ELFT> *S); |
Rui Ueyama | b91bf1a | 2016-05-23 16:55:43 +0000 | [diff] [blame] | 175 | void splitIntoPieces(); |
| 176 | |
| 177 | // Mark the piece at a given offset live. Used by GC. |
| 178 | void markLiveAt(uintX_t Offset) { LiveOffsets.insert(Offset); } |
| 179 | |
| 180 | // Translate an offset in the input section to an offset |
| 181 | // in the output section. |
Rafael Espindola | 48225b4 | 2015-10-23 19:55:11 +0000 | [diff] [blame] | 182 | uintX_t getOffset(uintX_t Offset); |
Rui Ueyama | b91bf1a | 2016-05-23 16:55:43 +0000 | [diff] [blame] | 183 | |
| 184 | private: |
| 185 | llvm::DenseSet<uintX_t> LiveOffsets; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 186 | }; |
| 187 | |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 188 | // This corresponds to a .eh_frame section of an input file. |
Rui Ueyama | 0b9a903 | 2016-05-24 04:19:20 +0000 | [diff] [blame^] | 189 | template <class ELFT> class EhInputSection : public SplitInputSection<ELFT> { |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 190 | public: |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 191 | typedef typename ELFT::Shdr Elf_Shdr; |
| 192 | typedef typename ELFT::uint uintX_t; |
Rui Ueyama | 0b9a903 | 2016-05-24 04:19:20 +0000 | [diff] [blame^] | 193 | EhInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header); |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 194 | static bool classof(const InputSectionBase<ELFT> *S); |
Rui Ueyama | 88abd9b | 2016-05-22 23:53:00 +0000 | [diff] [blame] | 195 | void split(); |
Rafael Espindola | 0c6a4f1 | 2015-11-11 19:54:14 +0000 | [diff] [blame] | 196 | |
| 197 | // Translate an offset in the input section to an offset in the output |
| 198 | // section. |
| 199 | uintX_t getOffset(uintX_t Offset); |
| 200 | |
| 201 | // Relocation section that refer to this one. |
| 202 | const Elf_Shdr *RelocSection = nullptr; |
| 203 | }; |
| 204 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 205 | // This corresponds to a non SHF_MERGE section of an input file. |
| 206 | template <class ELFT> class InputSection : public InputSectionBase<ELFT> { |
Rui Ueyama | 0b28952 | 2016-02-25 18:43:51 +0000 | [diff] [blame] | 207 | friend ICF<ELFT>; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 208 | typedef InputSectionBase<ELFT> Base; |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 209 | typedef typename ELFT::Shdr Elf_Shdr; |
| 210 | typedef typename ELFT::Rela Elf_Rela; |
| 211 | typedef typename ELFT::Rel Elf_Rel; |
| 212 | typedef typename ELFT::Sym Elf_Sym; |
| 213 | typedef typename ELFT::uint uintX_t; |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 214 | |
| 215 | public: |
| 216 | InputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header); |
| 217 | |
| 218 | // Write this section to a mmap'ed file, assuming Buf is pointing to |
| 219 | // beginning of the output section. |
| 220 | void writeTo(uint8_t *Buf); |
| 221 | |
Michael J. Spencer | 67bc8d6 | 2015-08-27 23:15:56 +0000 | [diff] [blame] | 222 | // Relocation sections that refer to this one. |
Rui Ueyama | c00718f | 2016-02-23 03:34:37 +0000 | [diff] [blame] | 223 | llvm::TinyPtrVector<const Elf_Shdr *> RelocSections; |
Michael J. Spencer | 67bc8d6 | 2015-08-27 23:15:56 +0000 | [diff] [blame] | 224 | |
Rui Ueyama | edffd91 | 2015-10-14 21:00:23 +0000 | [diff] [blame] | 225 | // The offset from beginning of the output sections this section was assigned |
| 226 | // to. The writer sets a value. |
Rui Ueyama | 55c3f89 | 2015-10-15 01:58:40 +0000 | [diff] [blame] | 227 | uint64_t OutSecOff = 0; |
Rui Ueyama | edffd91 | 2015-10-14 21:00:23 +0000 | [diff] [blame] | 228 | |
Rafael Espindola | c159c96 | 2015-10-19 21:00:02 +0000 | [diff] [blame] | 229 | static bool classof(const InputSectionBase<ELFT> *S); |
George Rimar | 58941ee | 2016-02-25 08:23:37 +0000 | [diff] [blame] | 230 | |
| 231 | InputSectionBase<ELFT> *getRelocatedSection(); |
| 232 | |
Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 233 | // Register thunk related to the symbol. When the section is written |
| 234 | // to a mmap'ed file, target is requested to write an actual thunk code. |
| 235 | // Now thunks is supported for MIPS target only. |
| 236 | void addThunk(SymbolBody &Body); |
| 237 | |
| 238 | // The offset of synthetic thunk code from beginning of this section. |
| 239 | uint64_t getThunkOff() const; |
| 240 | |
| 241 | // Size of chunk with thunks code. |
| 242 | uint64_t getThunksSize() const; |
| 243 | |
Rui Ueyama | 2b6fb80 | 2016-04-28 18:42:04 +0000 | [diff] [blame] | 244 | template <class RelTy> |
| 245 | void relocateNonAlloc(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels); |
| 246 | |
George Rimar | 58941ee | 2016-02-25 08:23:37 +0000 | [diff] [blame] | 247 | private: |
Rui Ueyama | fc467e7 | 2016-03-13 05:06:50 +0000 | [diff] [blame] | 248 | template <class RelTy> |
Rafael Espindola | 0f7ccc3 | 2016-04-05 14:47:28 +0000 | [diff] [blame] | 249 | void copyRelocations(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels); |
Rui Ueyama | 0b28952 | 2016-02-25 18:43:51 +0000 | [diff] [blame] | 250 | |
| 251 | // Called by ICF to merge two input sections. |
| 252 | void replace(InputSection<ELFT> *Other); |
| 253 | |
| 254 | // Used by ICF. |
| 255 | uint64_t GroupId = 0; |
Simon Atanasyan | 13f6da1 | 2016-03-31 21:26:23 +0000 | [diff] [blame] | 256 | |
| 257 | llvm::TinyPtrVector<const SymbolBody *> Thunks; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 258 | }; |
| 259 | |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 260 | // MIPS .reginfo section provides information on the registers used by the code |
| 261 | // in the object file. Linker should collect this information and write a single |
| 262 | // .reginfo section in the output file. The output section contains a union of |
| 263 | // used registers masks taken from input .reginfo sections and final value |
| 264 | // of the `_gp` symbol. For details: Chapter 4 / "Register Information" at |
| 265 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
| 266 | template <class ELFT> |
| 267 | class MipsReginfoInputSection : public InputSectionBase<ELFT> { |
Rui Ueyama | 9328b2c | 2016-03-14 23:16:09 +0000 | [diff] [blame] | 268 | typedef typename ELFT::Shdr Elf_Shdr; |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 269 | |
| 270 | public: |
Rui Ueyama | 70eed36 | 2016-01-06 22:42:43 +0000 | [diff] [blame] | 271 | MipsReginfoInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Hdr); |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 272 | static bool classof(const InputSectionBase<ELFT> *S); |
Rui Ueyama | 70eed36 | 2016-01-06 22:42:43 +0000 | [diff] [blame] | 273 | |
Simon Atanasyan | add74f3 | 2016-05-04 10:07:38 +0000 | [diff] [blame] | 274 | const llvm::object::Elf_Mips_RegInfo<ELFT> *Reginfo = nullptr; |
| 275 | }; |
| 276 | |
| 277 | template <class ELFT> |
| 278 | class MipsOptionsInputSection : public InputSectionBase<ELFT> { |
| 279 | typedef typename ELFT::Shdr Elf_Shdr; |
| 280 | |
| 281 | public: |
| 282 | MipsOptionsInputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Hdr); |
| 283 | static bool classof(const InputSectionBase<ELFT> *S); |
| 284 | |
| 285 | const llvm::object::Elf_Mips_RegInfo<ELFT> *Reginfo = nullptr; |
Simon Atanasyan | 1d7df40 | 2015-12-20 10:57:34 +0000 | [diff] [blame] | 286 | }; |
| 287 | |
Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 288 | } // namespace elf |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 289 | } // namespace lld |
| 290 | |
| 291 | #endif |