| 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 /// This file defines the writer for ELF relocatable object files. | 11 /// This file 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 "IceOperand.h" | 23 #include "IceOperand.h" |
| 24 |
| 25 #pragma clang diagnostic push |
| 26 #pragma clang diagnostic ignored "-Wunused-parameter" |
| 27 #pragma clang diagnostic ignored "-Wshadow" |
| 24 #include "llvm/Support/MathExtras.h" | 28 #include "llvm/Support/MathExtras.h" |
| 29 #pragma clang diagnostic pop |
| 25 | 30 |
| 26 using namespace llvm::ELF; | 31 using namespace llvm::ELF; |
| 27 | 32 |
| 28 namespace Ice { | 33 namespace Ice { |
| 29 | 34 |
| 30 namespace { | 35 namespace { |
| 31 | 36 |
| 32 struct { | 37 struct { |
| 33 bool IsELF64; | 38 bool IsELF64; |
| 34 uint16_t ELFMachine; | 39 uint16_t ELFMachine; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 57 | 62 |
| 58 uint32_t getELFFlags(TargetArch Arch) { | 63 uint32_t getELFFlags(TargetArch Arch) { |
| 59 if (Arch < TargetArch_NUM) | 64 if (Arch < TargetArch_NUM) |
| 60 return ELFTargetInfo[Arch].ELFFlags; | 65 return ELFTargetInfo[Arch].ELFFlags; |
| 61 llvm_unreachable("Invalid target arch for getELFFlags"); | 66 llvm_unreachable("Invalid target arch for getELFFlags"); |
| 62 return 0; | 67 return 0; |
| 63 } | 68 } |
| 64 | 69 |
| 65 } // end of anonymous namespace | 70 } // end of anonymous namespace |
| 66 | 71 |
| 67 ELFObjectWriter::ELFObjectWriter(GlobalContext &Ctx, ELFStreamer &Out) | 72 ELFObjectWriter::ELFObjectWriter(GlobalContext &MyCtx, ELFStreamer &Out) |
| 68 : Ctx(Ctx), Str(Out), ELF64(isELF64(Ctx.getFlags().getTargetArch())) { | 73 : Ctx(MyCtx), Str(Out), ELF64(isELF64(Ctx.getFlags().getTargetArch())) { |
| 69 // Create the special bookkeeping sections now. | 74 // Create the special bookkeeping sections now. |
| 70 const IceString NullSectionName(""); | 75 const IceString NullSectionName(""); |
| 71 NullSection = new (Ctx.allocate<ELFSection>()) | 76 NullSection = new (Ctx.allocate<ELFSection>()) |
| 72 ELFSection(NullSectionName, SHT_NULL, 0, 0, 0); | 77 ELFSection(NullSectionName, SHT_NULL, 0, 0, 0); |
| 73 | 78 |
| 74 const IceString ShStrTabName(".shstrtab"); | 79 const IceString ShStrTabName(".shstrtab"); |
| 75 ShStrTab = new (Ctx.allocate<ELFStringTableSection>()) | 80 ShStrTab = new (Ctx.allocate<ELFStringTableSection>()) |
| 76 ELFStringTableSection(ShStrTabName, SHT_STRTAB, 0, 1, 0); | 81 ELFStringTableSection(ShStrTabName, SHT_STRTAB, 0, 1, 0); |
| 77 ShStrTab->add(ShStrTabName); | 82 ShStrTab->add(ShStrTabName); |
| 78 | 83 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 315 |
| 311 // TODO(jvoung): Handle fdata-sections. | 316 // TODO(jvoung): Handle fdata-sections. |
| 312 void ELFObjectWriter::writeDataOfType(SectionType ST, | 317 void ELFObjectWriter::writeDataOfType(SectionType ST, |
| 313 const VariableDeclarationList &Vars, | 318 const VariableDeclarationList &Vars, |
| 314 FixupKind RelocationKind, | 319 FixupKind RelocationKind, |
| 315 const IceString &SectionSuffix) { | 320 const IceString &SectionSuffix) { |
| 316 if (Vars.empty()) | 321 if (Vars.empty()) |
| 317 return; | 322 return; |
| 318 ELFDataSection *Section; | 323 ELFDataSection *Section; |
| 319 ELFRelocationSection *RelSection; | 324 ELFRelocationSection *RelSection; |
| 320 IceString SectionName; | |
| 321 Elf64_Xword ShAddralign = 1; | 325 Elf64_Xword ShAddralign = 1; |
| 322 for (VariableDeclaration *Var : Vars) { | 326 for (VariableDeclaration *Var : Vars) { |
| 323 Elf64_Xword Align = Var->getAlignment(); | 327 Elf64_Xword Align = Var->getAlignment(); |
| 324 ShAddralign = std::max(ShAddralign, Align); | 328 ShAddralign = std::max(ShAddralign, Align); |
| 325 } | 329 } |
| 326 const Elf64_Xword ShEntsize = 0; // non-uniform data element size. | 330 const Elf64_Xword ShEntsize = 0; // non-uniform data element size. |
| 327 // Lift this out, so it can be re-used if we do fdata-sections? | 331 // Lift this out, so it can be re-used if we do fdata-sections? |
| 328 switch (ST) { | 332 switch (ST) { |
| 329 case ROData: { | 333 case ROData: { |
| 330 const IceString SectionName = MangleSectionName(".rodata", SectionSuffix); | 334 const IceString SectionName = MangleSectionName(".rodata", SectionSuffix); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 if (ELF64) { | 630 if (ELF64) { |
| 627 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), | 631 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), |
| 628 AllSections.size()); | 632 AllSections.size()); |
| 629 } else { | 633 } else { |
| 630 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), | 634 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), |
| 631 AllSections.size()); | 635 AllSections.size()); |
| 632 } | 636 } |
| 633 } | 637 } |
| 634 | 638 |
| 635 } // end of namespace Ice | 639 } // end of namespace Ice |
| OLD | NEW |