OLD | NEW |
---|---|
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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 ELFDataSection *Section; | 311 ELFDataSection *Section; |
312 ELFRelocationSection *RelSection; | 312 ELFRelocationSection *RelSection; |
313 // TODO(jvoung): Handle fdata-sections. | 313 // TODO(jvoung): Handle fdata-sections. |
314 IceString SectionName; | 314 IceString SectionName; |
315 Elf64_Xword ShAddralign = 0; | 315 if (Vars.empty()) |
Jim Stichnoth
2015/02/02 21:57:26
Move this to the top? or at least above the IceSt
jvoung (off chromium)
2015/02/03 01:53:38
Done.
| |
316 return; | |
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 Loading... | |
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 Loading... | |
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 |
OLD | NEW |