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 /// \file | 10 /// \file |
(...skipping 46 matching lines...) Loading... |
57 /// Write the initial ELF header. This is just to reserve space in the ELF | 57 /// Write the initial ELF header. This is just to reserve space in the ELF |
58 /// file. Reserving space allows the other functions to write text and data | 58 /// file. Reserving space allows the other functions to write text and data |
59 /// directly to the file and get the right file offsets. | 59 /// directly to the file and get the right file offsets. |
60 void writeInitialELFHeader(); | 60 void writeInitialELFHeader(); |
61 | 61 |
62 /// Copy initializer data for globals to file and note the offset and size of | 62 /// Copy initializer data for globals to file and note the offset and size of |
63 /// each global's definition in the symbol table. Use the given target's | 63 /// each global's definition in the symbol table. Use the given target's |
64 /// RelocationKind for any relocations. | 64 /// RelocationKind for any relocations. |
65 void writeDataSection(const VariableDeclarationList &Vars, | 65 void writeDataSection(const VariableDeclarationList &Vars, |
66 FixupKind RelocationKind, | 66 FixupKind RelocationKind, |
67 const IceString &SectionSuffix, bool IsPIC); | 67 const std::string &SectionSuffix, bool IsPIC); |
68 | 68 |
69 /// Copy data of a function's text section to file and note the offset of the | 69 /// Copy data of a function's text section to file and note the offset of the |
70 /// symbol's definition in the symbol table. Copy the text fixups for use | 70 /// symbol's definition in the symbol table. Copy the text fixups for use |
71 /// after all functions are written. The text buffer and fixups are extracted | 71 /// after all functions are written. The text buffer and fixups are extracted |
72 /// from the Assembler object. | 72 /// from the Assembler object. |
73 void writeFunctionCode(const IceString &FuncName, bool IsInternal, | 73 void writeFunctionCode(GlobalString FuncName, bool IsInternal, |
74 Assembler *Asm); | 74 Assembler *Asm); |
75 | 75 |
76 /// Queries the GlobalContext for constant pools of the given type and writes | 76 /// Queries the GlobalContext for constant pools of the given type and writes |
77 /// out read-only data sections for those constants. This also fills the | 77 /// out read-only data sections for those constants. This also fills the |
78 /// symbol table with labels for each constant pool entry. | 78 /// symbol table with labels for each constant pool entry. |
79 template <typename ConstType> void writeConstantPool(Type Ty); | 79 template <typename ConstType> void writeConstantPool(Type Ty); |
80 | 80 |
81 /// Write a jump table and register fixups for the target addresses. | 81 /// Write a jump table and register fixups for the target addresses. |
82 void writeJumpTable(const JumpTableData &JT, FixupKind RelocationKind, | 82 void writeJumpTable(const JumpTableData &JT, FixupKind RelocationKind, |
83 bool IsPIC); | 83 bool IsPIC); |
(...skipping 28 matching lines...) Loading... |
112 RelSectionList RelRODataSections; | 112 RelSectionList RelRODataSections; |
113 DataSectionList BSSSections; | 113 DataSectionList BSSSections; |
114 | 114 |
115 // Handles to special sections that need incremental bookkeeping. | 115 // Handles to special sections that need incremental bookkeeping. |
116 ELFSection *NullSection; | 116 ELFSection *NullSection; |
117 ELFStringTableSection *ShStrTab; | 117 ELFStringTableSection *ShStrTab; |
118 ELFSymbolTableSection *SymTab; | 118 ELFSymbolTableSection *SymTab; |
119 ELFStringTableSection *StrTab; | 119 ELFStringTableSection *StrTab; |
120 | 120 |
121 template <typename T> | 121 template <typename T> |
122 T *createSection(const IceString &Name, Elf64_Word ShType, | 122 T *createSection(const std::string &Name, Elf64_Word ShType, |
123 Elf64_Xword ShFlags, Elf64_Xword ShAddralign, | 123 Elf64_Xword ShFlags, Elf64_Xword ShAddralign, |
124 Elf64_Xword ShEntsize); | 124 Elf64_Xword ShEntsize); |
125 | 125 |
126 /// Create a relocation section, given the related section (e.g., .text, | 126 /// Create a relocation section, given the related section (e.g., .text, |
127 /// .data., .rodata). | 127 /// .data., .rodata). |
128 ELFRelocationSection * | 128 ELFRelocationSection * |
129 createRelocationSection(const ELFSection *RelatedSection); | 129 createRelocationSection(const ELFSection *RelatedSection); |
130 | 130 |
131 /// Align the file position before writing out a section's data, and return | 131 /// Align the file position before writing out a section's data, and return |
132 /// the position of the file. | 132 /// the position of the file. |
(...skipping 16 matching lines...) Loading... |
149 SectionList &AllSections); | 149 SectionList &AllSections); |
150 | 150 |
151 /// Link the relocation sections to the symbol table. | 151 /// Link the relocation sections to the symbol table. |
152 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); | 152 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); |
153 | 153 |
154 /// Helper function for writeDataSection. Writes a data section of type | 154 /// Helper function for writeDataSection. Writes a data section of type |
155 /// SectionType, given the global variables Vars belonging to that | 155 /// SectionType, given the global variables Vars belonging to that |
156 /// SectionType. | 156 /// SectionType. |
157 void writeDataOfType(SectionType SectionType, | 157 void writeDataOfType(SectionType SectionType, |
158 const VariableDeclarationPartition &Vars, | 158 const VariableDeclarationPartition &Vars, |
159 FixupKind RelocationKind, const IceString &SectionSuffix, | 159 FixupKind RelocationKind, |
160 bool IsPIC); | 160 const std::string &SectionSuffix, bool IsPIC); |
161 | 161 |
162 /// Write the final relocation sections given the final symbol table. May also | 162 /// Write the final relocation sections given the final symbol table. May also |
163 /// be able to seek around the file and resolve function calls that are for | 163 /// be able to seek around the file and resolve function calls that are for |
164 /// functions within the same section. | 164 /// functions within the same section. |
165 void writeAllRelocationSections(); | 165 void writeAllRelocationSections(); |
166 void writeRelocationSections(RelSectionList &RelSections); | 166 void writeRelocationSections(RelSectionList &RelSections); |
167 | 167 |
168 /// Write the ELF file header with the given information about sections. | 168 /// Write the ELF file header with the given information about sections. |
169 template <bool IsELF64> | 169 template <bool IsELF64> |
170 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset, | 170 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset, |
171 SizeT SectHeaderStrIndex, SizeT NumSections); | 171 SizeT SectHeaderStrIndex, SizeT NumSections); |
172 }; | 172 }; |
173 | 173 |
174 } // end of namespace Ice | 174 } // end of namespace Ice |
175 | 175 |
176 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H | 176 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H |
OLD | NEW |