[lld] r173743 - [ELF] Give Chunk a ELFTargetInfo.

Michael J. Spencer bigcheesegs at gmail.com
Mon Jan 28 17:07:47 PST 2013


Author: mspencer
Date: Mon Jan 28 19:07:47 2013
New Revision: 173743

URL: http://llvm.org/viewvc/llvm-project?rev=173743&view=rev
Log:
[ELF] Give Chunk a ELFTargetInfo.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h
    lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h
    lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h
    lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h
    lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h
    lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp

Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h?rev=173743&r1=173742&r2=173743&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultELFLayout.h Mon Jan 28 19:07:47 2013
@@ -406,8 +406,8 @@ DefaultELFLayout<ELFT>::addAtom(const At
     if (_sectionMap.find(sectionKey) == _sectionMap.end()) {
       SectionOrder section_order =
           getSectionOrder(sectionName, contentType, permissions);
-      section = new (_allocator.Allocate<Section<ELFT> >())
-          Section<ELFT>(sectionName, contentType, permissions, section_order);
+      section = new (_allocator) Section<ELFT>(
+          _targetInfo, sectionName, contentType, permissions, section_order);
       section->setOrder(section_order);
       _sections.push_back(section);
       _sectionMap.insert(std::make_pair(sectionKey, section));
@@ -487,8 +487,8 @@ DefaultELFLayout<ELFT>::assignSectionsTo
         if (!segmentInsert.second) {
           segment = segmentInsert.first->second;
         } else {
-          segment = new (_allocator.Allocate<Segment<ELFT>>()) Segment<ELFT>(
-            segmentName, getSegmentType(section), _targetInfo);
+          segment = new (_allocator)
+              Segment<ELFT>(_targetInfo, segmentName, getSegmentType(section));
           segmentInsert.first->second = segment;
           _segments.push_back(segment);
         }

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h?rev=173743&r1=173742&r2=173743&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFChunk.h Mon Jan 28 19:07:47 2013
@@ -37,16 +37,10 @@ public:
     K_ELFSection, // Section
     K_ELFSectionHeader // Section header
   };
-  Chunk(llvm::StringRef name, Kind kind)
-    : _name(name)
-    , _kind(kind)
-    , _fsize(0)
-    , _msize(0)
-    , _align2(0)
-    , _order(0)
-    , _ordinal(1)
-    , _start(0)
-    , _fileoffset(0) {}
+  Chunk(llvm::StringRef name, Kind kind, const ELFTargetInfo &ti)
+      : _name(name), _kind(kind), _fsize(0), _msize(0), _align2(0), _order(0),
+        _ordinal(1), _start(0), _fileoffset(0), _targetInfo(ti) {
+  }
   virtual             ~Chunk() {}
   // Does the chunk occupy disk space
   virtual bool        occupiesNoDiskSpace() const {
@@ -90,6 +84,7 @@ protected:
   uint64_t _ordinal;
   uint64_t _start;
   uint64_t _fileoffset;
+  const ELFTargetInfo &_targetInfo;
 };
 
 } // elf

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h?rev=173743&r1=173742&r2=173743&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFHeaderChunks.h Mon Jan 28 19:07:47 2013
@@ -30,7 +30,7 @@ class ELFHeader : public Chunk<ELFT> {
 public:
   typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
 
-  ELFHeader();
+  ELFHeader(const ELFTargetInfo &);
 
   void e_ident(int I, unsigned char C) { _eh.e_ident[I] = C; }
   void e_type(uint16_t type)           { _eh.e_type = type; }
@@ -60,9 +60,9 @@ private:
   Elf_Ehdr _eh;
 };
 
