comparison lld/ELF/InputSection.h @ 221:79ff65ed7e25

LLVM12 Original
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:15:29 +0900
parents 0572611fdcc8
children c4bab56944e8
comparison
equal deleted inserted replaced
220:42394fc6a535 221:79ff65ed7e25
50 // Repl pointer of one section points to another section. So, 50 // Repl pointer of one section points to another section. So,
51 // if you need to get a pointer to this instance, do not use 51 // if you need to get a pointer to this instance, do not use
52 // this but instead this->Repl. 52 // this but instead this->Repl.
53 SectionBase *repl; 53 SectionBase *repl;
54 54
55 unsigned sectionKind : 3; 55 uint8_t sectionKind : 3;
56 56
57 // The next two bit fields are only used by InputSectionBase, but we 57 // The next two bit fields are only used by InputSectionBase, but we
58 // put them here so the struct packs better. 58 // put them here so the struct packs better.
59 59
60 unsigned bss : 1; 60 uint8_t bss : 1;
61 61
62 // Set for sections that should not be folded by ICF. 62 // Set for sections that should not be folded by ICF.
63 unsigned keepUnique : 1; 63 uint8_t keepUnique : 1;
64 64
65 // The 1-indexed partition that this section is assigned to by the garbage 65 // The 1-indexed partition that this section is assigned to by the garbage
66 // collector, or 0 if this section is dead. Normally there is only one 66 // collector, or 0 if this section is dead. Normally there is only one
67 // partition, so this will either be 0 or 1. 67 // partition, so this will either be 0 or 1.
68 uint8_t partition; 68 uint8_t partition;
131 // If basic block sections are enabled, many code sections could end up with 131 // If basic block sections are enabled, many code sections could end up with
132 // one or two jump instructions at the end that could be relaxed to a smaller 132 // one or two jump instructions at the end that could be relaxed to a smaller
133 // instruction. The members below help trimming the trailing jump instruction 133 // instruction. The members below help trimming the trailing jump instruction
134 // and shrinking a section. 134 // and shrinking a section.
135 unsigned bytesDropped = 0; 135 unsigned bytesDropped = 0;
136
137 // Whether the section needs to be padded with a NOP filler due to
138 // deleteFallThruJmpInsn.
139 bool nopFiller = false;
136 140
137 void drop_back(uint64_t num) { bytesDropped += num; } 141 void drop_back(uint64_t num) { bytesDropped += num; }
138 142
139 void push_back(uint64_t num) { 143 void push_back(uint64_t num) {
140 assert(bytesDropped >= num); 144 assert(bytesDropped >= num);
208 RelExpr Expr); 212 RelExpr Expr);
209 213
210 // The native ELF reloc data type is not very convenient to handle. 214 // The native ELF reloc data type is not very convenient to handle.
211 // So we convert ELF reloc records to our own records in Relocations.cpp. 215 // So we convert ELF reloc records to our own records in Relocations.cpp.
212 // This vector contains such "cooked" relocations. 216 // This vector contains such "cooked" relocations.
213 std::vector<Relocation> relocations; 217 SmallVector<Relocation, 0> relocations;
214
215 // Indicates that this section needs to be padded with a NOP filler if set to
216 // true.
217 bool nopFiller = false;
218 218
219 // These are modifiers to jump instructions that are necessary when basic 219 // These are modifiers to jump instructions that are necessary when basic
220 // block sections are enabled. Basic block sections creates opportunities to 220 // block sections are enabled. Basic block sections creates opportunities to
221 // relax jump instructions at basic block boundaries after reordering the 221 // relax jump instructions at basic block boundaries after reordering the
222 // basic blocks. 222 // basic blocks.
223 std::vector<JumpInstrMod> jumpInstrMods; 223 SmallVector<JumpInstrMod, 0> jumpInstrMods;
224 224
225 // A function compiled with -fsplit-stack calling a function 225 // A function compiled with -fsplit-stack calling a function
226 // compiled without -fsplit-stack needs its prologue adjusted. Find 226 // compiled without -fsplit-stack needs its prologue adjusted. Find
227 // such functions and adjust their prologues. This is very similar 227 // such functions and adjust their prologues. This is very similar
228 // to relocation. See https://gcc.gnu.org/wiki/SplitStacks for more 228 // to relocation. See https://gcc.gnu.org/wiki/SplitStacks for more
312 struct EhSectionPiece { 312 struct EhSectionPiece {
313 EhSectionPiece(size_t off, InputSectionBase *sec, uint32_t size, 313 EhSectionPiece(size_t off, InputSectionBase *sec, uint32_t size,
314 unsigned firstRelocation) 314 unsigned firstRelocation)
315 : inputOff(off), sec(sec), size(size), firstRelocation(firstRelocation) {} 315 : inputOff(off), sec(sec), size(size), firstRelocation(firstRelocation) {}
316 316
317 ArrayRef<uint8_t> data() { 317 ArrayRef<uint8_t> data() const {
318 return {sec->data().data() + this->inputOff, size}; 318 return {sec->data().data() + this->inputOff, size};
319 } 319 }
320 320
321 size_t inputOff; 321 size_t inputOff;
322 ssize_t outputOff = -1; 322 ssize_t outputOff = -1;
388 void copyRelocations(uint8_t *buf, llvm::ArrayRef<RelTy> rels); 388 void copyRelocations(uint8_t *buf, llvm::ArrayRef<RelTy> rels);
389 389
390 template <class ELFT> void copyShtGroup(uint8_t *buf); 390 template <class ELFT> void copyShtGroup(uint8_t *buf);
391 }; 391 };
392 392
393 #ifdef _WIN32
394 static_assert(sizeof(InputSection) <= 192, "InputSection is too big");
395 #else
396 static_assert(sizeof(InputSection) <= 184, "InputSection is too big");
397 #endif
398
393 inline bool isDebugSection(const InputSectionBase &sec) { 399 inline bool isDebugSection(const InputSectionBase &sec) {
394 return sec.name.startswith(".debug") || sec.name.startswith(".zdebug"); 400 return (sec.flags & llvm::ELF::SHF_ALLOC) == 0 &&
401 (sec.name.startswith(".debug") || sec.name.startswith(".zdebug"));
395 } 402 }
396 403
397 // The list of all input sections. 404 // The list of all input sections.
398 extern std::vector<InputSectionBase *> inputSections; 405 extern std::vector<InputSectionBase *> inputSections;
399 406