[ELF] Remove is64bits() and isLittlEndian().
authorShankar Easwaran <shankare@codeaurora.org>
Fri, 7 Nov 2014 14:08:43 +0000 (14:08 +0000)
committerShankar Easwaran <shankare@codeaurora.org>
Fri, 7 Nov 2014 14:08:43 +0000 (14:08 +0000)
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

12 files changed:
lld/include/lld/ReaderWriter/ELFLinkingContext.h
lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h
lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
lld/lib/ReaderWriter/ELF/HeaderChunks.h
lld/lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
lld/lib/ReaderWriter/ELF/OutputELFWriter.h
lld/lib/ReaderWriter/ELF/PPC/PPCLinkingContext.h
lld/lib/ReaderWriter/ELF/SectionChunks.h
lld/lib/ReaderWriter/ELF/X86/X86LinkingContext.h
lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h

index 3080977..05324ac 100644 (file)
@@ -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; }
index 8e5a655..1480730 100644 (file)
@@ -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;
index c596aab..221a78b 100644 (file)
@@ -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())));
index 5a83ee5..f274b70 100644 (file)
@@ -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;
index 42a85f7..06b40b0 100644 (file)
@@ -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;
index af3f8ad..31c8608 100644 (file)
@@ -20,10 +20,6 @@ MipsLinkingContext::MipsLinkingContext(llvm::Triple triple)
     : 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;
index ef8ff42..dfeb429 100644 (file)
@@ -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;
index 7eb9bd9..8231136 100644 (file)
@@ -405,11 +405,6 @@ std::error_code OutputELFWriter<ELFT>::buildOutput(const File &file) {
 }
 
 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>::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);
 
index ab42398..cd7a9f5 100644 (file)
@@ -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; }
 };
index 244382e..b3838ae 100644 (file)
@@ -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;
index 0ff5773..8792566 100644 (file)
@@ -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
index b45abaa..45f81b4 100644 (file)
@@ -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;