| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 Number = N; | 57 Number = N; |
| 58 } | 58 } |
| 59 SizeT getNumber() const { | 59 SizeT getNumber() const { |
| 60 assert(Number != NoSectionNumber); | 60 assert(Number != NoSectionNumber); |
| 61 return Number; | 61 return Number; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void setSize(Elf64_Xword sh_size) { Header.sh_size = sh_size; } | 64 void setSize(Elf64_Xword sh_size) { Header.sh_size = sh_size; } |
| 65 SizeT getCurrentSize() const { return Header.sh_size; } | 65 SizeT getCurrentSize() const { return Header.sh_size; } |
| 66 | 66 |
| 67 void setAlignment(Elf64_Xword sh_addralign) { |
| 68 Header.sh_addralign = sh_addralign; |
| 69 } |
| 70 |
| 67 void setNameStrIndex(Elf64_Word sh_name) { Header.sh_name = sh_name; } | 71 void setNameStrIndex(Elf64_Word sh_name) { Header.sh_name = sh_name; } |
| 68 | 72 |
| 69 IceString getName() const { return Name; } | 73 IceString getName() const { return Name; } |
| 70 | 74 |
| 71 void setLinkNum(Elf64_Word sh_link) { Header.sh_link = sh_link; } | 75 void setLinkNum(Elf64_Word sh_link) { Header.sh_link = sh_link; } |
| 72 | 76 |
| 73 void setInfoNum(Elf64_Word sh_info) { Header.sh_info = sh_info; } | 77 void setInfoNum(Elf64_Word sh_info) { Header.sh_info = sh_info; } |
| 74 | 78 |
| 75 void setFileOffset(Elf64_Off sh_offset) { Header.sh_offset = sh_offset; } | 79 void setFileOffset(Elf64_Off sh_offset) { Header.sh_offset = sh_offset; } |
| 76 | 80 |
| 77 Elf64_Xword getSectionAlign() const { return Header.sh_addralign; } | 81 Elf64_Xword getSectionAlign() const { return Header.sh_addralign; } |
| 78 | 82 |
| 79 // Write the section header out with the given streamer. | 83 // Write the section header out with the given streamer. |
| 80 template <bool IsELF64> void writeHeader(ELFStreamer &Str); | 84 template <bool IsELF64> void writeHeader(ELFStreamer &Str); |
| 81 | 85 |
| 86 void padToAlignment(ELFStreamer &Str, bool WritePadding, Elf64_Xword Align); |
| 87 |
| 82 protected: | 88 protected: |
| 83 ~ELFSection() {} | 89 ~ELFSection() {} |
| 84 | 90 |
| 85 // Name of the section in convenient string form (instead of a index | 91 // Name of the section in convenient string form (instead of a index |
| 86 // into the Section Header String Table, which is not known till later). | 92 // into the Section Header String Table, which is not known till later). |
| 87 IceString Name; | 93 IceString Name; |
| 88 | 94 |
| 89 // The fields of the header. May only be partially initialized, but should | 95 // The fields of the header. May only be partially initialized, but should |
| 90 // be fully initialized before writing. | 96 // be fully initialized before writing. |
| 91 Elf64_Shdr Header; | 97 Elf64_Shdr Header; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 110 // size of the section is then updated incrementally. | 116 // size of the section is then updated incrementally. |
| 111 // Some rodata sections may have fixed entsize and duplicates may be mergeable. | 117 // Some rodata sections may have fixed entsize and duplicates may be mergeable. |
| 112 class ELFDataSection : public ELFSection { | 118 class ELFDataSection : public ELFSection { |
| 113 ELFDataSection(const ELFDataSection &) = delete; | 119 ELFDataSection(const ELFDataSection &) = delete; |
| 114 ELFDataSection &operator=(const ELFDataSection &) = delete; | 120 ELFDataSection &operator=(const ELFDataSection &) = delete; |
| 115 | 121 |
| 116 public: | 122 public: |
| 117 using ELFSection::ELFSection; | 123 using ELFSection::ELFSection; |
| 118 | 124 |
| 119 void appendData(ELFStreamer &Str, const llvm::StringRef MoreData); | 125 void appendData(ELFStreamer &Str, const llvm::StringRef MoreData); |
| 126 |
| 127 void appendZeros(ELFStreamer &Str, SizeT NumBytes); |
| 128 |
| 129 void appendRelocationOffset(ELFStreamer &Str, bool IsRela, |
| 130 RelocOffsetT RelocOffset); |
| 120 }; | 131 }; |
| 121 | 132 |
| 122 // Model of ELF symbol table entries. Besides keeping track of the fields | 133 // 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 | 134 // required for an elf symbol table entry it also tracks the number that |
| 124 // represents the symbol's final index in the symbol table. | 135 // represents the symbol's final index in the symbol table. |
| 125 struct ELFSym { | 136 struct ELFSym { |
| 126 Elf64_Sym Sym; | 137 Elf64_Sym Sym; |
| 127 ELFSection *Section; | 138 ELFSection *Section; |
| 128 SizeT Number; | 139 SizeT Number; |
| 129 | 140 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 }; | 199 }; |
| 189 | 200 |
| 190 // Models a relocation section. | 201 // Models a relocation section. |
| 191 class ELFRelocationSection : public ELFSection { | 202 class ELFRelocationSection : public ELFSection { |
| 192 ELFRelocationSection(const ELFRelocationSection &) = delete; | 203 ELFRelocationSection(const ELFRelocationSection &) = delete; |
| 193 ELFRelocationSection &operator=(const ELFRelocationSection &) = delete; | 204 ELFRelocationSection &operator=(const ELFRelocationSection &) = delete; |
| 194 | 205 |
| 195 public: | 206 public: |
| 196 using ELFSection::ELFSection; | 207 using ELFSection::ELFSection; |
| 197 | 208 |
| 198 ELFSection *getRelatedSection() const { return RelatedSection; } | 209 const ELFSection *getRelatedSection() const { return RelatedSection; } |
| 199 void setRelatedSection(ELFSection *Section) { RelatedSection = Section; } | 210 void setRelatedSection(const ELFSection *Section) { |
| 211 RelatedSection = Section; |
| 212 } |
| 200 | 213 |
| 201 // Track additional relocations which start out relative to offset 0, | 214 // Track additional relocations which start out relative to offset 0, |
| 202 // but should be adjusted to be relative to BaseOff. | 215 // but should be adjusted to be relative to BaseOff. |
| 203 void addRelocations(RelocOffsetT BaseOff, const FixupRefList &FixupRefs); | 216 void addRelocations(RelocOffsetT BaseOff, const FixupRefList &FixupRefs); |
| 204 | 217 |
| 218 // Track a single additional relocation. |
| 219 void addRelocation(const AssemblerFixup &Fixup) { Fixups.push_back(Fixup); } |
| 220 |
| 205 size_t getSectionDataSize(const GlobalContext &Ctx, | 221 size_t getSectionDataSize(const GlobalContext &Ctx, |
| 206 const ELFSymbolTableSection *SymTab) const; | 222 const ELFSymbolTableSection *SymTab) const; |
| 207 | 223 |
| 208 template <bool IsELF64> | 224 template <bool IsELF64> |
| 209 void writeData(const GlobalContext &Ctx, ELFStreamer &Str, | 225 void writeData(const GlobalContext &Ctx, ELFStreamer &Str, |
| 210 const ELFSymbolTableSection *SymTab); | 226 const ELFSymbolTableSection *SymTab); |
| 211 | 227 |
| 228 bool isRela() const { return Header.sh_type == SHT_RELA; } |
| 229 |
| 212 private: | 230 private: |
| 213 ELFSection *RelatedSection; | 231 const ELFSection *RelatedSection; |
| 214 FixupList Fixups; | 232 FixupList Fixups; |
| 215 }; | 233 }; |
| 216 | 234 |
| 217 // Models a string table. The user will build the string table by | 235 // Models a string table. The user will build the string table by |
| 218 // adding strings incrementally. At some point, all strings should be | 236 // adding strings incrementally. At some point, all strings should be |
| 219 // known and doLayout() should be called. After that, no other | 237 // known and doLayout() should be called. After that, no other |
| 220 // strings may be added. However, the final offsets of the strings | 238 // strings may be added. However, the final offsets of the strings |
| 221 // can be discovered and used to fill out section headers and symbol | 239 // can be discovered and used to fill out section headers and symbol |
| 222 // table entries. | 240 // table entries. |
| 223 class ELFStringTableSection : public ELFSection { | 241 class ELFStringTableSection : public ELFSection { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); | 353 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); |
| 336 Str.writeELFWord<IsELF64>(Rel.r_info); | 354 Str.writeELFWord<IsELF64>(Rel.r_info); |
| 337 } | 355 } |
| 338 } | 356 } |
| 339 } | 357 } |
| 340 } | 358 } |
| 341 | 359 |
| 342 } // end of namespace Ice | 360 } // end of namespace Ice |
| 343 | 361 |
| 344 #endif // SUBZERO_SRC_ICEELFSECTION_H | 362 #endif // SUBZERO_SRC_ICEELFSECTION_H |
| OLD | NEW |