From: Shankar Easwaran Date: Fri, 7 Nov 2014 14:08:43 +0000 (+0000) Subject: [ELF] Remove is64bits() and isLittlEndian(). X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=35cab83409360d2402fde39a455a2a3f7602f2f1;p=platform%2Fupstream%2Fllvm.git [ELF] Remove is64bits() and isLittlEndian(). ELFLinkingContext had these two functions, which is really not needed since the Writer uses a llvm::object template composed of Endianness, Alignment, Is32bit/64bit. We could just use that and not duplicate functionality. No Change In Functionality. llvm-svn: 221523 --- diff --git a/lld/include/lld/ReaderWriter/ELFLinkingContext.h b/lld/include/lld/ReaderWriter/ELFLinkingContext.h index 3080977..05324ac 100644 --- a/lld/include/lld/ReaderWriter/ELFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/ELFLinkingContext.h @@ -58,8 +58,6 @@ public: }; llvm::Triple getTriple() const { return _triple; } - virtual bool is64Bits() const; - virtual bool isLittleEndian() const = 0; virtual uint64_t getPageSize() const { return 0x1000; } OutputMagic getOutputMagic() const { return _outputMagic; } uint16_t getOutputELFType() const { return _outputELFType; } diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h index 8e5a655..1480730 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h @@ -57,10 +57,6 @@ public: } } - bool isLittleEndian() const override { - return AArch64ELFType::TargetEndianness == llvm::support::little; - } - bool isCopyRelocation(const Reference &r) const override { if (r.kindNamespace() != Reference::KindNamespace::ELF) return false; diff --git a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp index c596aab..221a78b 100644 --- a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp @@ -64,8 +64,6 @@ ELFLinkingContext::ELFLinkingContext( _noAllowDynamicLibraries(false), _mergeRODataToTextSegment(true), _demangle(true), _outputMagic(OutputMagic::DEFAULT), _sysrootPath("") {} -bool ELFLinkingContext::is64Bits() const { return getTriple().isArch64Bit(); } - void ELFLinkingContext::addPasses(PassManager &pm) { if (_runLayoutPass) pm.add(std::unique_ptr(new LayoutPass(registry()))); diff --git a/lld/lib/ReaderWriter/ELF/HeaderChunks.h b/lld/lib/ReaderWriter/ELF/HeaderChunks.h index 5a83ee5..f274b70 100644 --- a/lld/lib/ReaderWriter/ELF/HeaderChunks.h +++ b/lld/lib/ReaderWriter/ELF/HeaderChunks.h @@ -56,7 +56,16 @@ public: virtual void doPreFlight() {} - void finalize() {} + void finalize() { + _eh.e_ident[llvm::ELF::EI_CLASS] = + (ELFT::Is64Bits) ? llvm::ELF::ELFCLASS64 : llvm::ELF::ELFCLASS32; + _eh.e_ident[llvm::ELF::EI_DATA] = + (ELFT::TargetEndianness == llvm::support::little) + ? llvm::ELF::ELFDATA2LSB + : llvm::ELF::ELFDATA2MSB; + _eh.e_type = this->_context.getOutputELFType(); + _eh.e_machine = this->_context.getOutputMachine(); + } private: Elf_Ehdr _eh; diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h index 42a85f7..06b40b0 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h @@ -62,10 +62,6 @@ public: } } - bool isLittleEndian() const override { - return HexagonELFType::TargetEndianness == llvm::support::little; - } - /// \brief Create Internal files for Init/Fini void createInternalFiles( std::vector> &result) const override; diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp index af3f8ad..31c8608 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp @@ -20,10 +20,6 @@ MipsLinkingContext::MipsLinkingContext(llvm::Triple triple) : ELFLinkingContext(triple, std::unique_ptr( new MipsTargetHandler(*this))) {} -bool MipsLinkingContext::isLittleEndian() const { - return Mips32ElELFType::TargetEndianness == llvm::support::little; -} - uint64_t MipsLinkingContext::getBaseAddress() const { if (_baseAddress == 0 && getOutputELFType() == llvm::ELF::ET_EXEC) return 0x400000; diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h index ef8ff42..dfeb429 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h @@ -39,7 +39,6 @@ public: MipsLinkingContext(llvm::Triple triple); // ELFLinkingContext - bool isLittleEndian() const override; uint64_t getBaseAddress() const override; StringRef entrySymbolName() const override; StringRef getDefaultInterpreter() const override; diff --git a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h index 7eb9bd9..8231136 100644 --- a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h +++ b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h @@ -405,11 +405,6 @@ std::error_code OutputELFWriter::buildOutput(const File &file) { } template std::error_code OutputELFWriter::setELFHeader() { - _elfHeader->e_ident(ELF::EI_CLASS, - _context.is64Bits() ? ELF::ELFCLASS64 : ELF::ELFCLASS32); - _elfHeader->e_ident(ELF::EI_DATA, _context.isLittleEndian() - ? ELF::ELFDATA2LSB - : ELF::ELFDATA2MSB); _elfHeader->e_type(_context.getOutputELFType()); _elfHeader->e_machine(_context.getOutputMachine()); _elfHeader->e_ident(ELF::EI_VERSION, 1); @@ -450,6 +445,11 @@ std::error_code OutputELFWriter::writeOutput(const File &file, // HACK: We have to write out the header and program header here even though // they are a member of a segment because only sections are written in the // following loop. + + // Finalize ELF Header / Program Headers. + _elfHeader->finalize(); + _programHeader->finalize(); + _elfHeader->write(this, _layout, *buffer); _programHeader->write(this, _layout, *buffer); diff --git a/lld/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h b/lld/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h index ab42398..cd7a9f5 100644 --- a/lld/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h +++ b/lld/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h @@ -24,8 +24,6 @@ public: : ELFLinkingContext(triple, std::unique_ptr( new PPCTargetHandler(*this))) {} - bool isLittleEndian() const override { return false; } - /// \brief PPC has no relative relocations defined bool isRelativeReloc(const Reference &) const override { return false; } }; diff --git a/lld/lib/ReaderWriter/ELF/SectionChunks.h b/lld/lib/ReaderWriter/ELF/SectionChunks.h index 244382e..b3838ae 100644 --- a/lld/lib/ReaderWriter/ELF/SectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/SectionChunks.h @@ -903,10 +903,7 @@ public: this->setOrder(order); this->_flags = SHF_ALLOC; // Set the alignment properly depending on the target architecture - if (context.is64Bits()) - this->_align2 = 8; - else - this->_align2 = 4; + this->_align2 = ELFT::Is64Bits ? 8 : 4; if (context.isRelaOutputFormat()) { this->_entSize = sizeof(Elf_Rela); this->_type = SHT_RELA; @@ -1232,11 +1229,7 @@ public: this->_entSize = 4; this->_type = SHT_HASH; this->_flags = SHF_ALLOC; - // Set the alignment properly depending on the target architecture - if (context.is64Bits()) - this->_align2 = 8; - else - this->_align2 = 4; + this->_align2 = ELFT::Is64Bits ? 8 : 4; this->_fsize = 0; this->_msize = 0; } @@ -1340,11 +1333,7 @@ public: this->_entSize = 0; this->_type = SHT_PROGBITS; this->_flags = SHF_ALLOC; - // Set the alignment properly depending on the target architecture - if (context.is64Bits()) - this->_align2 = 8; - else - this->_align2 = 4; + this->_align2 = ELFT::Is64Bits ? 8 : 4; // Minimum size for empty .eh_frame_hdr. this->_fsize = 1 + 1 + 1 + 1 + 4; this->_msize = this->_fsize; diff --git a/lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h b/lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h index 0ff5773..8792566 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h +++ b/lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h @@ -23,10 +23,6 @@ public: : ELFLinkingContext(triple, std::unique_ptr( new X86TargetHandler(*this))) {} - bool isLittleEndian() const override { - return X86ELFType::TargetEndianness == llvm::support::little; - } - /// \brief X86 has only two relative relocation /// a) for supporting IFUNC relocs - R_386_IRELATIVE /// b) for supporting relative relocs - R_386_RELATIVE diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h index b45abaa..45f81b4 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h @@ -56,10 +56,6 @@ public: } } - bool isLittleEndian() const override { - return X86_64ELFType::TargetEndianness == llvm::support::little; - } - bool isCopyRelocation(const Reference &r) const override { if (r.kindNamespace() != Reference::KindNamespace::ELF) return false;