Bug 816494 part 1 - When inserting a section before or after another, also insert it in the segments containing that other. r=nfroyd,a=akeybl
authorMike Hommey <mh+mozilla@glandium.org>
Mon, 10 Dec 2012 10:33:08 +0100
changeset 119177 bad85e46f9d5b9e2d8183110b46c5e17d5d7ade5
parent 119176 32dba69af0fa8df5a0db7e35b9ee7ad331e33535
child 119178 9f952d7c6bb1d74d4e7fbb03186a4b478d2d7cab
push id3101
push usermh@glandium.org
push dateFri, 04 Jan 2013 14:49:20 +0000
treeherdermozilla-aurora@84efed665a29 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd, akeybl
bugs816494
milestone19.0a2
Bug 816494 part 1 - When inserting a section before or after another, also insert it in the segments containing that other. r=nfroyd,a=akeybl
build/unix/elfhack/elfxx.h
--- a/build/unix/elfhack/elfxx.h
+++ b/build/unix/elfhack/elfxx.h
@@ -359,16 +359,17 @@ public:
             next = section->next;
             section->next = this;
         } else
             next = NULL;
         if (next != NULL)
             next->previous = this;
         if (dirty)
             markDirty();
+        insertInSegments(section->segments);
     }
 
     void insertBefore(ElfSection *section, bool dirty = true) {
         if (previous != NULL)
             previous->next = next;
         if (next != NULL)
             next->previous = previous;
         next = section;
@@ -376,16 +377,17 @@ public:
             previous = section->previous;
             section->previous = this;
         } else
             previous = NULL;
         if (previous != NULL)
             previous->next = this;
         if (dirty)
             markDirty();
+        insertInSegments(section->segments);
     }
 
     void markDirty() {
         if (link != NULL)
             shdr.sh_link = -1;
         if (info.index)
             shdr.sh_info = -1;
         shdr.sh_offset = -1;
@@ -411,16 +413,19 @@ private:
     }
 
     void removeFromSegment(ElfSegment *segment) {
         std::vector<ElfSegment *>::iterator i = std::find(segments.begin(), segments.end(), segment);
         segments.erase(i, i + 1);
     }
 
     bool isInSegmentType(unsigned int type);
+
+    void insertInSegments(std::vector<ElfSegment *> &segs);
+
 protected:
     Elf_Shdr shdr;
     char *data;
     const char *name;
 private:
     ElfSection *link;
     SectionInfo info;
     ElfSection *next, *previous;
@@ -645,16 +650,22 @@ inline unsigned int Elf::getSize() {
 
 inline bool ElfSection::isInSegmentType(unsigned int type) {
     for (std::vector<ElfSegment *>::iterator seg = segments.begin(); seg != segments.end(); seg++)
         if ((*seg)->getType() == type)
             return true;
     return false;
 }
 
+inline void ElfSection::insertInSegments(std::vector<ElfSegment *> &segs) {
+    for (std::vector<ElfSegment *>::iterator it = segs.begin(); it != segs.end(); ++it) {
+        (*it)->addSection(this);
+    }
+}
+
 inline ElfLocation::ElfLocation(ElfSection *section, unsigned int off, enum position pos)
 : section(section) {
     if ((pos == ABSOLUTE) && section)
         offset = off - section->getAddr();
     else
         offset = off;
 }