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

Side by Side Diff: src/IceELFObjectWriter.cpp

Issue 899483002: Subzero: Track protos + globals w/out initializers as undef too (not just helper funcs) (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: rebase Created 5 years, 10 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/IceConverter.cpp ('k') | src/PNaClTranslator.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/IceELFObjectWriter.cpp - ELF object file writer --------===// 1 //===- subzero/src/IceELFObjectWriter.cpp - ELF object file writer --------===//
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 // This file defines the writer for ELF relocatable object files. 10 // This file defines the writer for ELF relocatable object files.
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 size_t I = 0; 301 size_t I = 0;
302 for (auto &SectionList : VarsBySection) { 302 for (auto &SectionList : VarsBySection) {
303 writeDataOfType(static_cast<SectionType>(I++), SectionList, RelocationKind, 303 writeDataOfType(static_cast<SectionType>(I++), SectionList, RelocationKind,
304 IsELF64); 304 IsELF64);
305 } 305 }
306 } 306 }
307 307
308 void ELFObjectWriter::writeDataOfType(SectionType ST, 308 void ELFObjectWriter::writeDataOfType(SectionType ST,
309 const VariableDeclarationList &Vars, 309 const VariableDeclarationList &Vars,
310 FixupKind RelocationKind, bool IsELF64) { 310 FixupKind RelocationKind, bool IsELF64) {
311 if (Vars.empty())
312 return;
311 ELFDataSection *Section; 313 ELFDataSection *Section;
312 ELFRelocationSection *RelSection; 314 ELFRelocationSection *RelSection;
313 // TODO(jvoung): Handle fdata-sections. 315 // TODO(jvoung): Handle fdata-sections.
314 IceString SectionName; 316 IceString SectionName;
315 Elf64_Xword ShAddralign = 0; 317 Elf64_Xword ShAddralign = 1;
316 for (VariableDeclaration *Var : Vars) { 318 for (VariableDeclaration *Var : Vars) {
317 Elf64_Xword Align = Var->getAlignment(); 319 Elf64_Xword Align = Var->getAlignment();
318 ShAddralign = std::max(ShAddralign, Align); 320 ShAddralign = std::max(ShAddralign, Align);
319 } 321 }
320 const Elf64_Xword ShEntsize = 0; // non-uniform data element size. 322 const Elf64_Xword ShEntsize = 0; // non-uniform data element size.
321 // Lift this out, so it can be re-used if we do fdata-sections? 323 // Lift this out, so it can be re-used if we do fdata-sections?
322 switch (ST) { 324 switch (ST) {
323 case ROData: { 325 case ROData: {
324 SectionName = ".rodata"; 326 SectionName = ".rodata";
325 // Only expecting to write the data sections all in one shot for now. 327 // Only expecting to write the data sections all in one shot for now.
(...skipping 29 matching lines...) Expand all
355 BSSSections.push_back(Section); 357 BSSSections.push_back(Section);
356 break; 358 break;
357 } 359 }
358 case NumSectionTypes: 360 case NumSectionTypes:
359 llvm::report_fatal_error("Unknown SectionType"); 361 llvm::report_fatal_error("Unknown SectionType");
360 break; 362 break;
361 } 363 }
362 364
363 const uint8_t SymbolType = STT_OBJECT; 365 const uint8_t SymbolType = STT_OBJECT;
364 for (VariableDeclaration *Var : Vars) { 366 for (VariableDeclaration *Var : Vars) {
367 // If the variable declaration does not have an initializer, its symtab
368 // entry will be created separately.
369 if (!Var->hasInitializer())
370 continue;
365 Elf64_Xword Align = Var->getAlignment(); 371 Elf64_Xword Align = Var->getAlignment();
366 Section->padToAlignment(Str, Align); 372 Section->padToAlignment(Str, Align);
367 SizeT SymbolSize = Var->getNumBytes(); 373 SizeT SymbolSize = Var->getNumBytes();
368 bool IsExternal = Var->isExternal() || Ctx.getFlags().DisableInternal; 374 bool IsExternal = Var->isExternal() || Ctx.getFlags().DisableInternal;
369 const uint8_t SymbolBinding = IsExternal ? STB_GLOBAL : STB_LOCAL; 375 const uint8_t SymbolBinding = IsExternal ? STB_GLOBAL : STB_LOCAL;
370 IceString MangledName = Var->mangleName(&Ctx); 376 IceString MangledName = Var->mangleName(&Ctx);
371 SymTab->createDefinedSym(MangledName, SymbolType, SymbolBinding, Section, 377 SymTab->createDefinedSym(MangledName, SymbolType, SymbolBinding, Section,
372 Section->getCurrentSize(), SymbolSize); 378 Section->getCurrentSize(), SymbolSize);
373 StrTab->add(MangledName); 379 StrTab->add(MangledName);
374 if (!Var->hasNonzeroInitializer()) { 380 if (!Var->hasNonzeroInitializer()) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 if (IsELF64) { 608 if (IsELF64) {
603 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), 609 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(),
604 AllSections.size()); 610 AllSections.size());
605 } else { 611 } else {
606 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), 612 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(),
607 AllSections.size()); 613 AllSections.size());
608 } 614 }
609 } 615 }
610 616
611 } // end of namespace Ice 617 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceConverter.cpp ('k') | src/PNaClTranslator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698