[lld] r221523 - [ELF] Remove is64bits() and isLittlEndian().
Shankar Easwaran
shankare at codeaurora.org
Fri Nov 7 06:08:44 PST 2014
Author: shankare
Date: Fri Nov 7 08:08:43 2014
New Revision: 221523
URL: http://llvm.org/viewvc/llvm-project?rev=221523&view=rev
Log:
[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.
Modified:
lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h
lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
lld/trunk/lib/ReaderWriter/ELF/X86/X86LinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h
Modified: lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h Fri Nov 7 08:08:43 2014
@@ -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; }
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h Fri Nov 7 08:08:43 2014
@@ -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;
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Fri Nov 7 08:08:43 2014
@@ -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<Pass>(new LayoutPass(registry())));
Modified: lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h Fri Nov 7 08:08:43 2014
@@ -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;
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h Fri Nov 7 08:08:43 2014
@@ -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<std::unique_ptr<File>> &result) const override;
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp Fri Nov 7 08:08:43 2014
@@ -20,10 +20,6 @@ MipsLinkingContext::MipsLinkingContext(l
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
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;
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h Fri Nov 7 08:08:43 2014
@@ -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;
Modified: lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h Fri Nov 7 08:08:43 2014
@@ -405,11 +405,6 @@ std::error_code OutputELFWriter<ELFT>::b
}
template <class ELFT> std::error_code OutputELFWriter<ELFT>::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<ELFT>::w
// 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);
Modified: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h Fri Nov 7 08:08:43 2014
@@ -24,8 +24,6 @@ public:
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new PPCTargetHandler(*this))) {}
- bool isLittleEndian() const override { return false; }
-
/// \brief PPC has no relative relocations defined
bool isRelativeReloc(const Reference &) const override { return false; }
};
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Fri Nov 7 08:08:43 2014
@@ -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;
Modified: lld/trunk/lib/ReaderWriter/ELF/X86/X86LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86LinkingContext.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86LinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86LinkingContext.h Fri Nov 7 08:08:43 2014
@@ -23,10 +23,6 @@ public:
: ELFLinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
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
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h?rev=221523&r1=221522&r2=221523&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h Fri Nov 7 08:08:43 2014
@@ -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;
More information about the llvm-commits
mailing list