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

Side by Side Diff: src/IceELFObjectWriter.cpp

Issue 1257283004: Iasm and obj lowering for advanced switch lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 4 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 /// \file 10 /// \file
11 /// This file defines the writer for ELF relocatable object files. 11 /// This file defines the writer for ELF relocatable object files.
12 /// 12 ///
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "IceELFObjectWriter.h" 15 #include "IceELFObjectWriter.h"
16 16
17 #include "IceAssembler.h" 17 #include "IceAssembler.h"
18 #include "IceDefs.h" 18 #include "IceDefs.h"
19 #include "IceELFSection.h" 19 #include "IceELFSection.h"
20 #include "IceELFStreamer.h" 20 #include "IceELFStreamer.h"
21 #include "IceGlobalContext.h" 21 #include "IceGlobalContext.h"
22 #include "IceGlobalInits.h" 22 #include "IceGlobalInits.h"
23 #include "IceInst.h"
23 #include "IceOperand.h" 24 #include "IceOperand.h"
24 #include "llvm/Support/MathExtras.h" 25 #include "llvm/Support/MathExtras.h"
25 26
26 using namespace llvm::ELF; 27 using namespace llvm::ELF;
27 28
28 namespace Ice { 29 namespace Ice {
29 30
30 namespace { 31 namespace {
31 32
32 struct { 33 struct {
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 template void ELFObjectWriter::writeConstantPool<ConstantDouble>(Type Ty); 547 template void ELFObjectWriter::writeConstantPool<ConstantDouble>(Type Ty);
547 548
548 template void ELFObjectWriter::writeConstantPool<ConstantInteger32>(Type Ty); 549 template void ELFObjectWriter::writeConstantPool<ConstantInteger32>(Type Ty);
549 550
550 void ELFObjectWriter::writeAllRelocationSections() { 551 void ELFObjectWriter::writeAllRelocationSections() {
551 writeRelocationSections(RelTextSections); 552 writeRelocationSections(RelTextSections);
552 writeRelocationSections(RelDataSections); 553 writeRelocationSections(RelDataSections);
553 writeRelocationSections(RelRODataSections); 554 writeRelocationSections(RelRODataSections);
554 } 555 }
555 556
557 void ELFObjectWriter::writeJumpTable(const JumpTableData &JT,
558 FixupKind RelocationKind) {
559 ELFDataSection *Section;
560 ELFRelocationSection *RelSection;
561 const Elf64_Xword PointerSize = typeWidthInBytes(getPointerType());
562 const Elf64_Xword ShAddralign = PointerSize;
563 const Elf64_Xword ShEntsize = PointerSize;
564 const IceString SectionName =
565 MangleSectionName(".rodata", JT.getFunctionName() + "$jumptable");
566 Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, SHF_ALLOC,
567 ShAddralign, ShEntsize);
568 Section->setFileOffset(alignFileOffset(ShAddralign));
569 RODataSections.push_back(Section);
570 RelSection = createRelocationSection(Section);
571 RelRODataSections.push_back(RelSection);
572
573 const uint8_t SymbolType = STT_OBJECT;
574 Section->padToAlignment(Str, PointerSize);
575 bool IsExternal = Ctx.getFlags().getDisableInternal();
576 const uint8_t SymbolBinding = IsExternal ? STB_GLOBAL : STB_LOCAL;
577 IceString JumpTableName =
578 InstJumpTable::makeName(JT.getFunctionName(), JT.getId());
579 SymTab->createDefinedSym(JumpTableName, SymbolType, SymbolBinding, Section,
580 Section->getCurrentSize(), PointerSize);
581 StrTab->add(JumpTableName);
582
583 for (intptr_t TargetOffset : JT.getTargetOffsets()) {
584 AssemblerFixup NewFixup;
585 NewFixup.set_position(Section->getCurrentSize());
586 NewFixup.set_kind(RelocationKind);
587 constexpr bool SuppressMangling = true;
588 NewFixup.set_value(Ctx.getConstantSym(TargetOffset, JT.getFunctionName(),
589 SuppressMangling));
590 RelSection->addRelocation(NewFixup);
591 Section->appendRelocationOffset(Str, RelSection->isRela(), TargetOffset);
592 }
593 }
594
556 void ELFObjectWriter::setUndefinedSyms(const ConstantList &UndefSyms) { 595 void ELFObjectWriter::setUndefinedSyms(const ConstantList &UndefSyms) {
557 for (const Constant *S : UndefSyms) { 596 for (const Constant *S : UndefSyms) {
558 const auto Sym = llvm::cast<ConstantRelocatable>(S); 597 const auto Sym = llvm::cast<ConstantRelocatable>(S);
559 const IceString &Name = Sym->getName(); 598 const IceString &Name = Sym->getName();
560 bool BadIntrinsic; 599 bool BadIntrinsic;
561 const Intrinsics::FullIntrinsicInfo *Info = 600 const Intrinsics::FullIntrinsicInfo *Info =
562 Ctx.getIntrinsicsInfo().find(Name, BadIntrinsic); 601 Ctx.getIntrinsicsInfo().find(Name, BadIntrinsic);
563 if (Info) 602 if (Info)
564 continue; 603 continue;
565 assert(!BadIntrinsic); 604 assert(!BadIntrinsic);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 if (ELF64) { 665 if (ELF64) {
627 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), 666 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(),
628 AllSections.size()); 667 AllSections.size());
629 } else { 668 } else {
630 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), 669 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(),
631 AllSections.size()); 670 AllSections.size());
632 } 671 }
633 } 672 }
634 673
635 } // end of namespace Ice 674 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698