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.
--- 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;