| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 using namespace llvm::ELF; | 22 using namespace llvm::ELF; |
| 23 | 23 |
| 24 namespace Ice { | 24 namespace Ice { |
| 25 | 25 |
| 26 class ELFStreamer; | 26 class ELFStreamer; |
| 27 class ELFStringTableSection; | 27 class ELFStringTableSection; |
| 28 | 28 |
| 29 // Base representation of an ELF section. | 29 // Base representation of an ELF section. |
| 30 class ELFSection { | 30 class ELFSection { |
| 31 ELFSection() = delete; |
| 31 ELFSection(const ELFSection &) = delete; | 32 ELFSection(const ELFSection &) = delete; |
| 32 ELFSection &operator=(const ELFSection &) = delete; | 33 ELFSection &operator=(const ELFSection &) = delete; |
| 33 | 34 |
| 34 public: | 35 public: |
| 35 // Sentinel value for a section number/index for before the final | 36 // Sentinel value for a section number/index for before the final |
| 36 // section index is actually known. The dummy NULL section will be assigned | 37 // section index is actually known. The dummy NULL section will be assigned |
| 37 // number 0, and it is referenced by the dummy 0-th symbol in the symbol | 38 // number 0, and it is referenced by the dummy 0-th symbol in the symbol |
| 38 // table, so use max() instead of 0. | 39 // table, so use max() instead of 0. |
| 39 enum { NoSectionNumber = std::numeric_limits<SizeT>::max() }; | 40 enum { NoSectionNumber = std::numeric_limits<SizeT>::max() }; |
| 40 | 41 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // be fully initialized before writing. | 91 // be fully initialized before writing. |
| 91 Elf64_Shdr Header; | 92 Elf64_Shdr Header; |
| 92 | 93 |
| 93 // The number of the section after laying out sections. | 94 // The number of the section after laying out sections. |
| 94 SizeT Number; | 95 SizeT Number; |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 // Models text/code sections. Code is written out incrementally and the | 98 // Models text/code sections. Code is written out incrementally and the |
| 98 // size of the section is then updated incrementally. | 99 // size of the section is then updated incrementally. |
| 99 class ELFTextSection : public ELFSection { | 100 class ELFTextSection : public ELFSection { |
| 101 ELFTextSection() = delete; |
| 100 ELFTextSection(const ELFTextSection &) = delete; | 102 ELFTextSection(const ELFTextSection &) = delete; |
| 101 ELFTextSection &operator=(const ELFTextSection &) = delete; | 103 ELFTextSection &operator=(const ELFTextSection &) = delete; |
| 102 | 104 |
| 103 public: | 105 public: |
| 104 using ELFSection::ELFSection; | 106 using ELFSection::ELFSection; |
| 105 | 107 |
| 106 void appendData(ELFStreamer &Str, const llvm::StringRef MoreData); | 108 void appendData(ELFStreamer &Str, const llvm::StringRef MoreData); |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 // Models data/rodata sections. Data is written out incrementally and the | 111 // Models data/rodata sections. Data is written out incrementally and the |
| 110 // size of the section is then updated incrementally. | 112 // size of the section is then updated incrementally. |
| 111 // Some rodata sections may have fixed entsize and duplicates may be mergeable. | 113 // Some rodata sections may have fixed entsize and duplicates may be mergeable. |
| 112 class ELFDataSection : public ELFSection { | 114 class ELFDataSection : public ELFSection { |
| 115 ELFDataSection() = delete; |
| 113 ELFDataSection(const ELFDataSection &) = delete; | 116 ELFDataSection(const ELFDataSection &) = delete; |
| 114 ELFDataSection &operator=(const ELFDataSection &) = delete; | 117 ELFDataSection &operator=(const ELFDataSection &) = delete; |
| 115 | 118 |
| 116 public: | 119 public: |
| 117 using ELFSection::ELFSection; | 120 using ELFSection::ELFSection; |
| 118 | 121 |
| 119 void appendData(ELFStreamer &Str, const llvm::StringRef MoreData); | 122 void appendData(ELFStreamer &Str, const llvm::StringRef MoreData); |
| 120 | 123 |
| 121 void appendZeros(ELFStreamer &Str, SizeT NumBytes); | 124 void appendZeros(ELFStreamer &Str, SizeT NumBytes); |
| 122 | 125 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 148 | 151 |
| 149 SizeT getNumber() const { | 152 SizeT getNumber() const { |
| 150 assert(Number != UnknownNumber); | 153 assert(Number != UnknownNumber); |
| 151 return Number; | 154 return Number; |
| 152 } | 155 } |
| 153 }; | 156 }; |
| 154 | 157 |
| 155 // Models a symbol table. Symbols may be added up until updateIndices is | 158 // Models a symbol table. Symbols may be added up until updateIndices is |
| 156 // called. At that point the indices of each symbol will be finalized. | 159 // called. At that point the indices of each symbol will be finalized. |
| 157 class ELFSymbolTableSection : public ELFSection { | 160 class ELFSymbolTableSection : public ELFSection { |
| 161 ELFSymbolTableSection() = delete; |
| 162 ELFSymbolTableSection(const ELFSymbolTableSection &) = delete; |
| 163 ELFSymbolTableSection &operator=(const ELFSymbolTableSection &) = delete; |
| 164 |
| 158 public: | 165 public: |
| 159 using ELFSection::ELFSection; | 166 using ELFSection::ELFSection; |
| 160 | 167 |
| 161 // Create initial entry for a symbol when it is defined. | 168 // Create initial entry for a symbol when it is defined. |
| 162 // Each entry should only be defined once. | 169 // Each entry should only be defined once. |
| 163 // We might want to allow Name to be a dummy name initially, then | 170 // We might want to allow Name to be a dummy name initially, then |
| 164 // get updated to the real thing, since Data initializers are read | 171 // get updated to the real thing, since Data initializers are read |
| 165 // before the bitcode's symbol table is read. | 172 // before the bitcode's symbol table is read. |
| 166 void createDefinedSym(const IceString &Name, uint8_t Type, uint8_t Binding, | 173 void createDefinedSym(const IceString &Name, uint8_t Type, uint8_t Binding, |
| 167 ELFSection *Section, RelocOffsetT Offset, SizeT Size); | 174 ELFSection *Section, RelocOffsetT Offset, SizeT Size); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 192 void writeSymbolMap(ELFStreamer &Str, const SymMap &Map); | 199 void writeSymbolMap(ELFStreamer &Str, const SymMap &Map); |
| 193 | 200 |
| 194 // Keep Local and Global symbols separate, since the sh_info needs to | 201 // Keep Local and Global symbols separate, since the sh_info needs to |
| 195 // know the index of the last LOCAL. | 202 // know the index of the last LOCAL. |
| 196 SymMap LocalSymbols; | 203 SymMap LocalSymbols; |
| 197 SymMap GlobalSymbols; | 204 SymMap GlobalSymbols; |
| 198 }; | 205 }; |
| 199 | 206 |
| 200 // Models a relocation section. | 207 // Models a relocation section. |
| 201 class ELFRelocationSection : public ELFSection { | 208 class ELFRelocationSection : public ELFSection { |
| 209 ELFRelocationSection() = delete; |
| 202 ELFRelocationSection(const ELFRelocationSection &) = delete; | 210 ELFRelocationSection(const ELFRelocationSection &) = delete; |
| 203 ELFRelocationSection &operator=(const ELFRelocationSection &) = delete; | 211 ELFRelocationSection &operator=(const ELFRelocationSection &) = delete; |
| 204 | 212 |
| 205 public: | 213 public: |
| 206 using ELFSection::ELFSection; | 214 using ELFSection::ELFSection; |
| 207 | 215 |
| 208 const ELFSection *getRelatedSection() const { return RelatedSection; } | 216 const ELFSection *getRelatedSection() const { return RelatedSection; } |
| 209 void setRelatedSection(const ELFSection *Section) { | 217 void setRelatedSection(const ELFSection *Section) { |
| 210 RelatedSection = Section; | 218 RelatedSection = Section; |
| 211 } | 219 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 230 FixupList Fixups; | 238 FixupList Fixups; |
| 231 }; | 239 }; |
| 232 | 240 |
| 233 // Models a string table. The user will build the string table by | 241 // Models a string table. The user will build the string table by |
| 234 // adding strings incrementally. At some point, all strings should be | 242 // adding strings incrementally. At some point, all strings should be |
| 235 // known and doLayout() should be called. After that, no other | 243 // known and doLayout() should be called. After that, no other |
| 236 // strings may be added. However, the final offsets of the strings | 244 // strings may be added. However, the final offsets of the strings |
| 237 // can be discovered and used to fill out section headers and symbol | 245 // can be discovered and used to fill out section headers and symbol |
| 238 // table entries. | 246 // table entries. |
| 239 class ELFStringTableSection : public ELFSection { | 247 class ELFStringTableSection : public ELFSection { |
| 248 ELFStringTableSection() = delete; |
| 240 ELFStringTableSection(const ELFStringTableSection &) = delete; | 249 ELFStringTableSection(const ELFStringTableSection &) = delete; |
| 241 ELFStringTableSection &operator=(const ELFStringTableSection &) = delete; | 250 ELFStringTableSection &operator=(const ELFStringTableSection &) = delete; |
| 242 | 251 |
| 243 public: | 252 public: |
| 244 using ELFSection::ELFSection; | 253 using ELFSection::ELFSection; |
| 245 | 254 |
| 246 // Add a string to the table, in preparation for final layout. | 255 // Add a string to the table, in preparation for final layout. |
| 247 void add(const IceString &Str); | 256 void add(const IceString &Str); |
| 248 | 257 |
| 249 // Finalizes the layout of the string table and fills in the section Data. | 258 // Finalizes the layout of the string table and fills in the section Data. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); | 358 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); |
| 350 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); | 359 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); |
| 351 Str.writeELFWord<IsELF64>(Rel.r_info); | 360 Str.writeELFWord<IsELF64>(Rel.r_info); |
| 352 } | 361 } |
| 353 } | 362 } |
| 354 } | 363 } |
| 355 | 364 |
| 356 } // end of namespace Ice | 365 } // end of namespace Ice |
| 357 | 366 |
| 358 #endif // SUBZERO_SRC_ICEELFSECTION_H | 367 #endif // SUBZERO_SRC_ICEELFSECTION_H |
| OLD | NEW |