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 /// \file | 10 /// \file |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 } | 574 } |
575 | 575 |
576 void ELFObjectWriter::writeJumpTable(const JumpTableData &JT, | 576 void ELFObjectWriter::writeJumpTable(const JumpTableData &JT, |
577 FixupKind RelocationKind, bool IsPIC) { | 577 FixupKind RelocationKind, bool IsPIC) { |
578 TimerMarker Timer(TimerStack::TT_writeELF, &Ctx); | 578 TimerMarker Timer(TimerStack::TT_writeELF, &Ctx); |
579 ELFDataSection *Section; | 579 ELFDataSection *Section; |
580 ELFRelocationSection *RelSection; | 580 ELFRelocationSection *RelSection; |
581 const Elf64_Xword PointerSize = typeWidthInBytes(getPointerType()); | 581 const Elf64_Xword PointerSize = typeWidthInBytes(getPointerType()); |
582 const Elf64_Xword ShAddralign = PointerSize; | 582 const Elf64_Xword ShAddralign = PointerSize; |
583 const Elf64_Xword ShEntsize = PointerSize; | 583 const Elf64_Xword ShEntsize = PointerSize; |
584 const GlobalString JTName = JT.getFunctionName(); | |
585 const std::string SectionName = MangleSectionName( | 584 const std::string SectionName = MangleSectionName( |
586 IsPIC ? ".data.rel.ro" : ".rodata", | 585 IsPIC ? ".data.rel.ro" : ".rodata", JT.getSectionName()); |
587 (JTName.hasStdString() ? JTName.toString() | |
588 : std::to_string(JTName.getID())) + | |
589 "$jumptable"); | |
590 Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, SHF_ALLOC, | 586 Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, SHF_ALLOC, |
591 ShAddralign, ShEntsize); | 587 ShAddralign, ShEntsize); |
592 Section->setFileOffset(alignFileOffset(ShAddralign)); | 588 Section->setFileOffset(alignFileOffset(ShAddralign)); |
593 RODataSections.push_back(Section); | 589 RODataSections.push_back(Section); |
594 RelSection = createRelocationSection(Section); | 590 RelSection = createRelocationSection(Section); |
595 RelRODataSections.push_back(RelSection); | 591 RelRODataSections.push_back(RelSection); |
596 | 592 |
597 constexpr uint8_t SymbolType = STT_OBJECT; | 593 constexpr uint8_t SymbolType = STT_OBJECT; |
598 Section->padToAlignment(Str, PointerSize); | 594 Section->padToAlignment(Str, PointerSize); |
599 const bool IsExternal = getFlags().getDisableInternal(); | 595 const bool IsExternal = getFlags().getDisableInternal(); |
600 const uint8_t SymbolBinding = IsExternal ? STB_GLOBAL : STB_LOCAL; | 596 const uint8_t SymbolBinding = IsExternal ? STB_GLOBAL : STB_LOCAL; |
601 GlobalString JumpTableName = Ctx.getGlobalString( | 597 const auto JumpTableName = JT.getName(); |
602 InstJumpTable::makeName(JT.getFunctionName(), JT.getId())); | |
603 SymTab->createDefinedSym(JumpTableName, SymbolType, SymbolBinding, Section, | 598 SymTab->createDefinedSym(JumpTableName, SymbolType, SymbolBinding, Section, |
604 Section->getCurrentSize(), PointerSize); | 599 Section->getCurrentSize(), PointerSize); |
605 StrTab->add(JumpTableName); | 600 StrTab->add(JumpTableName); |
606 | 601 |
607 for (intptr_t TargetOffset : JT.getTargetOffsets()) { | 602 for (intptr_t TargetOffset : JT.getTargetOffsets()) { |
608 AssemblerFixup NewFixup; | 603 AssemblerFixup NewFixup; |
609 NewFixup.set_position(Section->getCurrentSize()); | 604 NewFixup.set_position(Section->getCurrentSize()); |
610 NewFixup.set_kind(RelocationKind); | 605 NewFixup.set_kind(RelocationKind); |
611 NewFixup.set_value(Ctx.getConstantSym(TargetOffset, JT.getFunctionName())); | 606 NewFixup.set_value(Ctx.getConstantSym(TargetOffset, JT.getFunctionName())); |
612 RelSection->addRelocation(NewFixup); | 607 RelSection->addRelocation(NewFixup); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 if (ELF64) { | 687 if (ELF64) { |
693 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), | 688 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), |
694 AllSections.size()); | 689 AllSections.size()); |
695 } else { | 690 } else { |
696 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), | 691 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), |
697 AllSections.size()); | 692 AllSections.size()); |
698 } | 693 } |
699 } | 694 } |
700 | 695 |
701 } // end of namespace Ice | 696 } // end of namespace Ice |
OLD | NEW |