Closed Bug 816494 Opened 12 years ago Closed 11 years ago

Allow to revert the effects of elfhack

Categories

(Firefox Build System :: General, defect)

All
Linux
defect
Not set
normal

Tracking

(b2g18 fixed, b2g18-v1.0.0 fixed)

RESOLVED FIXED
mozilla20
Tracking Status
b2g18 --- fixed
b2g18-v1.0.0 --- fixed

People

(Reporter: glandium, Assigned: glandium)

References

Details

Attachments

(5 files, 2 obsolete files)

2.69 KB, patch
froydnj
: review+
Details | Diff | Splinter Review
2.94 KB, patch
froydnj
: review+
Details | Diff | Splinter Review
2.88 KB, patch
khuey
: review+
Details | Diff | Splinter Review
14.81 KB, patch
froydnj
: review+
Details | Diff | Splinter Review
6.54 KB, patch
Details | Diff | Splinter Review
One of the annoying effect of elfhack is that some tools (like perf or valgrind) don't play very well with it. While some of the things elfhack does are destructive (removal of the __cxa_pure_virtual relocations), there is enough information in a elfhacked ELF binary to re-create something mostly identical to the original file.
Also, section offsets are not adjusted until the split is done.
Attachment #686572 - Flags: review?(nfroyd)
Sections are positioned accordingly, which means the resulting ELF binary will have a big gap full of zero between .rel.plt and .plt.
Attachment #686575 - Flags: review?(nfroyd)
(In reply to Mike Hommey [:glandium] from comment #4) > Created attachment 686575 [details] [diff] [review] > part 4 - Add a -r option to elfhack that re-merges the split PT_LOADs > > Sections are positioned accordingly, which means the resulting ELF binary > will > have a big gap full of zero between .rel.plt and .plt. At this point, we aren't really close to the original file, but it's unelfhacked enough that valgrind is happy.
Attachment #686576 - Flags: review?(khuey)
Attachment #686573 - Flags: review?(nfroyd) → review+
Attachment #686571 - Flags: review?(nfroyd) → review+
Comment on attachment 686572 [details] [diff] [review] part 2 - Move the PT_LOAD splitting logic in elfhack.cpp Review of attachment 686572 [details] [diff] [review]: ----------------------------------------------------------------- ::: build/unix/elfhack/elfhack.cpp @@ +535,5 @@ > + relhack->insertAfter(relhackcode); > + > + // Adjust PT_LOAD segments > + for (ElfSegment *segment = elf->getSegmentByType(PT_LOAD); segment; > + segment = elf->getSegmentByType(PT_LOAD, segment)) { The inner body of this loop probably deserves its own function for clarity's sake. @@ +539,5 @@ > + segment = elf->getSegmentByType(PT_LOAD, segment)) { > + std::list<ElfSection *>::iterator it = segment->begin(); > + for (ElfSection *last = *(it++); it != segment->end(); last = *(it++)) { > + if (((*it)->getType() != SHT_NOBITS) && (last->getType() != SHT_NOBITS) && > + ((*it)->getOffset() - last->getOffset() - last->getSize() > 0x1000)) { Is this magic 0x1000 supposed to be page size? Can we declare a |const| variable somewhere to make this clearer? Can this condition be given its own reasonably named function as well? @@ +551,5 @@ > + phdr.p_filesz = (unsigned int)-1; > + phdr.p_memsz = (unsigned int)-1; > + ElfSegment *newSegment = new ElfSegment(&phdr); > + elf->insertSegmentAfter(segment, newSegment); > + std::list<ElfSection *>::reverse_iterator firstSection(it); This variable is never used. ::: build/unix/elfhack/elfxx.h @@ +284,5 @@ > unsigned int getSize(); > + > + void insertSegmentAfter(ElfSegment *previous, ElfSegment *segment) { > + std::vector<ElfSegment *>::iterator prev = std::find(segments.begin(), segments.end(), previous); > + segments.insert(++prev, segment); Nit: I think |prev + 1| is clearer here in declaring intent and avoiding side-effects.
Attachment #686572 - Flags: review?(nfroyd) → review+
Attachment #686575 - Flags: review?(nfroyd) → review+
How about this? (I removed 0x1000 altogether, and used the PT_LOAD alignment instead, which is better)
Attachment #687662 - Flags: review?(nfroyd)
Attachment #686572 - Attachment is obsolete: true
Attachment #686575 - Attachment is obsolete: true
Attachment #687662 - Flags: review?(nfroyd) → review+
Whiteboard: [leave open]
Blocks: 822584
Comment on attachment 686571 [details] [diff] [review] part 1 - When inserting a section before or after another, also insert it in the segments containing that other. [Approval Request Comment] This patch is required for bug 822584 Testing completed: It has been on m-c for a while now. Risk to taking this patch (and alternatives if risky): Low. This patch doesn't have any impact on functionality. It only adds an API to elfhack (it's a build system change only, elfhack being a build tool). String or UUID changes made by this patch: None
Attachment #686571 - Flags: approval-mozilla-b2g18?
Attachment #686571 - Flags: approval-mozilla-aurora?
Comment on attachment 687662 [details] [diff] [review] part 2 - Move the PT_LOAD splitting logic in elfhack.cpp. section offsets are not adjusted until the split is done. [Approval Request Comment] This patch is required for bug 822584 Testing completed: It has been on m-c for a while now. Risk to taking this patch (and alternatives if risky): Low. This patch doesn't have any impact on functionality. It only moves code around in elfhack (it's a build system change only, elfhack being a build tool). String or UUID changes made by this patch: None
Attachment #687662 - Flags: approval-mozilla-b2g18?
Attachment #687662 - Flags: approval-mozilla-aurora?
Comment on attachment 686573 [details] [diff] [review] part 3 - Allocate Elf instance on stack in do_file() [Approval Request Comment] This patch is required for bug 822584 Testing completed: It has been on m-c for a while now. Risk to taking this patch (and alternatives if risky): Low. This patch doesn't have any impact on functionality. It only refactors a part of elfhack (it's a build system change only, elfhack being a build tool). String or UUID changes made by this patch: None
Attachment #686573 - Flags: approval-mozilla-b2g18?
Attachment #686573 - Flags: approval-mozilla-aurora?
Comment on attachment 687663 [details] [diff] [review] part 4 - Add a -r option to elfhack that re-merges the split PT_LOADs. are positioned accordingly, which means the resulting ELF binary will [Approval Request Comment] This patch is required for bug 822584 Testing completed: It has been on m-c for a while now. Risk to taking this patch (and alternatives if risky): Low. This patch only adds new API and feature to elfhack (it's a build system change only, elfhack being a build tool). The new feature is not used at build time. String or UUID changes made by this patch: None
Attachment #687663 - Flags: approval-mozilla-b2g18?
Attachment #687663 - Flags: approval-mozilla-aurora?
Attachment #686571 - Flags: approval-mozilla-b2g18?
Attachment #686571 - Flags: approval-mozilla-b2g18+
Attachment #686571 - Flags: approval-mozilla-aurora?
Attachment #686571 - Flags: approval-mozilla-aurora+
Attachment #686573 - Flags: approval-mozilla-b2g18?
Attachment #686573 - Flags: approval-mozilla-b2g18+
Attachment #686573 - Flags: approval-mozilla-aurora?
Attachment #686573 - Flags: approval-mozilla-aurora+
Attachment #687662 - Flags: approval-mozilla-b2g18?
Attachment #687662 - Flags: approval-mozilla-b2g18+
Attachment #687662 - Flags: approval-mozilla-aurora?
Attachment #687662 - Flags: approval-mozilla-aurora+
Attachment #687663 - Flags: approval-mozilla-b2g18?
Attachment #687663 - Flags: approval-mozilla-b2g18+
Attachment #687663 - Flags: approval-mozilla-aurora?
Attachment #687663 - Flags: approval-mozilla-aurora+
After so long without activity, let's say this is fixed. I'll open a new bug if I ever want to fix what I had left this bug open for.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Whiteboard: [leave open]
Target Milestone: --- → mozilla20
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: