-
Notifications
You must be signed in to change notification settings - Fork 821
DWARF: Update Ranges #2612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DWARF: Update Ranges #2612
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -368,7 +368,6 @@ struct AddrExprMap { | |
| } | ||
| } | ||
|
|
||
|
|
||
| Expression* getStart(BinaryLocation addr) const { | ||
| auto iter = startMap.find(addr); | ||
| if (iter != startMap.end()) { | ||
|
|
@@ -498,6 +497,10 @@ struct LocationUpdater { | |
| return 0; | ||
| } | ||
|
|
||
| bool hasOldExprEndAddr(BinaryLocation oldAddr) const { | ||
| return oldExprAddrMap.getEnd(oldAddr); | ||
| } | ||
|
|
||
| BinaryLocation getNewFuncStartAddr(BinaryLocation oldAddr) const { | ||
| if (auto* func = oldFuncAddrMap.getStart(oldAddr)) { | ||
| // The function might have been optimized away, check. | ||
|
|
@@ -612,7 +615,6 @@ static void updateDebugLines(llvm::DWARFYAML::Data& data, | |
| } else if (locationUpdater.hasOldExtraAddr(oldAddr)) { | ||
| newAddr = locationUpdater.getNewExtraAddr(oldAddr); | ||
| } | ||
| // TODO: last 'end' of a function | ||
| if (newAddr) { | ||
| // LLVM sometimes emits the same address more than once. We should | ||
| // probably investigate that. | ||
|
|
@@ -764,6 +766,55 @@ static void updateCompileUnits(const BinaryenDWARFInfo& info, | |
| }); | ||
| } | ||
|
|
||
| static void updateRanges(llvm::DWARFYAML::Data& yaml, | ||
| const LocationUpdater& locationUpdater) { | ||
| // In each range section, try to update the start and end. If we no longer | ||
| // have something to map them to, we must skip that part. | ||
| size_t skip = 0; | ||
| for (size_t i = 0; i < yaml.Ranges.size(); i++) { | ||
| auto& range = yaml.Ranges[i]; | ||
| BinaryLocation oldStart = range.Start, oldEnd = range.End, newStart = 0, | ||
| newEnd = 0; | ||
| // If this was not an end marker, try to find what it should be updated to. | ||
| if (oldStart != 0 && oldEnd != 0) { | ||
| if (locationUpdater.hasOldExprAddr(oldStart)) { | ||
| newStart = locationUpdater.getNewExprAddr(oldStart); | ||
| } else if (locationUpdater.hasOldFuncStartAddr(oldStart)) { | ||
| newStart = locationUpdater.getNewFuncStartAddr(oldStart); | ||
| } | ||
| if (locationUpdater.hasOldExprEndAddr(oldEnd)) { | ||
| newEnd = locationUpdater.getNewExprEndAddr(oldEnd); | ||
| } else if (locationUpdater.hasOldFuncEndAddr(oldEnd)) { | ||
| newEnd = locationUpdater.getNewFuncEndAddr(oldEnd); | ||
| } | ||
| if (newStart == 0 || newEnd == 0) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess in answer to my earlier question, If we have a range that represents a run of several instructions and we eliminate the last, I guess we don't have a good way to do "nearby" lookups in our current data structure. |
||
| // This part of the range no longer has a mapping, so we must skip it. | ||
| skip++; | ||
| continue; | ||
| } | ||
| // The range start and end markers have been preserved. However, TODO | ||
| // instructions in the middle may have moved around, making the range no | ||
| // longer contiguous, we should check that, and possibly split/merge | ||
| // the range. Or, we may need to have tracking in the IR for this. | ||
| } else { | ||
| // This was not a valid range in the old binary. It was either two 0's | ||
| // (an end marker) or an invalid value that should be ignored. Either way, | ||
| // write an end marker and finish the current section of ranges, filling | ||
| // it out to the original size (we must fill it out as indexes into | ||
| // the ranges section are not updated - we could update them and then | ||
| // pack the section, as an optimization TODO). | ||
| while (skip) { | ||
| auto& writtenRange = yaml.Ranges[i - skip]; | ||
| writtenRange.Start = writtenRange.End = 0; | ||
| skip--; | ||
| } | ||
| } | ||
| auto& writtenRange = yaml.Ranges[i - skip]; | ||
| writtenRange.Start = newStart; | ||
| writtenRange.End = newEnd; | ||
| } | ||
| } | ||
|
|
||
| void writeDWARFSections(Module& wasm, const BinaryLocations& newLocations) { | ||
| BinaryenDWARFInfo info(wasm); | ||
|
|
||
|
|
@@ -779,6 +830,8 @@ void writeDWARFSections(Module& wasm, const BinaryLocations& newLocations) { | |
|
|
||
| updateCompileUnits(info, data, locationUpdater); | ||
|
|
||
| updateRanges(data, locationUpdater); | ||
|
|
||
| // Convert to binary sections. | ||
| auto newSections = | ||
| EmitDebugSections(data, false /* EmitFixups for debug_info */); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have some kind of combined lookup like
hasOldExprOrFuncStartAddr()? I guess when updating ranges we have no way to tell the context of the use...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could refactor a function for this, but I don't think that would be reusable anywhere else. This is the one place where we update both sides of a span (start, end) at once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the second part, yeah, we can't tell the context atm. If the context would help I could work on getting it. However, I think it should be safe as it is, as we do have the context of whether we are at the start or end of a span, and the risky thing is just the ambiguity of the end of one thing which is equal to the start of the next, which we avoid here.