Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 namespace Ice { | 24 namespace Ice { |
| 25 | 25 |
| 26 // Higher level ELF object writer. Manages section information and writes | 26 // Higher level ELF object writer. Manages section information and writes |
| 27 // the final ELF object. The object writer will write to file the code | 27 // the final ELF object. The object writer will write to file the code |
| 28 // and data as it is being defined (rather than keep a copy). | 28 // and data as it is being defined (rather than keep a copy). |
| 29 // After all definitions are written out, it will finalize the bookkeeping | 29 // After all definitions are written out, it will finalize the bookkeeping |
| 30 // sections and write them out. Expected usage: | 30 // sections and write them out. Expected usage: |
| 31 // | 31 // |
| 32 // (1) writeInitialELFHeader (invoke once) | 32 // (1) writeInitialELFHeader (invoke once) |
| 33 // (2) writeDataSection (invoke once) | 33 // (2) writeDataSection (may be invoked multiple times, as long as |
| 34 // SectionSuffix is unique) | |
| 34 // (3) writeFunctionCode (must invoke once per function) | 35 // (3) writeFunctionCode (must invoke once per function) |
| 35 // (4) writeConstantPool (must invoke once per pooled primitive type) | 36 // (4) writeConstantPool (must invoke once per pooled primitive type) |
| 36 // (5) setUndefinedSyms (invoke once) | 37 // (5) setUndefinedSyms (invoke once) |
| 37 // (6) writeNonUserSections (invoke once) | 38 // (6) writeNonUserSections (invoke once) |
| 38 // | 39 // |
| 39 // The requirement for writeDataSection to be invoked only once can | 40 // The requirement for writeDataSection to be invoked only once can |
|
jvoung (off chromium)
2015/06/16 18:23:10
Maybe just remove this "invoked only once" note.
John
2015/06/16 19:58:01
Done.
| |
| 40 // be relaxed if using -fdata-sections. The requirement to invoke only once | 41 // be relaxed if using -fdata-sections. The requirement to invoke only once |
| 41 // without -fdata-sections is so that variables that belong to each possible | 42 // without -fdata-sections is so that variables that belong to each possible |
| 42 // SectionType are contiguous in the file. With -fdata-sections, each global | 43 // SectionType are contiguous in the file. With -fdata-sections, each global |
| 43 // variable is in a separate section and therefore the sections will be | 44 // variable is in a separate section and therefore the sections will be |
| 44 // trivially contiguous. | 45 // trivially contiguous. |
| 45 // | 46 // |
| 46 // The motivation for requiring that writeFunctionCode happen after | 47 // TODO(jpp): explain what's going on here. |
| 47 // writeDataSection: to keep the .text and .data sections contiguous in the | |
| 48 // file. Having both -fdata-sections and -ffunction-sections does allow | |
| 49 // relaxing this requirement. | |
| 50 class ELFObjectWriter { | 48 class ELFObjectWriter { |
| 51 ELFObjectWriter() = delete; | 49 ELFObjectWriter() = delete; |
| 52 ELFObjectWriter(const ELFObjectWriter &) = delete; | 50 ELFObjectWriter(const ELFObjectWriter &) = delete; |
| 53 ELFObjectWriter &operator=(const ELFObjectWriter &) = delete; | 51 ELFObjectWriter &operator=(const ELFObjectWriter &) = delete; |
| 54 | 52 |
| 55 public: | 53 public: |
| 56 ELFObjectWriter(GlobalContext &Ctx, ELFStreamer &Out); | 54 ELFObjectWriter(GlobalContext &Ctx, ELFStreamer &Out); |
| 57 | 55 |
| 58 // Write the initial ELF header. This is just to reserve space in the ELF | 56 // Write the initial ELF header. This is just to reserve space in the ELF |
| 59 // file. Reserving space allows the other functions to write text | 57 // file. Reserving space allows the other functions to write text |
| 60 // and data directly to the file and get the right file offsets. | 58 // and data directly to the file and get the right file offsets. |
| 61 void writeInitialELFHeader(); | 59 void writeInitialELFHeader(); |
| 62 | 60 |
| 63 // Copy initializer data for globals to file and note the offset and size | 61 // Copy initializer data for globals to file and note the offset and size |
| 64 // of each global's definition in the symbol table. | 62 // of each global's definition in the symbol table. |
| 65 // Use the given target's RelocationKind for any relocations. | 63 // Use the given target's RelocationKind for any relocations. |
| 66 void writeDataSection(const VariableDeclarationList &Vars, | 64 void writeDataSection(const VariableDeclarationList &Vars, |
| 67 FixupKind RelocationKind); | 65 FixupKind RelocationKind, |
| 66 const IceString &SectionSuffix); | |
| 68 | 67 |
| 69 // Copy data of a function's text section to file and note the offset of the | 68 // Copy data of a function's text section to file and note the offset of the |
| 70 // symbol's definition in the symbol table. | 69 // symbol's definition in the symbol table. |
| 71 // Copy the text fixups for use after all functions are written. | 70 // Copy the text fixups for use after all functions are written. |
| 72 // The text buffer and fixups are extracted from the Assembler object. | 71 // The text buffer and fixups are extracted from the Assembler object. |
| 73 void writeFunctionCode(const IceString &FuncName, bool IsInternal, | 72 void writeFunctionCode(const IceString &FuncName, bool IsInternal, |
| 74 const Assembler *Asm); | 73 const Assembler *Asm); |
| 75 | 74 |
| 76 // Queries the GlobalContext for constant pools of the given type | 75 // Queries the GlobalContext for constant pools of the given type |
| 77 // and writes out read-only data sections for those constants. This also | 76 // and writes out read-only data sections for those constants. This also |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 RelSectionList &RelSections, | 143 RelSectionList &RelSections, |
| 145 SectionList &AllSections); | 144 SectionList &AllSections); |
| 146 | 145 |
| 147 // Link the relocation sections to the symbol table. | 146 // Link the relocation sections to the symbol table. |
| 148 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); | 147 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); |
| 149 | 148 |
| 150 // Helper function for writeDataSection. Writes a data section of type | 149 // Helper function for writeDataSection. Writes a data section of type |
| 151 // SectionType, given the global variables Vars belonging to that SectionType. | 150 // SectionType, given the global variables Vars belonging to that SectionType. |
| 152 void writeDataOfType(SectionType SectionType, | 151 void writeDataOfType(SectionType SectionType, |
| 153 const VariableDeclarationList &Vars, | 152 const VariableDeclarationList &Vars, |
| 154 FixupKind RelocationKind); | 153 FixupKind RelocationKind, |
| 154 const IceString &SectionSuffix); | |
| 155 | 155 |
| 156 // Write the final relocation sections given the final symbol table. | 156 // Write the final relocation sections given the final symbol table. |
| 157 // 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 |
| 158 // that are for functions within the same section. | 158 // that are for functions within the same section. |
| 159 void writeAllRelocationSections(); | 159 void writeAllRelocationSections(); |
| 160 void writeRelocationSections(RelSectionList &RelSections); | 160 void writeRelocationSections(RelSectionList &RelSections); |
| 161 | 161 |
| 162 // Write the ELF file header with the given information about sections. | 162 // Write the ELF file header with the given information about sections. |
| 163 template <bool IsELF64> | 163 template <bool IsELF64> |
| 164 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset, | 164 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset, |
| 165 SizeT SectHeaderStrIndex, SizeT NumSections); | 165 SizeT SectHeaderStrIndex, SizeT NumSections); |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 } // end of namespace Ice | 168 } // end of namespace Ice |
| 169 | 169 |
| 170 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H | 170 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H |
| OLD | NEW |