-template<class ELFT>
-ELFHeader<ELFT>::ELFHeader()
-: Chunk<ELFT>("elfhdr", Chunk<ELFT>::K_ELFHeader) {
+template <class ELFT>
+ELFHeader<ELFT>::ELFHeader(const ELFTargetInfo &ti)
+    : Chunk<ELFT>("elfhdr", Chunk<ELFT>::K_ELFHeader, ti) {
   this->_align2 = ELFT::Is64Bits ? 8 : 4;
   this->_fsize = sizeof(Elf_Ehdr);
   this->_msize = sizeof(Elf_Ehdr);
@@ -111,8 +111,8 @@ public:
     uint64_t _flagsClear;
   };
 
-  ELFProgramHeader()
-  : Chunk<ELFT>("elfphdr", Chunk<ELFT>::K_ELFProgramHeader) {
+  ELFProgramHeader(const ELFTargetInfo &ti)
+      : Chunk<ELFT>("elfphdr", Chunk<ELFT>::K_ELFProgramHeader, ti) {
     this->_align2 = ELFT::Is64Bits ? 8 : 4;
     resetProgramHeaders();
   }
@@ -213,7 +213,7 @@ class ELFSectionHeader : public Chunk<EL
 public:
   typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
 
-  ELFSectionHeader(int32_t order);
+  ELFSectionHeader(const ELFTargetInfo &, int32_t order);
 
   void appendSection(MergedSections<ELFT> *section);
   
@@ -249,9 +249,9 @@ private:
   llvm::BumpPtrAllocator                  _sectionAllocate;
 };
 
-template<class ELFT>
-ELFSectionHeader<ELFT>::ELFSectionHeader(int32_t order) 
-  : Chunk<ELFT>("shdr", Chunk<ELFT>::K_ELFSectionHeader) {
+template <class ELFT>
+ELFSectionHeader<ELFT>::ELFSectionHeader(const ELFTargetInfo &ti, int32_t order)
+    : Chunk<ELFT>("shdr", Chunk<ELFT>::K_ELFSectionHeader, ti) {
   this->_fsize = 0;
   this->_align2 = 8;
   this->setOrder(order);

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h?rev=173743&r1=173742&r2=173743&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFSectionChunks.h Mon Jan 28 19:07:47 2013
@@ -46,11 +46,9 @@ public:
   };
   // Create a section object, the section is set to the default type if the
   // caller doesnot set it
-  Section(const llvm::StringRef sectionName,
-          const int32_t contentType,
-          const int32_t contentPermissions,
-          const int32_t order,
-          const SectionKind kind = K_Default);
+  Section(const ELFTargetInfo &, const llvm::StringRef sectionName,
+          const int32_t contentType, const int32_t contentPermissions,
+          const int32_t order, const SectionKind kind = K_Default);
 
   /// return the section kind
   inline SectionKind sectionKind() const {
@@ -179,19 +177,14 @@ protected:
 
 // Create a section object, the section is set to the default type if the
 // caller doesnot set it
-template<class ELFT>
-Section<ELFT>::Section(const StringRef sectionName,
+template <class ELFT>
+Section<ELFT>::Section(const ELFTargetInfo &ti, const StringRef sectionName,
                        const int32_t contentType,
-                       const int32_t contentPermissions,
-                       const int32_t order,
+                       const int32_t contentPermissions, const int32_t order,
                        const SectionKind kind)
-  : Chunk<ELFT>(sectionName, Chunk<ELFT>::K_ELFSection)
-  , _contentType(contentType)
-  , _contentPermissions(contentPermissions)
-  , _sectionKind(kind)
-  , _entSize(0)
-  , _shInfo(0)
-  , _link(0) {
+    : Chunk<ELFT>(sectionName, Chunk<ELFT>::K_ELFSection, ti),
+      _contentType(contentType), _contentPermissions(contentPermissions),
+      _sectionKind(kind), _entSize(0), _shInfo(0), _link(0) {
   this->setOrder(order);
 }
 
@@ -498,7 +491,7 @@ MergedSections<ELFT>::appendSection(Chun
 template<class ELFT>
 class ELFStringTable : public Section<ELFT> {
 public:
-  ELFStringTable(const char *str, int32_t order);
+  ELFStringTable(const ELFTargetInfo &, const char *str, int32_t order);
 
   static inline bool classof(const Chunk<ELFT> *c) {
     return c->kind() == Section<ELFT>::K_StringTable;
@@ -514,15 +507,11 @@ private:
   std::vector<llvm::StringRef> _strings;
 };
 
-template<class ELFT>
-ELFStringTable<ELFT>::ELFStringTable(const char *str, 
+template <class ELFT>
+ELFStringTable<ELFT>::ELFStringTable(const ELFTargetInfo &ti, const char *str,
                                      int32_t order)
-  : Section<ELFT>(
-      str,
-      llvm::ELF::SHT_STRTAB,
-      DefinedAtom::perm___,
-      order,
-      Section<ELFT>::K_StringTable) {
+    : Section<ELFT>(ti, str, llvm::ELF::SHT_STRTAB, DefinedAtom::perm___, order,
+                    Section<ELFT>::K_StringTable) {
   // the string table has a NULL entry for which
   // add an empty string
   _strings.push_back("");
@@ -559,7 +548,7 @@ class ELFSymbolTable : public Section<EL
 public:
   typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
 
-  ELFSymbolTable(const char *str, int32_t order);
+  ELFSymbolTable(const ELFTargetInfo &ti, const char *str, int32_t order);
 
   void addSymbol(const Atom *atom, int32_t sectionIndex, uint64_t addr = 0);
 
@@ -583,15 +572,11 @@ private:
 };
 
 /// ELF Symbol Table 
-template<class ELFT>
-ELFSymbolTable<ELFT>::ELFSymbolTable(const char *str, 
+template <class ELFT>
+ELFSymbolTable<ELFT>::ELFSymbolTable(const ELFTargetInfo &ti, const char *str,
                                      int32_t order)
-  : Section<ELFT>(
-      str,
-      llvm::ELF::SHT_SYMTAB,
-      0,
-      order,
-      Section<ELFT>::K_SymbolTable) {
+    : Section<ELFT>(ti, str, llvm::ELF::SHT_SYMTAB, 0, order,
+                    Section<ELFT>::K_SymbolTable) {
   this->setOrder(order);
   Elf_Sym *symbol = new (_symbolAllocate.Allocate<Elf_Sym>()) Elf_Sym;
   memset((void *)symbol, 0, sizeof(Elf_Sym));

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h?rev=173743&r1=173742&r2=173743&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFSegmentChunks.h Mon Jan 28 19:07:47 2013
@@ -111,9 +111,8 @@ public:
   typedef typename std::vector<SegmentSlice<ELFT> *>::iterator SliceIter;
   typedef typename std::vector<Chunk<ELFT> *>::iterator SectionIter;
 
-  Segment(const StringRef name,
-          const ELFLayout::SegmentType type,
-          const ELFTargetInfo &ti);
+  Segment(const ELFTargetInfo &ti, const StringRef name,
+          const ELFLayout::SegmentType type);
 
   /// append a section to a segment
   void append(Section<ELFT> *section);
@@ -168,7 +167,7 @@ public:
 
   inline ELFLayout::SegmentType segmentType() { return _segmentType; }
 
-  inline int pageSize() const { return _targetInfo.getPageSize(); }
+  inline int pageSize() const { return this->_targetInfo.getPageSize(); }
 
   inline int64_t atomflags() const { return _atomflags; }
 
@@ -195,19 +194,14 @@ protected:
   ELFLayout::SegmentType _segmentType;
   int64_t _flags;
   int64_t _atomflags;
-  const ELFTargetInfo &_targetInfo;
   llvm::BumpPtrAllocator _segmentAllocate;
 };
 
-template<class ELFT>
-Segment<ELFT>::Segment(const StringRef name,
-                       const ELFLayout::SegmentType type,
-                       const ELFTargetInfo &ti)
-  : Chunk<ELFT>(name, Chunk<ELFT>::K_ELFSegment)
-  , _segmentType(type)
-  , _flags(0)
-  , _atomflags(0)
-  , _targetInfo(ti) {
+template <class ELFT>
+Segment<ELFT>::Segment(const ELFTargetInfo &ti, const StringRef name,
+                       const ELFLayout::SegmentType type)
+    : Chunk<ELFT>(name, Chunk<ELFT>::K_ELFSegment, ti), _segmentType(type),
+      _flags(0), _atomflags(0) {
   this->_align2 = 0;
   this->_fsize = 0;
 }
@@ -268,7 +262,7 @@ Segment<ELFT>::assignOffsets(uint64_t st
       SegmentSlice<ELFT> *slice = nullptr;
       // If the newOffset computed is more than a page away, lets create
       // a seperate segment, so that memory is not used up while running
-      if ((newOffset - curOffset) > _targetInfo.getPageSize()) {
+      if ((newOffset - curOffset) > this->_targetInfo.getPageSize()) {
         // TODO: use std::find here
         for (auto s : slices()) {
           if (s->startSection() == startSection) {
@@ -285,8 +279,8 @@ Segment<ELFT>::assignOffsets(uint64_t st
         slice->setSections(make_range(startSectionIter, endSectionIter));
         slice->setSize(curSliceSize);
         slice->setAlign(sliceAlign);
-        uint64_t newPageOffset =
-          llvm::RoundUpToAlignment(curOffset, _targetInfo.getPageSize());
+        uint64_t newPageOffset = llvm::RoundUpToAlignment(
+            curOffset, this->_targetInfo.getPageSize());
         newOffset = llvm::RoundUpToAlignment(newPageOffset, (*si)->align2());
         curSliceFileOffset = newOffset;
         startSectionIter = endSectionIter;
@@ -332,7 +326,7 @@ void 
 Segment<ELFT>::assignVirtualAddress(uint64_t &addr) {
   for (auto slice : slices()) {
     // Align to a page
-    addr = llvm::RoundUpToAlignment(addr, _targetInfo.getPageSize());
+    addr = llvm::RoundUpToAlignment(addr, this->_targetInfo.getPageSize());
     // Align to the slice alignment
     addr = llvm::RoundUpToAlignment(addr, slice->align2());
 

Modified: lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp?rev=173743&r1=173742&r2=173743&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp Mon Jan 28 19:07:47 2013
@@ -285,19 +285,19 @@ ELFExecutableWriter<ELFT>::writeFile(con
 
 template<class ELFT>
 void ELFExecutableWriter<ELFT>::createDefaultSections() {
-  _elfHeader = new ELFHeader<ELFT>();
-  _programHeader = new ELFProgramHeader<ELFT>();
+  _elfHeader = new ELFHeader<ELFT>(_targetInfo);
+  _programHeader = new ELFProgramHeader<ELFT>(_targetInfo);
   _layout->setELFHeader(_elfHeader);
   _layout->setProgramHeader(_programHeader);
 
-  _symtab = new ELFSymbolTable<ELFT>(
-    ".symtab", DefaultELFLayout<ELFT>::ORDER_SYMBOL_TABLE);
-  _strtab = new ELFStringTable<ELFT>(
-    ".strtab", DefaultELFLayout<ELFT>::ORDER_STRING_TABLE);
+  _symtab = new ELFSymbolTable<
+      ELFT>(_targetInfo, ".symtab", DefaultELFLayout<ELFT>::ORDER_SYMBOL_TABLE);
+  _strtab = new ELFStringTable<
+      ELFT>(_targetInfo, ".strtab", DefaultELFLayout<ELFT>::ORDER_STRING_TABLE);
   _shstrtab = new ELFStringTable<ELFT>(
-    ".shstrtab", DefaultELFLayout<ELFT>::ORDER_SECTION_STRINGS);
-  _shdrtab  = new ELFSectionHeader<ELFT>(
-    DefaultELFLayout<ELFT>::ORDER_SECTION_HEADERS);
+      _targetInfo, ".shstrtab", DefaultELFLayout<ELFT>::ORDER_SECTION_STRINGS);
+  _shdrtab = new ELFSectionHeader<
+      ELFT>(_targetInfo, DefaultELFLayout<ELFT>::ORDER_SECTION_HEADERS);
   _layout->addSection(_symtab);
   _layout->addSection(_strtab);
   _layout->addSection(_shstrtab);





More information about the llvm-commits mailing list