| 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 /// \file | 10 /// \file |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 /// Track additional relocations which start out relative to offset 0, but | 233 /// Track additional relocations which start out relative to offset 0, but |
| 234 /// should be adjusted to be relative to BaseOff. | 234 /// should be adjusted to be relative to BaseOff. |
| 235 void addRelocations(RelocOffsetT BaseOff, const FixupRefList &FixupRefs); | 235 void addRelocations(RelocOffsetT BaseOff, const FixupRefList &FixupRefs); |
| 236 | 236 |
| 237 /// Track a single additional relocation. | 237 /// Track a single additional relocation. |
| 238 void addRelocation(const AssemblerFixup &Fixup) { Fixups.push_back(Fixup); } | 238 void addRelocation(const AssemblerFixup &Fixup) { Fixups.push_back(Fixup); } |
| 239 | 239 |
| 240 size_t getSectionDataSize() const; | 240 size_t getSectionDataSize() const; |
| 241 | 241 |
| 242 template <bool IsELF64> | 242 template <bool IsELF64> |
| 243 void writeData(const GlobalContext &Ctx, ELFStreamer &Str, | 243 void writeData(ELFStreamer &Str, const ELFSymbolTableSection *SymTab); |
| 244 const ELFSymbolTableSection *SymTab); | |
| 245 | 244 |
| 246 bool isRela() const { return Header.sh_type == SHT_RELA; } | 245 bool isRela() const { return Header.sh_type == SHT_RELA; } |
| 247 | 246 |
| 248 private: | 247 private: |
| 249 const ELFSection *RelatedSection; | 248 const ELFSection *RelatedSection; |
| 250 FixupList Fixups; | 249 FixupList Fixups; |
| 251 }; | 250 }; |
| 252 | 251 |
| 253 /// Models a string table. The user will build the string table by adding | 252 /// Models a string table. The user will build the string table by adding |
| 254 /// strings incrementally. At some point, all strings should be known and | 253 /// strings incrementally. At some point, all strings should be known and |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 Str.writeAddrOrOffset<IsELF64>(SymInfo.st_value); | 340 Str.writeAddrOrOffset<IsELF64>(SymInfo.st_value); |
| 342 Str.writeELFWord<IsELF64>(SymInfo.st_size); | 341 Str.writeELFWord<IsELF64>(SymInfo.st_size); |
| 343 Str.write8(SymInfo.st_info); | 342 Str.write8(SymInfo.st_info); |
| 344 Str.write8(SymInfo.st_other); | 343 Str.write8(SymInfo.st_other); |
| 345 Str.writeLE16(SymInfo.st_shndx); | 344 Str.writeLE16(SymInfo.st_shndx); |
| 346 } | 345 } |
| 347 } | 346 } |
| 348 } | 347 } |
| 349 | 348 |
| 350 template <bool IsELF64> | 349 template <bool IsELF64> |
| 351 void ELFRelocationSection::writeData(const GlobalContext &Ctx, ELFStreamer &Str, | 350 void ELFRelocationSection::writeData(ELFStreamer &Str, |
| 352 const ELFSymbolTableSection *SymTab) { | 351 const ELFSymbolTableSection *SymTab) { |
| 353 for (const AssemblerFixup &Fixup : Fixups) { | 352 for (const AssemblerFixup &Fixup : Fixups) { |
| 354 const ELFSym *Symbol; | 353 const ELFSym *Symbol; |
| 355 if (Fixup.isNullSymbol()) { | 354 if (Fixup.isNullSymbol()) { |
| 356 Symbol = SymTab->getNullSymbol(); | 355 Symbol = SymTab->getNullSymbol(); |
| 357 } else { | 356 } else { |
| 358 constexpr Assembler *Asm = nullptr; | 357 constexpr Assembler *Asm = nullptr; |
| 359 IceString Name = Fixup.symbol(&Ctx, Asm); | 358 const IceString Name = Fixup.symbol(Asm); |
| 360 Symbol = SymTab->findSymbol(Name); | 359 Symbol = SymTab->findSymbol(Name); |
| 361 if (!Symbol) | 360 if (!Symbol) |
| 362 llvm::report_fatal_error(Name + ": Missing symbol mentioned in reloc"); | 361 llvm::report_fatal_error(Name + ": Missing symbol mentioned in reloc"); |
| 363 } | 362 } |
| 364 | 363 |
| 365 if (IsELF64) { | 364 if (IsELF64) { |
| 366 Elf64_Rela Rela; | 365 Elf64_Rela Rela; |
| 367 Rela.r_offset = Fixup.position(); | 366 Rela.r_offset = Fixup.position(); |
| 368 Rela.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); | 367 Rela.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); |
| 369 Rela.r_addend = Fixup.offset(); | 368 Rela.r_addend = Fixup.offset(); |
| 370 Str.writeAddrOrOffset<IsELF64>(Rela.r_offset); | 369 Str.writeAddrOrOffset<IsELF64>(Rela.r_offset); |
| 371 Str.writeELFXword<IsELF64>(Rela.r_info); | 370 Str.writeELFXword<IsELF64>(Rela.r_info); |
| 372 Str.writeELFXword<IsELF64>(Rela.r_addend); | 371 Str.writeELFXword<IsELF64>(Rela.r_addend); |
| 373 } else { | 372 } else { |
| 374 Elf32_Rel Rel; | 373 Elf32_Rel Rel; |
| 375 Rel.r_offset = Fixup.position(); | 374 Rel.r_offset = Fixup.position(); |
| 376 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); | 375 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); |
| 377 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); | 376 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); |
| 378 Str.writeELFWord<IsELF64>(Rel.r_info); | 377 Str.writeELFWord<IsELF64>(Rel.r_info); |
| 379 } | 378 } |
| 380 } | 379 } |
| 381 } | 380 } |
| 382 | 381 |
| 383 } // end of namespace Ice | 382 } // end of namespace Ice |
| 384 | 383 |
| 385 #endif // SUBZERO_SRC_ICEELFSECTION_H | 384 #endif // SUBZERO_SRC_ICEELFSECTION_H |
| OLD | NEW |