Chromium Code Reviews| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 if (ST == ROData) | 383 if (ST == ROData) |
| 384 Section->appendZeros(Str, SymbolSize); | 384 Section->appendZeros(Str, SymbolSize); |
| 385 else | 385 else |
| 386 Section->setSize(Section->getCurrentSize() + SymbolSize); | 386 Section->setSize(Section->getCurrentSize() + SymbolSize); |
| 387 } else { | 387 } else { |
| 388 assert(ST != BSS); | 388 assert(ST != BSS); |
| 389 for (const std::unique_ptr<VariableDeclaration::Initializer> &Init : | 389 for (const std::unique_ptr<VariableDeclaration::Initializer> &Init : |
| 390 Var->getInitializers()) { | 390 Var->getInitializers()) { |
| 391 switch (Init->getKind()) { | 391 switch (Init->getKind()) { |
| 392 case VariableDeclaration::Initializer::DataInitializerKind: { | 392 case VariableDeclaration::Initializer::DataInitializerKind: { |
| 393 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>( | 393 const auto Data = |
|
John
2015/06/24 00:24:00
please change this to
const auto& Data,
or this
qining
2015/06/24 01:20:40
Done.
| |
| 394 Init.get())->getContents(); | 394 llvm::cast<VariableDeclaration::DataInitializer>(Init.get()) |
| 395 ->getContents(); | |
| 395 Section->appendData(Str, llvm::StringRef(Data.data(), Data.size())); | 396 Section->appendData(Str, llvm::StringRef(Data.data(), Data.size())); |
| 396 break; | 397 break; |
| 397 } | 398 } |
| 398 case VariableDeclaration::Initializer::ZeroInitializerKind: | 399 case VariableDeclaration::Initializer::ZeroInitializerKind: |
| 399 Section->appendZeros(Str, Init->getNumBytes()); | 400 Section->appendZeros(Str, Init->getNumBytes()); |
| 400 break; | 401 break; |
| 401 case VariableDeclaration::Initializer::RelocInitializerKind: { | 402 case VariableDeclaration::Initializer::RelocInitializerKind: { |
| 402 const auto Reloc = | 403 const auto Reloc = |
| 403 llvm::cast<VariableDeclaration::RelocInitializer>(Init.get()); | 404 llvm::cast<VariableDeclaration::RelocInitializer>(Init.get()); |
| 404 AssemblerFixup NewFixup; | 405 AssemblerFixup NewFixup; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 SecStrBuf << ".rodata.cst" << WriteAmt; | 501 SecStrBuf << ".rodata.cst" << WriteAmt; |
| 501 ELFDataSection *Section = createSection<ELFDataSection>( | 502 ELFDataSection *Section = createSection<ELFDataSection>( |
| 502 SecStrBuf.str(), SHT_PROGBITS, ShFlags, Align, WriteAmt); | 503 SecStrBuf.str(), SHT_PROGBITS, ShFlags, Align, WriteAmt); |
| 503 RODataSections.push_back(Section); | 504 RODataSections.push_back(Section); |
| 504 SizeT OffsetInSection = 0; | 505 SizeT OffsetInSection = 0; |
| 505 // The symbol table entry doesn't need to know the defined symbol's | 506 // The symbol table entry doesn't need to know the defined symbol's |
| 506 // size since this is in a section with a fixed Entry Size. | 507 // size since this is in a section with a fixed Entry Size. |
| 507 const SizeT SymbolSize = 0; | 508 const SizeT SymbolSize = 0; |
| 508 Section->setFileOffset(alignFileOffset(Align)); | 509 Section->setFileOffset(alignFileOffset(Align)); |
| 509 | 510 |
| 511 // If the -reorder-pooled-constant option is set to true, we should shuffle | |
| 512 // the constants before we emit them. | |
| 513 if (Ctx.getFlags().shouldReorderPooledConstants()) | |
| 514 RandomShuffle(Pool.begin(), Pool.end(), [this](uint64_t N) { | |
|
John
2015/06/24 00:24:00
Can you capture [Ctx] instead of [this]?
qining
2015/06/24 01:20:40
Done. But it seems I can't capture Ctx or its refe
John
2015/06/24 08:15:54
Oh, I was genuinely asking whether capturing [Ctx]
| |
| 515 return (uint32_t)Ctx.getRNG().next(N); | |
| 516 }); | |
| 517 | |
| 510 // Write the data. | 518 // Write the data. |
| 511 for (Constant *C : Pool) { | 519 for (Constant *C : Pool) { |
| 512 if (!C->getShouldBePooled()) | 520 if (!C->getShouldBePooled()) |
| 513 continue; | 521 continue; |
| 514 auto Const = llvm::cast<ConstType>(C); | 522 auto Const = llvm::cast<ConstType>(C); |
| 515 std::string SymBuffer; | 523 std::string SymBuffer; |
| 516 llvm::raw_string_ostream SymStrBuf(SymBuffer); | 524 llvm::raw_string_ostream SymStrBuf(SymBuffer); |
| 517 Const->emitPoolLabel(SymStrBuf); | 525 Const->emitPoolLabel(SymStrBuf); |
| 518 std::string &SymName = SymStrBuf.str(); | 526 std::string &SymName = SymStrBuf.str(); |
| 519 SymTab->createDefinedSym(SymName, STT_NOTYPE, STB_LOCAL, Section, | 527 SymTab->createDefinedSym(SymName, STT_NOTYPE, STB_LOCAL, Section, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 if (ELF64) { | 625 if (ELF64) { |
| 618 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), | 626 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), |
| 619 AllSections.size()); | 627 AllSections.size()); |
| 620 } else { | 628 } else { |
| 621 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), | 629 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), |
| 622 AllSections.size()); | 630 AllSections.size()); |
| 623 } | 631 } |
| 624 } | 632 } |
| 625 | 633 |
| 626 } // end of namespace Ice | 634 } // end of namespace Ice |
| OLD | NEW |