| OLD | NEW |
| 1 //===- subzero/src/IceELFSection.h - Model of ELF sections ------*- C++ -*-===// | 1 //===- subzero/src/IceELFSection.h - Model of ELF sections ------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // Representation of ELF sections. | 10 // Representation of ELF sections. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // size of the section is then updated incrementally. | 110 // size of the section is then updated incrementally. |
| 111 // Some rodata sections may have fixed entsize and duplicates may be mergeable. | 111 // Some rodata sections may have fixed entsize and duplicates may be mergeable. |
| 112 class ELFDataSection : public ELFSection { | 112 class ELFDataSection : public ELFSection { |
| 113 ELFDataSection(const ELFDataSection &) = delete; | 113 ELFDataSection(const ELFDataSection &) = delete; |
| 114 ELFDataSection &operator=(const ELFDataSection &) = delete; | 114 ELFDataSection &operator=(const ELFDataSection &) = delete; |
| 115 | 115 |
| 116 public: | 116 public: |
| 117 using ELFSection::ELFSection; | 117 using ELFSection::ELFSection; |
| 118 | 118 |
| 119 void appendData(ELFStreamer &Str, const llvm::StringRef MoreData); | 119 void appendData(ELFStreamer &Str, const llvm::StringRef MoreData); |
| 120 |
| 121 void appendZeros(ELFStreamer &Str, SizeT NumBytes); |
| 122 |
| 123 void appendRelocationOffset(ELFStreamer &Str, bool IsRela, |
| 124 RelocOffsetT RelocOffset); |
| 125 |
| 126 // Pad the next section offset for writing data elements to the requested |
| 127 // alignment. If the section is NOBITS then do not actually write out |
| 128 // the padding and only update the section size. |
| 129 void padToAlignment(ELFStreamer &Str, Elf64_Xword Align); |
| 120 }; | 130 }; |
| 121 | 131 |
| 122 // Model of ELF symbol table entries. Besides keeping track of the fields | 132 // Model of ELF symbol table entries. Besides keeping track of the fields |
| 123 // required for an elf symbol table entry it also tracks the number that | 133 // required for an elf symbol table entry it also tracks the number that |
| 124 // represents the symbol's final index in the symbol table. | 134 // represents the symbol's final index in the symbol table. |
| 125 struct ELFSym { | 135 struct ELFSym { |
| 126 Elf64_Sym Sym; | 136 Elf64_Sym Sym; |
| 127 ELFSection *Section; | 137 ELFSection *Section; |
| 128 SizeT Number; | 138 SizeT Number; |
| 129 | 139 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 }; | 198 }; |
| 189 | 199 |
| 190 // Models a relocation section. | 200 // Models a relocation section. |
| 191 class ELFRelocationSection : public ELFSection { | 201 class ELFRelocationSection : public ELFSection { |
| 192 ELFRelocationSection(const ELFRelocationSection &) = delete; | 202 ELFRelocationSection(const ELFRelocationSection &) = delete; |
| 193 ELFRelocationSection &operator=(const ELFRelocationSection &) = delete; | 203 ELFRelocationSection &operator=(const ELFRelocationSection &) = delete; |
| 194 | 204 |
| 195 public: | 205 public: |
| 196 using ELFSection::ELFSection; | 206 using ELFSection::ELFSection; |
| 197 | 207 |
| 198 ELFSection *getRelatedSection() const { return RelatedSection; } | 208 const ELFSection *getRelatedSection() const { return RelatedSection; } |
| 199 void setRelatedSection(ELFSection *Section) { RelatedSection = Section; } | 209 void setRelatedSection(const ELFSection *Section) { |
| 210 RelatedSection = Section; |
| 211 } |
| 200 | 212 |
| 201 // Track additional relocations which start out relative to offset 0, | 213 // Track additional relocations which start out relative to offset 0, |
| 202 // but should be adjusted to be relative to BaseOff. | 214 // but should be adjusted to be relative to BaseOff. |
| 203 void addRelocations(RelocOffsetT BaseOff, const FixupRefList &FixupRefs); | 215 void addRelocations(RelocOffsetT BaseOff, const FixupRefList &FixupRefs); |
| 204 | 216 |
| 217 // Track a single additional relocation. |
| 218 void addRelocation(const AssemblerFixup &Fixup) { Fixups.push_back(Fixup); } |
| 219 |
| 205 size_t getSectionDataSize(const GlobalContext &Ctx, | 220 size_t getSectionDataSize(const GlobalContext &Ctx, |
| 206 const ELFSymbolTableSection *SymTab) const; | 221 const ELFSymbolTableSection *SymTab) const; |
| 207 | 222 |
| 208 template <bool IsELF64> | 223 template <bool IsELF64> |
| 209 void writeData(const GlobalContext &Ctx, ELFStreamer &Str, | 224 void writeData(const GlobalContext &Ctx, ELFStreamer &Str, |
| 210 const ELFSymbolTableSection *SymTab); | 225 const ELFSymbolTableSection *SymTab); |
| 211 | 226 |
| 227 bool isRela() const { return Header.sh_type == SHT_RELA; } |
| 228 |
| 212 private: | 229 private: |
| 213 ELFSection *RelatedSection; | 230 const ELFSection *RelatedSection; |
| 214 FixupList Fixups; | 231 FixupList Fixups; |
| 215 }; | 232 }; |
| 216 | 233 |
| 217 // Models a string table. The user will build the string table by | 234 // Models a string table. The user will build the string table by |
| 218 // adding strings incrementally. At some point, all strings should be | 235 // adding strings incrementally. At some point, all strings should be |
| 219 // known and doLayout() should be called. After that, no other | 236 // known and doLayout() should be called. After that, no other |
| 220 // strings may be added. However, the final offsets of the strings | 237 // strings may be added. However, the final offsets of the strings |
| 221 // can be discovered and used to fill out section headers and symbol | 238 // can be discovered and used to fill out section headers and symbol |
| 222 // table entries. | 239 // table entries. |
| 223 class ELFStringTableSection : public ELFSection { | 240 class ELFStringTableSection : public ELFSection { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); | 352 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); |
| 336 Str.writeELFWord<IsELF64>(Rel.r_info); | 353 Str.writeELFWord<IsELF64>(Rel.r_info); |
| 337 } | 354 } |
| 338 } | 355 } |
| 339 } | 356 } |
| 340 } | 357 } |
| 341 | 358 |
| 342 } // end of namespace Ice | 359 } // end of namespace Ice |
| 343 | 360 |
| 344 #endif // SUBZERO_SRC_ICEELFSECTION_H | 361 #endif // SUBZERO_SRC_ICEELFSECTION_H |
| OLD | NEW |