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

Side by Side Diff: src/IceELFObjectWriter.cpp

Issue 1185703004: Add constant blinding/pooling option for X8632 code translation (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: reformat Created 5 years, 6 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.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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 assert(ST == BSS || ST == ROData); 376 assert(ST == BSS || ST == ROData);
377 if (ST == ROData) 377 if (ST == ROData)
378 Section->appendZeros(Str, SymbolSize); 378 Section->appendZeros(Str, SymbolSize);
379 else 379 else
380 Section->setSize(Section->getCurrentSize() + SymbolSize); 380 Section->setSize(Section->getCurrentSize() + SymbolSize);
381 } else { 381 } else {
382 assert(ST != BSS); 382 assert(ST != BSS);
383 for (VariableDeclaration::Initializer *Init : Var->getInitializers()) { 383 for (VariableDeclaration::Initializer *Init : Var->getInitializers()) {
384 switch (Init->getKind()) { 384 switch (Init->getKind()) {
385 case VariableDeclaration::Initializer::DataInitializerKind: { 385 case VariableDeclaration::Initializer::DataInitializerKind: {
386 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>( 386 const auto Data =
387 Init)->getContents(); 387 llvm::cast<VariableDeclaration::DataInitializer>(Init)
388 ->getContents();
388 Section->appendData(Str, llvm::StringRef(Data.data(), Data.size())); 389 Section->appendData(Str, llvm::StringRef(Data.data(), Data.size()));
389 break; 390 break;
390 } 391 }
391 case VariableDeclaration::Initializer::ZeroInitializerKind: 392 case VariableDeclaration::Initializer::ZeroInitializerKind:
392 Section->appendZeros(Str, Init->getNumBytes()); 393 Section->appendZeros(Str, Init->getNumBytes());
393 break; 394 break;
394 case VariableDeclaration::Initializer::RelocInitializerKind: { 395 case VariableDeclaration::Initializer::RelocInitializerKind: {
395 const auto Reloc = 396 const auto Reloc =
396 llvm::cast<VariableDeclaration::RelocInitializer>(Init); 397 llvm::cast<VariableDeclaration::RelocInitializer>(Init);
397 AssemblerFixup NewFixup; 398 AssemblerFixup NewFixup;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 RODataSections.push_back(Section); 498 RODataSections.push_back(Section);
498 SizeT OffsetInSection = 0; 499 SizeT OffsetInSection = 0;
499 // The symbol table entry doesn't need to know the defined symbol's 500 // The symbol table entry doesn't need to know the defined symbol's
500 // size since this is in a section with a fixed Entry Size. 501 // size since this is in a section with a fixed Entry Size.
501 const SizeT SymbolSize = 0; 502 const SizeT SymbolSize = 0;
502 Section->setFileOffset(alignFileOffset(Align)); 503 Section->setFileOffset(alignFileOffset(Align));
503 504
504 // Write the data. 505 // Write the data.
505 for (Constant *C : Pool) { 506 for (Constant *C : Pool) {
506 auto Const = llvm::cast<ConstType>(C); 507 auto Const = llvm::cast<ConstType>(C);
508 // When constant pooling turned on, only emit labels for eligible constants
Jim Stichnoth 2015/06/12 23:48:17 end sentence with period
qining 2015/06/17 04:28:53 Done.
509 // If C is i32 constant and not large enough, we should ignore it here.
510 if (llvm::isa<ConstantInteger32>(C) &&
Jim Stichnoth 2015/06/12 23:48:17 Normally this kind of type checking would be done
qining 2015/06/17 04:28:53 I have moved shouldBeRandomizedOrPooled() to class
511 llvm::dyn_cast_or_null<ConstantInteger32>(C)
512 ->shouldBeRandomizedOrPooled(&Ctx) == false)
Jim Stichnoth 2015/06/12 23:48:17 use "!x" instead of "x==false"
qining 2015/06/17 04:28:53 Done.
513 continue;
507 std::string SymBuffer; 514 std::string SymBuffer;
508 llvm::raw_string_ostream SymStrBuf(SymBuffer); 515 llvm::raw_string_ostream SymStrBuf(SymBuffer);
509 Const->emitPoolLabel(SymStrBuf); 516 Const->emitPoolLabel(SymStrBuf);
510 std::string &SymName = SymStrBuf.str(); 517 std::string &SymName = SymStrBuf.str();
511 SymTab->createDefinedSym(SymName, STT_NOTYPE, STB_LOCAL, Section, 518 SymTab->createDefinedSym(SymName, STT_NOTYPE, STB_LOCAL, Section,
512 OffsetInSection, SymbolSize); 519 OffsetInSection, SymbolSize);
513 StrTab->add(SymName); 520 StrTab->add(SymName);
514 typename ConstType::PrimType Value = Const->getValue(); 521 typename ConstType::PrimType Value = Const->getValue();
515 memcpy(Buf, &Value, WriteAmt); 522 memcpy(Buf, &Value, WriteAmt);
516 Str.writeBytes(llvm::StringRef(Buf, WriteAmt)); 523 Str.writeBytes(llvm::StringRef(Buf, WriteAmt));
517 OffsetInSection += WriteAmt; 524 OffsetInSection += WriteAmt;
518 } 525 }
519 Section->setSize(OffsetInSection); 526 Section->setSize(OffsetInSection);
520 } 527 }
521 528
522 // Instantiate known needed versions of the template, since we are 529 // Instantiate known needed versions of the template, since we are
523 // defining the function in the .cpp file instead of the .h file. 530 // defining the function in the .cpp file instead of the .h file.
524 // We may need to instantiate constant pools for integers as well 531 // We may need to instantiate constant pools for integers as well
525 // if we do constant-pooling of large integers to remove them 532 // if we do constant-pooling of large integers to remove them
526 // from the instruction stream (fewer bytes controlled by an attacker). 533 // from the instruction stream (fewer bytes controlled by an attacker).
527 template void ELFObjectWriter::writeConstantPool<ConstantFloat>(Type Ty); 534 template void ELFObjectWriter::writeConstantPool<ConstantFloat>(Type Ty);
528 535
529 template void ELFObjectWriter::writeConstantPool<ConstantDouble>(Type Ty); 536 template void ELFObjectWriter::writeConstantPool<ConstantDouble>(Type Ty);
530 537
538 template void ELFObjectWriter::writeConstantPool<ConstantInteger32>(Type Ty);
539
531 void ELFObjectWriter::writeAllRelocationSections() { 540 void ELFObjectWriter::writeAllRelocationSections() {
532 writeRelocationSections(RelTextSections); 541 writeRelocationSections(RelTextSections);
533 writeRelocationSections(RelDataSections); 542 writeRelocationSections(RelDataSections);
534 writeRelocationSections(RelRODataSections); 543 writeRelocationSections(RelRODataSections);
535 } 544 }
536 545
537 void ELFObjectWriter::setUndefinedSyms(const ConstantList &UndefSyms) { 546 void ELFObjectWriter::setUndefinedSyms(const ConstantList &UndefSyms) {
538 for (const Constant *S : UndefSyms) { 547 for (const Constant *S : UndefSyms) {
539 const auto Sym = llvm::cast<ConstantRelocatable>(S); 548 const auto Sym = llvm::cast<ConstantRelocatable>(S);
540 const IceString &Name = Sym->getName(); 549 const IceString &Name = Sym->getName();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 if (ELF64) { 616 if (ELF64) {
608 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), 617 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(),
609 AllSections.size()); 618 AllSections.size());
610 } else { 619 } else {
611 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), 620 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(),
612 AllSections.size()); 621 AllSections.size());
613 } 622 }
614 } 623 }
615 624
616 } // end of namespace Ice 625 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698