Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: src/IceELFObjectWriter.h

Issue 1216963007: Doxygenize the documentation comments (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #ifndef SUBZERO_SRC_ICEELFOBJECTWRITER_H 14 #ifndef SUBZERO_SRC_ICEELFOBJECTWRITER_H
15 #define SUBZERO_SRC_ICEELFOBJECTWRITER_H 15 #define SUBZERO_SRC_ICEELFOBJECTWRITER_H
16 16
17 #include "IceDefs.h" 17 #include "IceDefs.h"
18 #include "IceELFSection.h" 18 #include "IceELFSection.h"
19 #include "IceELFStreamer.h" 19 #include "IceELFStreamer.h"
20 #include "IceTypes.h" 20 #include "IceTypes.h"
21 21
22 using namespace llvm::ELF; 22 using namespace llvm::ELF;
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 (may be invoked multiple times, as long as 33 /// (2) writeDataSection (may be invoked multiple times, as long as
34 // SectionSuffix is unique) 34 /// SectionSuffix is unique)
35 // (3) writeFunctionCode (must invoke once per function) 35 /// (3) writeFunctionCode (must invoke once per function)
36 // (4) writeConstantPool (must invoke once per pooled primitive type) 36 /// (4) writeConstantPool (must invoke once per pooled primitive type)
37 // (5) setUndefinedSyms (invoke once) 37 /// (5) setUndefinedSyms (invoke once)
38 // (6) writeNonUserSections (invoke once) 38 /// (6) writeNonUserSections (invoke once)
39 // 39 ///
40 // The requirement for writeDataSection to be invoked only once can 40 /// The requirement for writeDataSection to be invoked only once can
41 // 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
42 // 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
43 // SectionType are contiguous in the file. With -fdata-sections, each global 43 /// SectionType are contiguous in the file. With -fdata-sections, each global
44 // 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
45 // trivially contiguous. 45 /// trivially contiguous.
46 class ELFObjectWriter { 46 class ELFObjectWriter {
47 ELFObjectWriter() = delete; 47 ELFObjectWriter() = delete;
48 ELFObjectWriter(const ELFObjectWriter &) = delete; 48 ELFObjectWriter(const ELFObjectWriter &) = delete;
49 ELFObjectWriter &operator=(const ELFObjectWriter &) = delete; 49 ELFObjectWriter &operator=(const ELFObjectWriter &) = delete;
50 50
51 public: 51 public:
52 ELFObjectWriter(GlobalContext &Ctx, ELFStreamer &Out); 52 ELFObjectWriter(GlobalContext &Ctx, ELFStreamer &Out);
53 53
54 // Write the initial ELF header. This is just to reserve space in the ELF 54 /// Write the initial ELF header. This is just to reserve space in the ELF
55 // file. Reserving space allows the other functions to write text 55 /// file. Reserving space allows the other functions to write text
56 // and data directly to the file and get the right file offsets. 56 /// and data directly to the file and get the right file offsets.
57 void writeInitialELFHeader(); 57 void writeInitialELFHeader();
58 58
59 // Copy initializer data for globals to file and note the offset and size 59 /// Copy initializer data for globals to file and note the offset and size
60 // of each global's definition in the symbol table. 60 /// of each global's definition in the symbol table.
61 // Use the given target's RelocationKind for any relocations. 61 /// Use the given target's RelocationKind for any relocations.
62 void writeDataSection(const VariableDeclarationList &Vars, 62 void writeDataSection(const VariableDeclarationList &Vars,
63 FixupKind RelocationKind, 63 FixupKind RelocationKind,
64 const IceString &SectionSuffix); 64 const IceString &SectionSuffix);
65 65
66 // Copy data of a function's text section to file and note the offset of the 66 /// Copy data of a function's text section to file and note the offset of the
67 // symbol's definition in the symbol table. 67 /// symbol's definition in the symbol table.
68 // Copy the text fixups for use after all functions are written. 68 /// Copy the text fixups for use after all functions are written.
69 // The text buffer and fixups are extracted from the Assembler object. 69 /// The text buffer and fixups are extracted from the Assembler object.
70 void writeFunctionCode(const IceString &FuncName, bool IsInternal, 70 void writeFunctionCode(const IceString &FuncName, bool IsInternal,
71 const Assembler *Asm); 71 const Assembler *Asm);
72 72
73 // Queries the GlobalContext for constant pools of the given type 73 /// Queries the GlobalContext for constant pools of the given type
74 // and writes out read-only data sections for those constants. This also 74 /// and writes out read-only data sections for those constants. This also
75 // fills the symbol table with labels for each constant pool entry. 75 /// fills the symbol table with labels for each constant pool entry.
76 template <typename ConstType> void writeConstantPool(Type Ty); 76 template <typename ConstType> void writeConstantPool(Type Ty);
77 77
78 // Populate the symbol table with a list of external/undefined symbols. 78 /// Populate the symbol table with a list of external/undefined symbols.
79 void setUndefinedSyms(const ConstantList &UndefSyms); 79 void setUndefinedSyms(const ConstantList &UndefSyms);
80 80
81 // Do final layout and write out the rest of the object file. 81 /// Do final layout and write out the rest of the object file.
82 // Finally, patch up the initial ELF header with the final info. 82 /// Finally, patch up the initial ELF header with the final info.
83 void writeNonUserSections(); 83 void writeNonUserSections();
84 84
85 // Which type of ELF section a global variable initializer belongs to. 85 /// Which type of ELF section a global variable initializer belongs to.
86 // This is used as an array index so should start at 0 and be contiguous. 86 /// This is used as an array index so should start at 0 and be contiguous.
87 enum SectionType { ROData = 0, Data, BSS, NumSectionTypes }; 87 enum SectionType { ROData = 0, Data, BSS, NumSectionTypes };
88 88
89 private: 89 private:
90 GlobalContext &Ctx; 90 GlobalContext &Ctx;
91 ELFStreamer &Str; 91 ELFStreamer &Str;
92 bool SectionNumbersAssigned = false; 92 bool SectionNumbersAssigned = false;
93 bool ELF64; 93 bool ELF64;
94 94
95 // All created sections, separated into different pools. 95 // All created sections, separated into different pools.
96 typedef std::vector<ELFSection *> SectionList; 96 typedef std::vector<ELFSection *> SectionList;
(...skipping 12 matching lines...) Expand all
109 ELFSection *NullSection; 109 ELFSection *NullSection;
110 ELFStringTableSection *ShStrTab; 110 ELFStringTableSection *ShStrTab;
111 ELFSymbolTableSection *SymTab; 111 ELFSymbolTableSection *SymTab;
112 ELFStringTableSection *StrTab; 112 ELFStringTableSection *StrTab;
113 113
114 template <typename T> 114 template <typename T>
115 T *createSection(const IceString &Name, Elf64_Word ShType, 115 T *createSection(const IceString &Name, Elf64_Word ShType,
116 Elf64_Xword ShFlags, Elf64_Xword ShAddralign, 116 Elf64_Xword ShFlags, Elf64_Xword ShAddralign,
117 Elf64_Xword ShEntsize); 117 Elf64_Xword ShEntsize);
118 118
119 // Create a relocation section, given the related section 119 /// Create a relocation section, given the related section
120 // (e.g., .text, .data., .rodata). 120 /// (e.g., .text, .data., .rodata).
121 ELFRelocationSection * 121 ELFRelocationSection *
122 createRelocationSection(const ELFSection *RelatedSection); 122 createRelocationSection(const ELFSection *RelatedSection);
123 123
124 // Align the file position before writing out a section's data, 124 /// Align the file position before writing out a section's data,
125 // and return the position of the file. 125 /// and return the position of the file.
126 Elf64_Off alignFileOffset(Elf64_Xword Align); 126 Elf64_Off alignFileOffset(Elf64_Xword Align);
127 127
128 // Assign an ordering / section numbers to each section. 128 /// Assign an ordering / section numbers to each section.
129 // Fill in other information that is only known near the end 129 /// Fill in other information that is only known near the end
130 // (such as the size, if it wasn't already incrementally updated). 130 /// (such as the size, if it wasn't already incrementally updated).
131 // This then collects all sections in the decided order, into one vector, 131 /// This then collects all sections in the decided order, into one vector,
132 // for conveniently writing out all of the section headers. 132 /// for conveniently writing out all of the section headers.
133 void assignSectionNumbersInfo(SectionList &AllSections); 133 void assignSectionNumbersInfo(SectionList &AllSections);
134 134
135 // This function assigns .foo and .rel.foo consecutive section numbers. 135 /// This function assigns .foo and .rel.foo consecutive section numbers.
136 // It also sets the relocation section's sh_info field to the related 136 /// It also sets the relocation section's sh_info field to the related
137 // section's number. 137 /// section's number.
138 template <typename UserSectionList> 138 template <typename UserSectionList>
139 void assignRelSectionNumInPairs(SizeT &CurSectionNumber, 139 void assignRelSectionNumInPairs(SizeT &CurSectionNumber,
140 UserSectionList &UserSections, 140 UserSectionList &UserSections,
141 RelSectionList &RelSections, 141 RelSectionList &RelSections,
142 SectionList &AllSections); 142 SectionList &AllSections);
143 143
144 // Link the relocation sections to the symbol table. 144 /// Link the relocation sections to the symbol table.
145 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); 145 void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections);
146 146
147 // Helper function for writeDataSection. Writes a data section of type 147 /// Helper function for writeDataSection. Writes a data section of type
148 // SectionType, given the global variables Vars belonging to that SectionType. 148 /// SectionType, given the global variables Vars belonging to that SectionType .
149 void writeDataOfType(SectionType SectionType, 149 void writeDataOfType(SectionType SectionType,
150 const VariableDeclarationList &Vars, 150 const VariableDeclarationList &Vars,
151 FixupKind RelocationKind, 151 FixupKind RelocationKind,
152 const IceString &SectionSuffix); 152 const IceString &SectionSuffix);
153 153
154 // Write the final relocation sections given the final symbol table. 154 /// Write the final relocation sections given the final symbol table.
155 // May also be able to seek around the file and resolve function calls 155 /// May also be able to seek around the file and resolve function calls
156 // that are for functions within the same section. 156 /// that are for functions within the same section.
157 void writeAllRelocationSections(); 157 void writeAllRelocationSections();
158 void writeRelocationSections(RelSectionList &RelSections); 158 void writeRelocationSections(RelSectionList &RelSections);
159 159
160 // Write the ELF file header with the given information about sections. 160 /// Write the ELF file header with the given information about sections.
161 template <bool IsELF64> 161 template <bool IsELF64>
162 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset, 162 void writeELFHeaderInternal(Elf64_Off SectionHeaderOffset,
163 SizeT SectHeaderStrIndex, SizeT NumSections); 163 SizeT SectHeaderStrIndex, SizeT NumSections);
164 }; 164 };
165 165
166 } // end of namespace Ice 166 } // end of namespace Ice
167 167
168 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H 168 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698