| OLD | NEW |
| 1 //===- subzero/src/IceELFObjectWriter.cpp - ELF object file writer --------===// | 1 //===- subzero/src/IceELFObjectWriter.cpp - ELF object file writer --------===// |
| 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 |
| 11 /// \brief Defines the writer for ELF relocatable object files. | 11 /// \brief Defines the writer for ELF relocatable object files. |
| 12 /// | 12 /// |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "IceELFObjectWriter.h" | 15 #include "IceELFObjectWriter.h" |
| 16 | 16 |
| 17 #include "IceAssembler.h" | 17 #include "IceAssembler.h" |
| 18 #include "IceDefs.h" | 18 #include "IceDefs.h" |
| 19 #include "IceELFSection.h" | 19 #include "IceELFSection.h" |
| 20 #include "IceELFStreamer.h" | 20 #include "IceELFStreamer.h" |
| 21 #include "IceGlobalContext.h" | 21 #include "IceGlobalContext.h" |
| 22 #include "IceGlobalInits.h" | 22 #include "IceGlobalInits.h" |
| 23 #include "IceInst.h" | 23 #include "IceInst.h" |
| 24 #include "IceOperand.h" | 24 #include "IceOperand.h" |
| 25 |
| 26 #include "llvm/Support/ELF.h" |
| 25 #include "llvm/Support/MathExtras.h" | 27 #include "llvm/Support/MathExtras.h" |
| 26 | 28 |
| 27 using namespace llvm::ELF; | |
| 28 | |
| 29 namespace Ice { | 29 namespace Ice { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 constexpr struct { | 33 constexpr struct { |
| 34 bool IsELF64; | 34 bool IsELF64; |
| 35 uint16_t ELFMachine; | 35 uint16_t ELFMachine; |
| 36 uint32_t ELFFlags; | 36 uint32_t ELFFlags; |
| 37 } ELFTargetInfo[TargetArch_NUM] = { | 37 } ELFTargetInfo[TargetArch_NUM] = { |
| 38 #define X(tag, str, is_elf64, e_machine, e_flags) \ | 38 #define X(tag, str, is_elf64, e_machine, e_flags) \ |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 const auto &Data = | 412 const auto &Data = |
| 413 llvm::cast<VariableDeclaration::DataInitializer>(Init.get()) | 413 llvm::cast<VariableDeclaration::DataInitializer>(Init.get()) |
| 414 ->getContents(); | 414 ->getContents(); |
| 415 Section->appendData(Str, llvm::StringRef(Data.data(), Data.size())); | 415 Section->appendData(Str, llvm::StringRef(Data.data(), Data.size())); |
| 416 break; | 416 break; |
| 417 } | 417 } |
| 418 case VariableDeclaration::Initializer::ZeroInitializerKind: | 418 case VariableDeclaration::Initializer::ZeroInitializerKind: |
| 419 Section->appendZeros(Str, Init->getNumBytes()); | 419 Section->appendZeros(Str, Init->getNumBytes()); |
| 420 break; | 420 break; |
| 421 case VariableDeclaration::Initializer::RelocInitializerKind: { | 421 case VariableDeclaration::Initializer::RelocInitializerKind: { |
| 422 const auto Reloc = | 422 const auto *Reloc = |
| 423 llvm::cast<VariableDeclaration::RelocInitializer>(Init.get()); | 423 llvm::cast<VariableDeclaration::RelocInitializer>(Init.get()); |
| 424 AssemblerFixup NewFixup; | 424 AssemblerFixup NewFixup; |
| 425 NewFixup.set_position(Section->getCurrentSize()); | 425 NewFixup.set_position(Section->getCurrentSize()); |
| 426 NewFixup.set_kind(RelocationKind); | 426 NewFixup.set_kind(Reloc->hasFixup() ? Reloc->getFixup() |
| 427 : RelocationKind); |
| 428 assert(NewFixup.kind() != llvm::ELF::R_ARM_NONE); |
| 427 constexpr bool SuppressMangling = true; | 429 constexpr bool SuppressMangling = true; |
| 428 NewFixup.set_value(Ctx.getConstantSym( | 430 NewFixup.set_value(Ctx.getConstantSym( |
| 429 Reloc->getOffset(), Reloc->getDeclaration()->mangleName(&Ctx), | 431 Reloc->getOffset(), Reloc->getDeclaration()->mangleName(&Ctx), |
| 430 SuppressMangling)); | 432 SuppressMangling)); |
| 431 RelSection->addRelocation(NewFixup); | 433 RelSection->addRelocation(NewFixup); |
| 432 Section->appendRelocationOffset(Str, RelSection->isRela(), | 434 Section->appendRelocationOffset(Str, RelSection->isRela(), |
| 433 Reloc->getOffset()); | 435 Reloc->getOffset()); |
| 434 break; | 436 break; |
| 435 } | 437 } |
| 436 } | 438 } |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 if (ELF64) { | 690 if (ELF64) { |
| 689 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), | 691 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), |
| 690 AllSections.size()); | 692 AllSections.size()); |
| 691 } else { | 693 } else { |
| 692 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), | 694 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), |
| 693 AllSections.size()); | 695 AllSections.size()); |
| 694 } | 696 } |
| 695 } | 697 } |
| 696 | 698 |
| 697 } // end of namespace Ice | 699 } // end of namespace Ice |
| OLD | NEW |