Bug 1499915 - Support undoing elfhack when the elfhacked sections are in separate segments r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 24 Oct 2018 13:42:38 +0000
changeset 442869 550a527e90ee52ce0ec3095b2fd977446ee2f5f2
parent 442868 0988f87f6bd2504463cea12fe0f2ba9ef5317b38
child 442870 fbe393405a4ac2fccae94a26d173fc9fbe30e276
push id34926
push userncsoregi@mozilla.com
push dateThu, 25 Oct 2018 04:44:20 +0000
treeherdermozilla-central@58b7faab3b8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1499915, 1423813, 1385783, 1423822
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1499915 - Support undoing elfhack when the elfhacked sections are in separate segments r=froydnj This is some sort of followup to bug 1423813, providing a minimalistic way to undo elfhack when the elfhack sections are in separate segments, which has been the case since bug 1385783 but didn't cause problems on Android builds until bug 1423822. Depends on D9622 Differential Revision: https://phabricator.services.mozilla.com/D9623
build/unix/elfhack/elfhack.cpp
--- a/build/unix/elfhack/elfhack.cpp
+++ b/build/unix/elfhack/elfhack.cpp
@@ -1201,34 +1201,39 @@ void undo_file(const char *name, bool ba
             text = section;
     }
 
     if (!data || !text) {
         fprintf(stderr, "Not elfhacked. Skipping\n");
         return;
     }
 
+    // When both elfhack sections are in the same segment, try to merge
+    // the segment that contains them both and the following segment.
+    // When the elfhack sections are in separate segments, try to merge
+    // those segments.
     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;
+    if (first == second) {
+        second = elf.getSegmentByType(PT_LOAD, first);
     }
-    second = elf.getSegmentByType(PT_LOAD, first);
+
+    // Only merge the segments when their flags match.
     if (second->getFlags() != first->getFlags()) {
-        fprintf(stderr, "Couldn't identify elfhacked PT_LOAD segments. Skipping\n");
+        fprintf(stderr, "Couldn't merge PT_LOAD segments. Skipping\n");
         return;
     }
     // Move sections from the second PT_LOAD to the first, and remove the
     // second PT_LOAD segment.
     for (std::list<ElfSection *>::iterator section = second->begin();
          section != second->end(); ++section)
         first->addSection(*section);
 
     elf.removeSegment(second);
+    elf.normalize();
 
     if (backup && backup_file(name) != 0) {
         fprintf(stderr, "Couln't create backup file\n");
     } else {
         std::ofstream ofile(name, std::ios::out|std::ios::binary|std::ios::trunc);
         elf.write(ofile);
         fprintf(stderr, "Grown by %d bytes\n", elf.getSize() - size);
     }