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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 void writeNonUserSections(); | 86 void writeNonUserSections(); |
87 | 87 |
88 // Which type of ELF section a global variable initializer belongs to. | 88 // Which type of ELF section a global variable initializer belongs to. |
89 // This is used as an array index so should start at 0 and be contiguous. | 89 // This is used as an array index so should start at 0 and be contiguous. |
90 enum SectionType { ROData = 0, Data, BSS, NumSectionTypes }; | 90 enum SectionType { ROData = 0, Data, BSS, NumSectionTypes }; |
91 | 91 |
92 private: | 92 private: |
93 GlobalContext &Ctx; | 93 GlobalContext &Ctx; |
94 ELFStreamer &Str; | 94 ELFStreamer &Str; |
95 bool SectionNumbersAssigned; | 95 bool SectionNumbersAssigned; |
| 96 bool ELF64; |
96 | 97 |
97 // All created sections, separated into different pools. | 98 // All created sections, separated into different pools. |
98 typedef std::vector<ELFSection *> SectionList; | 99 typedef std::vector<ELFSection *> SectionList; |
99 typedef std::vector<ELFTextSection *> TextSectionList; | 100 typedef std::vector<ELFTextSection *> TextSectionList; |
100 typedef std::vector<ELFDataSection *> DataSectionList; | 101 typedef std::vector<ELFDataSection *> DataSectionList; |
101 typedef std::vector<ELFRelocationSection *> RelSectionList; | 102 typedef std::vector<ELFRelocationSection *> RelSectionList; |
102 TextSectionList TextSections; | 103 TextSectionList TextSections; |
103 RelSectionList RelTextSections; | 104 RelSectionList RelTextSections; |
104 DataSectionList DataSections; | 105 DataSectionList DataSections; |
105 RelSectionList RelDataSections; | 106 RelSectionList RelDataSections; |
106 DataSectionList RODataSections; | 107 DataSectionList RODataSections; |
107 RelSectionList RelRODataSections; | 108 RelSectionList RelRODataSections; |
108 DataSectionList BSSSections; | 109 DataSectionList BSSSections; |
109 | 110 |
110 // Handles to special sections that need incremental bookkeeping. | 111 // Handles to special sections that need incremental bookkeeping. |
111 ELFSection *NullSection; | 112 ELFSection *NullSection; |
112 ELFStringTableSection *ShStrTab; | 113 ELFStringTableSection *ShStrTab; |
113 ELFSymbolTableSection *SymTab; | 114 ELFSymbolTableSection *SymTab; |
114 ELFStringTableSection *StrTab; | 115 ELFStringTableSection *StrTab; |
115 | 116 |
116 template <typename T> | 117 template <typename T> |
117 T *createSection(const IceString &Name, Elf64_Word ShType, | 118 T *createSection(const IceString &Name, Elf64_Word ShType, |
118 Elf64_Xword ShFlags, Elf64_Xword ShAddralign, | 119 Elf64_Xword ShFlags, Elf64_Xword ShAddralign, |
119 Elf64_Xword ShEntsize); | 120 Elf64_Xword ShEntsize); |
120 | 121 |
121 // Create a relocation section, given the related section | 122 // Create a relocation section, given the related section |
122 // (e.g., .text, .data., .rodata). | 123 // (e.g., .text, .data., .rodata). |
123 ELFRelocationSection * | 124 ELFRelocationSection * |
124 createRelocationSection(bool IsELF64, const ELFSection *RelatedSection); | 125 createRelocationSection(const ELFSection *RelatedSection); |
125 | 126 |
126 // Align the file position before writing out a section's data, | 127 // Align the file position before writing out a section's data, |
127 // and return the position of the file. | 128 // and return the position of the file. |
128 Elf64_Off alignFileOffset(Elf64_Xword Align); | 129 Elf64_Off alignFileOffset(Elf64_Xword Align); |
129 | 130 |
130 // Assign an ordering / section numbers to each section. | 131 // Assign an ordering / section numbers to each section. |
131 // Fill in other information that is only known near the end | 132 // Fill in other information that is only known near the end |
132 // (such as the size, if it wasn't already incrementally updated). | 133 // (such as the size, if it wasn't already incrementally updated). |
133 // This then collects all sections in the decided order, into one vector, | 134 // This then collects all sections in the decided order, into one vector, |
134 // for conveniently writing out all of the section headers. | 135 // for conveniently writing out all of the section headers. |
135 void assignSectionNumbersInfo(SectionList &AllSections); | 136 void assignSectionNumbersInfo(SectionList &AllSections); |
136 | 137 |
137 // This function assigns .foo and .rel.foo consecutive section numbers. | 138 // This function assigns .foo and .rel.foo consecutive section numbers. |
138 // It also sets the relocation section's sh_info field to the related | 139 // It also sets the relocation section's sh_info field to the related |
139 // section's number. | 140 // section's number. |
140 template <typename UserSectionList> | 141 template <typename UserSectionList> |
141 void assignRelSectionNumInPairs(SizeT &CurSectionNumber, | 142 void assignRelSectionNumInPairs(SizeT &CurSectionNumber, |
142 UserSectionList &UserSections, | 143 UserSectionList &UserSections, |
143 RelSectionList &RelSections, | 144 RelSectionList &RelSections, |
144 SectionList &AllSections); | 145 SectionList &AllSections); |
145 | 146 |
146 // Link the relocation sections to the symbol table. | 147 // Link the relocation sections to the symbol table. |
147 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); | 148 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); |
148 | 149 |
149 // Helper function for writeDataSection. Writes a data section of type | 150 // Helper function for writeDataSection. Writes a data section of type |
150 // SectionType, given the global variables Vars belonging to that SectionType. | 151 // SectionType, given the global variables Vars belonging to that SectionType. |
151 void writeDataOfType(SectionType SectionType, | 152 void writeDataOfType(SectionType SectionType, |
152 const VariableDeclarationList &Vars, | 153 const VariableDeclarationList &Vars, |
153 FixupKind RelocationKind, bool IsELF64); | 154 FixupKind RelocationKind); |
154 | 155 |
155 // Write the final relocation sections given the final symbol table. | 156 // Write the final relocation sections given the final symbol table. |
156 // May also be able to seek around the file and resolve function calls | 157 // May also be able to seek around the file and resolve function calls |
157 // that are for functions within the same section. | 158 // that are for functions within the same section. |
158 void writeAllRelocationSections(bool IsELF64); | 159 void writeAllRelocationSections(); |
159 void writeRelocationSections(bool IsELF64, RelSectionList &RelSections); | 160 void writeRelocationSections(RelSectionList &RelSections); |
160 | 161 |
161 // Write the ELF file header with the given information about sections. | 162 // Write the ELF file header with the given information about sections. |
162 template <bool IsELF64> | 163 template <bool IsELF64> |
163 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset, | 164 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset, |
164 SizeT SectHeaderStrIndex, SizeT NumSections); | 165 SizeT SectHeaderStrIndex, SizeT NumSections); |
165 }; | 166 }; |
166 | 167 |
167 } // end of namespace Ice | 168 } // end of namespace Ice |
168 | 169 |
169 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H | 170 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H |
OLD | NEW |