Bug 1423813 - Properly handle elfhack -r after bug 1385783. r?froydnj draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 07 Dec 2017 15:22:22 +0900
changeset 708785 7c6c75e3e8891d9e8ece389c5eeeb942fd543bb4
parent 708775 e7ee17e0a8cfaf9f1477de85f35f6f44c01b4fc4
child 708811 9fa4d8c66ecb53793c890478871572aef6638e35
push id92452
push userbmo:mh+mozilla@glandium.org
push dateThu, 07 Dec 2017 06:46:31 +0000
reviewersfroydnj
bugs1423813, 1385783
milestone59.0a1
Bug 1423813 - Properly handle elfhack -r after bug 1385783. r?froydnj Bug 1385783 changed things such that the two elfhack sections are not adjacent anymore. They can even be in different segments in some cases, but the undo code doesn't know how to actually handle that case. So for now, allow non adjacent sections, but still verify that they are in the same segment.
build/unix/elfhack/elfhack.cpp
build/unix/elfhack/elfxx.h
--- a/build/unix/elfhack/elfhack.cpp
+++ b/build/unix/elfhack/elfhack.cpp
@@ -896,23 +896,24 @@ void undo_file(const char *name, bool ba
             (strcmp(section->getName(), elfhack_text) == 0))
             text = section;
     }
 
     if (!data || !text) {
         fprintf(stderr, "Not elfhacked. Skipping\n");
         return;
     }
-    if (data != text->getNext()) {
-        fprintf(stderr, elfhack_data " section not following " elfhack_text ". Skipping\n");
+
+    ElfSegment *first = data->getSegmentByType(PT_LOAD);
+    ElfSegment *second = text->getSegmentByType(PT_LOAD);
+    if (first != second) {
+        fprintf(stderr, elfhack_data " and " elfhack_text " not in the same segment. Skipping\n");
         return;
     }
-
-    ElfSegment *first = elf.getSegmentByType(PT_LOAD);
-    ElfSegment *second = elf.getSegmentByType(PT_LOAD, first);
+    second = elf.getSegmentByType(PT_LOAD, first);
     ElfSegment *filler = nullptr;
     // If the second PT_LOAD is a filler from elfhack --fill, check the third.
     if (second->isElfHackFillerSegment()) {
         filler = second;
         second = elf.getSegmentByType(PT_LOAD, filler);
     }
     if (second->getFlags() != first->getFlags()) {
         fprintf(stderr, "Couldn't identify elfhacked PT_LOAD segments. Skipping\n");
--- a/build/unix/elfhack/elfxx.h
+++ b/build/unix/elfhack/elfxx.h
@@ -416,30 +416,30 @@ public:
     virtual void serialize(std::ofstream &file, char ei_class, char ei_data)
     {
         if (getType() == SHT_NOBITS)
             return;
         file.seekp(getOffset());
         file.write(data, getSize());
     }
 
+    ElfSegment *getSegmentByType(unsigned int type);
+
 private:
     friend class ElfSegment;
 
     void addToSegment(ElfSegment *segment) {
         segments.push_back(segment);
     }
 
     void removeFromSegment(ElfSegment *segment) {
         std::vector<ElfSegment *>::iterator i = std::find(segments.begin(), segments.end(), segment);
         segments.erase(i, i + 1);
     }
 
-    ElfSegment *getSegmentByType(unsigned int type);
-
     void insertInSegments(std::vector<ElfSegment *> &segs);
 
 protected:
     Elf_Shdr shdr;
     char *data;
     const char *name;
 private:
     ElfSection *link;