From a827925ebe5643ef03ca50dc307b1542f58c5378 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Wed, 3 Aug 2011 10:28:47 +0200 Subject: [PATCH] Bug 674888 - Allow elfhack to move .interp sections. r=tglek --- build/unix/elfhack/elf.cpp | 5 ++++- build/unix/elfhack/elfxx.h | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/build/unix/elfhack/elf.cpp b/build/unix/elfhack/elf.cpp index 31a30a8e6b5d..071891fe55ad 100644 --- a/build/unix/elfhack/elf.cpp +++ b/build/unix/elfhack/elf.cpp @@ -566,6 +566,7 @@ void ElfSegment::addSection(ElfSection *section) if ((*i)->getAddr() > section->getAddr()) break; sections.insert(i, section); + section->addToSegment(this); } unsigned int ElfSegment::getFileSize() @@ -636,8 +637,10 @@ ElfSegment *ElfSegment::splitBefore(ElfSection *section) phdr.p_memsz = (unsigned int)-1; ElfSegment *segment = new ElfSegment(&phdr); - for (rm = i; i != sections.end(); ++i) + for (rm = i; i != sections.end(); ++i) { + (*i)->removeFromSegment(this); segment->addSection(*i); + } sections.erase(rm, sections.end()); return segment; diff --git a/build/unix/elfhack/elfxx.h b/build/unix/elfhack/elfxx.h index d06271c12bd7..4ecb1fb8eb39 100644 --- a/build/unix/elfhack/elfxx.h +++ b/build/unix/elfhack/elfxx.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -370,7 +371,8 @@ public: (getType() == SHT_GNU_HASH) || (getType() == SHT_GNU_verdef) || (getType() == SHT_GNU_verneed) || - (getType() == SHT_GNU_versym)) && + (getType() == SHT_GNU_versym) || + isInSegmentType(PT_INTERP)) && (getFlags() & SHF_ALLOC); } @@ -410,6 +412,20 @@ public: file.seekp(getOffset()); file.write(data, getSize()); } + +private: + friend class ElfSegment; + + void addToSegment(ElfSegment *segment) { + segments.push_back(segment); + } + + void removeFromSegment(ElfSegment *segment) { + std::vector::iterator i = std::find(segments.begin(), segments.end(), segment); + segments.erase(i, i + 1); + } + + bool isInSegmentType(unsigned int type); protected: Elf_Shdr shdr; char *data; @@ -419,6 +435,7 @@ private: SectionInfo info; ElfSection *next, *previous; int index; + std::vector segments; }; class ElfSegment { @@ -636,6 +653,13 @@ inline unsigned int Elf::getSize() { return section->getOffset() + section->getSize(); } +inline bool ElfSection::isInSegmentType(unsigned int type) { + for (std::vector::iterator seg = segments.begin(); seg != segments.end(); seg++) + if ((*seg)->getType() == type) + return true; + return false; +} + inline ElfLocation::ElfLocation(ElfSection *section, unsigned int off, enum position pos) : section(section) { if ((pos == ABSOLUTE) && section)