From 0cf2b93ff25b373535812f5826f1ef0290525f23 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Wed, 24 Oct 2018 13:42:38 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- build/unix/elfhack/elfhack.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/build/unix/elfhack/elfhack.cpp b/build/unix/elfhack/elfhack.cpp index 44c6be6465ca..7cd4494b37cc 100644 --- a/build/unix/elfhack/elfhack.cpp +++ b/build/unix/elfhack/elfhack.cpp @@ -1206,15 +1206,19 @@ void undo_file(const char *name, bool backup = false) 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 @@ -1224,6 +1228,7 @@ void undo_file(const char *name, bool backup = false) first->addSection(*section); elf.removeSegment(second); + elf.normalize(); if (backup && backup_file(name) != 0) { fprintf(stderr, "Couln't create backup file\n");