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

Side by Side Diff: src/IceELFSection.h

Issue 1017373002: Subzero: Assemble calls to constant addresses. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: move test back Created 5 years, 9 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
« no previous file with comments | « src/IceELFObjectWriter.cpp ('k') | src/IceELFSection.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceELFSection.h - Model of ELF sections ------*- C++ -*-===// 1 //===- subzero/src/IceELFSection.h - Model of ELF sections ------*- 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 // Representation of ELF sections. 10 // Representation of ELF sections.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 }; 156 };
157 157
158 // Models a symbol table. Symbols may be added up until updateIndices is 158 // Models a symbol table. Symbols may be added up until updateIndices is
159 // called. At that point the indices of each symbol will be finalized. 159 // called. At that point the indices of each symbol will be finalized.
160 class ELFSymbolTableSection : public ELFSection { 160 class ELFSymbolTableSection : public ELFSection {
161 ELFSymbolTableSection() = delete; 161 ELFSymbolTableSection() = delete;
162 ELFSymbolTableSection(const ELFSymbolTableSection &) = delete; 162 ELFSymbolTableSection(const ELFSymbolTableSection &) = delete;
163 ELFSymbolTableSection &operator=(const ELFSymbolTableSection &) = delete; 163 ELFSymbolTableSection &operator=(const ELFSymbolTableSection &) = delete;
164 164
165 public: 165 public:
166 using ELFSection::ELFSection; 166 ELFSymbolTableSection(const IceString &Name, Elf64_Word ShType,
167 Elf64_Xword ShFlags, Elf64_Xword ShAddralign,
168 Elf64_Xword ShEntsize)
169 : ELFSection(Name, ShType, ShFlags, ShAddralign, ShEntsize),
170 NullSymbol(nullptr) {}
167 171
168 // Create initial entry for a symbol when it is defined. 172 // Create initial entry for a symbol when it is defined.
169 // Each entry should only be defined once. 173 // Each entry should only be defined once.
170 // We might want to allow Name to be a dummy name initially, then 174 // We might want to allow Name to be a dummy name initially, then
171 // get updated to the real thing, since Data initializers are read 175 // get updated to the real thing, since Data initializers are read
172 // before the bitcode's symbol table is read. 176 // before the bitcode's symbol table is read.
173 void createDefinedSym(const IceString &Name, uint8_t Type, uint8_t Binding, 177 void createDefinedSym(const IceString &Name, uint8_t Type, uint8_t Binding,
174 ELFSection *Section, RelocOffsetT Offset, SizeT Size); 178 ELFSection *Section, RelocOffsetT Offset, SizeT Size);
175 179
176 // Note that a symbol table entry needs to be created for the given 180 // Note that a symbol table entry needs to be created for the given
177 // symbol because it is undefined. 181 // symbol because it is undefined.
178 void noteUndefinedSym(const IceString &Name, ELFSection *NullSection); 182 void noteUndefinedSym(const IceString &Name, ELFSection *NullSection);
179 183
180 const ELFSym *findSymbol(const IceString &Name) const; 184 const ELFSym *findSymbol(const IceString &Name) const;
181 185
186 void createNullSymbol(ELFSection *NullSection);
187 const ELFSym *getNullSymbol() const { return NullSymbol; }
188
182 size_t getSectionDataSize() const { 189 size_t getSectionDataSize() const {
183 return (LocalSymbols.size() + GlobalSymbols.size()) * Header.sh_entsize; 190 return (LocalSymbols.size() + GlobalSymbols.size()) * Header.sh_entsize;
184 } 191 }
185 192
186 size_t getNumLocals() const { return LocalSymbols.size(); } 193 size_t getNumLocals() const { return LocalSymbols.size(); }
187 194
188 void updateIndices(const ELFStringTableSection *StrTab); 195 void updateIndices(const ELFStringTableSection *StrTab);
189 196
190 void writeData(ELFStreamer &Str, bool IsELF64); 197 void writeData(ELFStreamer &Str, bool IsELF64);
191 198
192 private: 199 private:
193 // Map from symbol name to its symbol information. 200 // Map from symbol name to its symbol information.
194 // This assumes symbols are unique across all sections. 201 // This assumes symbols are unique across all sections.
195 typedef IceString SymtabKey; 202 typedef IceString SymtabKey;
196 typedef std::map<SymtabKey, ELFSym> SymMap; 203 typedef std::map<SymtabKey, ELFSym> SymMap;
197 204
198 template <bool IsELF64> 205 template <bool IsELF64>
199 void writeSymbolMap(ELFStreamer &Str, const SymMap &Map); 206 void writeSymbolMap(ELFStreamer &Str, const SymMap &Map);
200 207
208 const ELFSym *NullSymbol;
201 // Keep Local and Global symbols separate, since the sh_info needs to 209 // Keep Local and Global symbols separate, since the sh_info needs to
202 // know the index of the last LOCAL. 210 // know the index of the last LOCAL.
203 SymMap LocalSymbols; 211 SymMap LocalSymbols;
204 SymMap GlobalSymbols; 212 SymMap GlobalSymbols;
205 }; 213 };
206 214
207 // Models a relocation section. 215 // Models a relocation section.
208 class ELFRelocationSection : public ELFSection { 216 class ELFRelocationSection : public ELFSection {
209 ELFRelocationSection() = delete; 217 ELFRelocationSection() = delete;
210 ELFRelocationSection(const ELFRelocationSection &) = delete; 218 ELFRelocationSection(const ELFRelocationSection &) = delete;
211 ELFRelocationSection &operator=(const ELFRelocationSection &) = delete; 219 ELFRelocationSection &operator=(const ELFRelocationSection &) = delete;
212 220
213 public: 221 public:
214 using ELFSection::ELFSection; 222 ELFRelocationSection(const IceString &Name, Elf64_Word ShType,
223 Elf64_Xword ShFlags, Elf64_Xword ShAddralign,
224 Elf64_Xword ShEntsize)
225 : ELFSection(Name, ShType, ShFlags, ShAddralign, ShEntsize),
226 RelatedSection(nullptr) {}
215 227
216 const ELFSection *getRelatedSection() const { return RelatedSection; } 228 const ELFSection *getRelatedSection() const { return RelatedSection; }
217 void setRelatedSection(const ELFSection *Section) { 229 void setRelatedSection(const ELFSection *Section) {
218 RelatedSection = Section; 230 RelatedSection = Section;
219 } 231 }
220 232
221 // Track additional relocations which start out relative to offset 0, 233 // Track additional relocations which start out relative to offset 0,
222 // but should be adjusted to be relative to BaseOff. 234 // but should be adjusted to be relative to BaseOff.
223 void addRelocations(RelocOffsetT BaseOff, const FixupRefList &FixupRefs); 235 void addRelocations(RelocOffsetT BaseOff, const FixupRefList &FixupRefs);
224 236
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 Str.write8(SymInfo.st_other); 345 Str.write8(SymInfo.st_other);
334 Str.writeLE16(SymInfo.st_shndx); 346 Str.writeLE16(SymInfo.st_shndx);
335 } 347 }
336 } 348 }
337 } 349 }
338 350
339 template <bool IsELF64> 351 template <bool IsELF64>
340 void ELFRelocationSection::writeData(const GlobalContext &Ctx, ELFStreamer &Str, 352 void ELFRelocationSection::writeData(const GlobalContext &Ctx, ELFStreamer &Str,
341 const ELFSymbolTableSection *SymTab) { 353 const ELFSymbolTableSection *SymTab) {
342 for (const AssemblerFixup &Fixup : Fixups) { 354 for (const AssemblerFixup &Fixup : Fixups) {
343 const ELFSym *Symbol = SymTab->findSymbol(Fixup.symbol(&Ctx)); 355 const ELFSym *Symbol;
356 if (Fixup.isNullSymbol())
357 Symbol = SymTab->getNullSymbol();
358 else
359 Symbol = SymTab->findSymbol(Fixup.symbol(&Ctx));
344 if (!Symbol) 360 if (!Symbol)
345 llvm::report_fatal_error("Missing symbol mentioned in reloc"); 361 llvm::report_fatal_error("Missing symbol mentioned in reloc");
346 362
347 if (IsELF64) { 363 if (IsELF64) {
348 Elf64_Rela Rela; 364 Elf64_Rela Rela;
349 Rela.r_offset = Fixup.position(); 365 Rela.r_offset = Fixup.position();
350 Rela.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); 366 Rela.setSymbolAndType(Symbol->getNumber(), Fixup.kind());
351 Rela.r_addend = Fixup.offset(); 367 Rela.r_addend = Fixup.offset();
352 Str.writeAddrOrOffset<IsELF64>(Rela.r_offset); 368 Str.writeAddrOrOffset<IsELF64>(Rela.r_offset);
353 Str.writeELFXword<IsELF64>(Rela.r_info); 369 Str.writeELFXword<IsELF64>(Rela.r_info);
354 Str.writeELFXword<IsELF64>(Rela.r_addend); 370 Str.writeELFXword<IsELF64>(Rela.r_addend);
355 } else { 371 } else {
356 Elf32_Rel Rel; 372 Elf32_Rel Rel;
357 Rel.r_offset = Fixup.position(); 373 Rel.r_offset = Fixup.position();
358 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); 374 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind());
359 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); 375 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset);
360 Str.writeELFWord<IsELF64>(Rel.r_info); 376 Str.writeELFWord<IsELF64>(Rel.r_info);
361 } 377 }
362 } 378 }
363 } 379 }
364 380
365 } // end of namespace Ice 381 } // end of namespace Ice
366 382
367 #endif // SUBZERO_SRC_ICEELFSECTION_H 383 #endif // SUBZERO_SRC_ICEELFSECTION_H
OLDNEW
« no previous file with comments | « src/IceELFObjectWriter.cpp ('k') | src/IceELFSection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698