Layout helper function.
authorMatt Fleming <matt@console-pimps.org>
Mon, 16 Aug 2010 18:35:06 +0000 (18:35 +0000)
committerMatt Fleming <matt@console-pimps.org>
Mon, 16 Aug 2010 18:35:06 +0000 (18:35 +0000)
Introduce a helper method to add a section to the end of a layout. This
will be used by the ELF ObjectWriter code to add the metadata sections
(symbol table, etc) to the end of an object file.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111171 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAssembler.h
lib/MC/MCAssembler.cpp

index e72011f0467779c0803b43b8d52eae86ae62ee3a..201df5eeaf0734b8b8c2bb0953c9ac1be2fe38d5 100644 (file)
@@ -664,6 +664,8 @@ public:
   void WriteSectionData(const MCSectionData *Section, const MCAsmLayout &Layout,
                         MCObjectWriter *OW) const;
 
+  void AddSectionToTheEnd(MCSectionData &SD, MCAsmLayout &Layout);
+
 public:
   /// Construct a new assembler instance.
   ///
index 8e255aa4ec44ed4a9727f8819cc4ac6483cd7d8b..35f39564cd5565f7ecbffb4d584767ebe7a6902b 100644 (file)
@@ -652,6 +652,40 @@ void MCAssembler::WriteSectionData(const MCSectionData *SD,
   assert(OW->getStream().tell() - Start == Layout.getSectionFileSize(SD));
 }
 
+void MCAssembler::AddSectionToTheEnd(MCSectionData &SD, MCAsmLayout &Layout) {
+  // Create dummy fragments and assign section ordinals.
+  unsigned SectionIndex = 0;
+  for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it)
+    SectionIndex++;
+
+  SD.setOrdinal(SectionIndex);
+
+  // Assign layout order indices to sections and fragments.
+  unsigned FragmentIndex = 0;
+  unsigned i = 0;
+  for (unsigned e = Layout.getSectionOrder().size(); i != e; ++i) {
+    MCSectionData *SD = Layout.getSectionOrder()[i];
+
+    for (MCSectionData::iterator it2 = SD->begin(),
+           ie2 = SD->end(); it2 != ie2; ++it2)
+      FragmentIndex++;
+  }
+
+  SD.setLayoutOrder(i);
+  for (MCSectionData::iterator it2 = SD.begin(),
+         ie2 = SD.end(); it2 != ie2; ++it2) {
+    it2->setLayoutOrder(FragmentIndex++);
+  }
+  Layout.getSectionOrder().push_back(&SD);
+
+  Layout.LayoutSection(&SD);
+
+  // Layout until everything fits.
+  while (LayoutOnce(Layout))
+    continue;
+
+}
+
 void MCAssembler::Finish(MCObjectWriter *Writer) {
   DEBUG_WITH_TYPE("mc-dump", {
       llvm::errs() << "assembler backend - pre-layout\n--\n";