OLD | NEW |
1 //===- subzero/src/IceELFObjectWriter.h - ELF object writer -----*- C++ -*-===// | 1 //===- subzero/src/IceELFObjectWriter.h - ELF object writer -----*- 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 // Abstraction for a writer that is responsible for writing an ELF file. | 10 // Abstraction for a writer that is responsible for writing an ELF file. |
(...skipping 29 matching lines...) Expand all Loading... |
40 public: | 40 public: |
41 ELFObjectWriter(GlobalContext &Ctx, ELFStreamer &Out); | 41 ELFObjectWriter(GlobalContext &Ctx, ELFStreamer &Out); |
42 | 42 |
43 // Write the initial ELF header. This is just to reserve space in the ELF | 43 // Write the initial ELF header. This is just to reserve space in the ELF |
44 // file. Reserving space allows the other functions to write text | 44 // file. Reserving space allows the other functions to write text |
45 // and data directly to the file and get the right file offsets. | 45 // and data directly to the file and get the right file offsets. |
46 void writeInitialELFHeader(); | 46 void writeInitialELFHeader(); |
47 | 47 |
48 // Copy data of a function's text section to file and note the offset of the | 48 // Copy data of a function's text section to file and note the offset of the |
49 // symbol's definition in the symbol table. | 49 // symbol's definition in the symbol table. |
50 // TODO(jvoung): This also needs the relocations to adjust the | 50 // Copy the text fixups for use after all functions are written. |
51 // section-relative offsets and hook them up to the symbol table references. | |
52 void writeFunctionCode(const IceString &FuncName, bool IsInternal, | 51 void writeFunctionCode(const IceString &FuncName, bool IsInternal, |
53 const llvm::StringRef Data); | 52 const Assembler *Asm); |
54 | 53 |
55 // Copy initializer data for a global to file and note the offset and | 54 // Copy initializer data for a global to file and note the offset and |
56 // size of the global's definition in the symbol table. | 55 // size of the global's definition in the symbol table. |
57 // TODO(jvoung): This needs to know which section. This also needs the | 56 // TODO(jvoung): This needs to know which section. This also needs the |
58 // relocations to hook them up to the symbol table references. Also | 57 // relocations to hook them up to the symbol table references. Also |
59 // TODO is handling BSS (which just needs to note the size). | 58 // TODO is handling BSS (which just needs to note the size). |
60 void writeDataInitializer(const IceString &VarName, | 59 void writeDataInitializer(const IceString &VarName, |
61 const llvm::StringRef Data); | 60 const llvm::StringRef Data); |
62 | 61 |
63 template <typename ConstType> void writeConstantPool(Type Ty); | 62 template <typename ConstType> void writeConstantPool(Type Ty); |
64 | 63 |
65 // Do final layout and write out the rest of the object file, then | 64 // Do final layout and write out the rest of the object file, then |
66 // patch up the initial ELF header with the final info. | 65 // patch up the initial ELF header with the final info. |
67 void writeNonUserSections(); | 66 void writeNonUserSections(); |
68 | 67 |
69 private: | 68 private: |
70 GlobalContext &Ctx; | 69 GlobalContext &Ctx; |
71 ELFStreamer &Str; | 70 ELFStreamer &Str; |
72 bool SectionNumbersAssigned; | 71 bool SectionNumbersAssigned; |
73 | 72 |
74 // All created sections, separated into different pools. | 73 // All created sections, separated into different pools. |
75 typedef std::vector<ELFSection *> SectionList; | 74 typedef std::vector<ELFSection *> SectionList; |
76 typedef std::vector<ELFTextSection *> TextSectionList; | 75 typedef std::vector<ELFTextSection *> TextSectionList; |
77 typedef std::vector<ELFDataSection *> DataSectionList; | 76 typedef std::vector<ELFDataSection *> DataSectionList; |
78 typedef std::vector<ELFRelocationSectionBase *> RelSectionList; | 77 typedef std::vector<ELFRelocationSection *> RelSectionList; |
79 TextSectionList TextSections; | 78 TextSectionList TextSections; |
80 RelSectionList RelTextSections; | 79 RelSectionList RelTextSections; |
81 DataSectionList DataSections; | 80 DataSectionList DataSections; |
82 RelSectionList RelDataSections; | 81 RelSectionList RelDataSections; |
83 DataSectionList RoDataSections; | 82 DataSectionList RoDataSections; |
84 RelSectionList RelRoDataSections; | 83 RelSectionList RelRoDataSections; |
85 | 84 |
86 // Handles to special sections that need incremental bookkeeping. | 85 // Handles to special sections that need incremental bookkeeping. |
87 ELFSection *NullSection; | 86 ELFSection *NullSection; |
88 ELFStringTableSection *ShStrTab; | 87 ELFStringTableSection *ShStrTab; |
(...skipping 21 matching lines...) Expand all Loading... |
110 // section's number. | 109 // section's number. |
111 template <typename UserSectionList> | 110 template <typename UserSectionList> |
112 void assignRelSectionNumInPairs(SizeT &CurSectionNumber, | 111 void assignRelSectionNumInPairs(SizeT &CurSectionNumber, |
113 UserSectionList &UserSections, | 112 UserSectionList &UserSections, |
114 RelSectionList &RelSections, | 113 RelSectionList &RelSections, |
115 SectionList &AllSections); | 114 SectionList &AllSections); |
116 | 115 |
117 // Link the relocation sections to the symbol table. | 116 // Link the relocation sections to the symbol table. |
118 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); | 117 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); |
119 | 118 |
| 119 // Write the final relocation sections given the final symbol table. |
| 120 // May also be able to seek around the file and resolve function calls |
| 121 // that are for functions within the same section. |
| 122 void writeAllRelocationSections(bool IsELF64); |
| 123 void writeRelocationSections(bool IsELF64, RelSectionList &RelSections); |
| 124 |
120 // Write the ELF file header with the given information about sections. | 125 // Write the ELF file header with the given information about sections. |
121 template <bool IsELF64> | 126 template <bool IsELF64> |
122 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset, | 127 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset, |
123 SizeT SectHeaderStrIndex, SizeT NumSections); | 128 SizeT SectHeaderStrIndex, SizeT NumSections); |
124 }; | 129 }; |
125 | 130 |
126 } // end of namespace Ice | 131 } // end of namespace Ice |
127 | 132 |
128 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H | 133 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H |
OLD | NEW |