forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 341
Fix cas-friendly line table emission in llvm #6718
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
rastogishubham
merged 1 commit into
swiftlang:experimental/cas/main
from
rastogishubham:LineTableFix
May 10, 2023
Merged
Changes from all commits
Commits
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,21 +144,26 @@ makeStartPlusIntExpr(MCContext &Ctx, const MCSymbol &Start, int IntVal) { | |
return Res; | ||
} | ||
|
||
void MCLineSection::addEndEntry(MCSymbol *EndLabel) { | ||
void MCLineSection::addEndEntry(MCSymbol *EndLabel, bool CasFriendlyDebugInfo) { | ||
auto *Sec = &EndLabel->getSection(); | ||
// The line table may be empty, which we should skip adding an end entry. | ||
// There are two cases: | ||
// There are three cases: | ||
// (1) MCAsmStreamer - emitDwarfLocDirective emits a location directive in | ||
// place instead of adding a line entry if the target has | ||
// usesDwarfFileAndLocDirectives. | ||
// (2) MCObjectStreamer - if a function has incomplete debug info where | ||
// instructions don't have DILocations, the line entries are missing. | ||
// (3) If the debug info is cas friendly, there is an end_sequence after every | ||
// function and another one doesn't have to be emitted at the end of the line | ||
// table. | ||
auto I = MCLineDivisions.find(Sec); | ||
if (I != MCLineDivisions.end()) { | ||
auto &Entries = I->second; | ||
auto EndEntry = Entries.back(); | ||
EndEntry.setEndLabel(EndLabel); | ||
Entries.push_back(EndEntry); | ||
if (!CasFriendlyDebugInfo) { | ||
EndEntry.setEndLabel(EndLabel); | ||
Entries.push_back(EndEntry); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -173,7 +178,9 @@ void MCDwarfLineTable::emitOne( | |
unsigned FileNum, LastLine, Column, Flags, Isa, Discriminator; | ||
MCSymbol *LastLabel; | ||
auto init = [&]() { | ||
FileNum = 1; | ||
// Force emission of DW_LNS_set_file for every function's contribution to | ||
// the line table to maximize deduplication. | ||
FileNum = MCOS->getGenerateCasFriendlyDebugInfo() ? 0 : 1; | ||
LastLine = 1; | ||
Column = 0; | ||
Flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0; | ||
|
@@ -188,29 +195,22 @@ void MCDwarfLineTable::emitOne( | |
for (const MCDwarfLineEntry &LineEntry : LineEntries) { | ||
MCSymbol *Label = LineEntry.getLabel(); | ||
const MCAsmInfo *asmInfo = MCOS->getContext().getAsmInfo(); | ||
if (LineEntry.IsEndEntry) { | ||
if (LineEntry.IsEndEntry || LineEntry.IsEndOfFunction) { | ||
MCOS->emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, Label, | ||
asmInfo->getCodePointerSize()); | ||
init(); | ||
EndEntryEmitted = true; | ||
continue; | ||
} | ||
if (LineEntry.IsEndOfFunction) { | ||
MCOS->emitInt8(char(dwarf::DW_LNS_extended_op)); | ||
MCOS->emitInt8(char(1)); | ||
MCOS->emitInt8(char(dwarf::DW_LNE_end_sequence)); | ||
init(); | ||
continue; | ||
} | ||
|
||
int64_t LineDelta = static_cast<int64_t>(LineEntry.getLine()) - LastLine; | ||
|
||
if (FileNum != LineEntry.getFileNum() || LineEntry.IsEndOfFunction) { | ||
if (FileNum != LineEntry.getFileNum()) { | ||
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. This looks like there could be some NFC refactoring done upstream first? Such as moving the LineEntry.IsEndOfFunction higher up? Might make maintaining the patch easier. |
||
FileNum = LineEntry.getFileNum(); | ||
MCOS->emitInt8(dwarf::DW_LNS_set_file); | ||
MCOS->emitULEB128IntValue(FileNum); | ||
} | ||
if (Column != LineEntry.getColumn() || LineEntry.IsEndOfFunction) { | ||
if (Column != LineEntry.getColumn()) { | ||
Column = LineEntry.getColumn(); | ||
MCOS->emitInt8(dwarf::DW_LNS_set_column); | ||
MCOS->emitULEB128IntValue(Column); | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.
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'm confused about the previous code: was this
|| LineEntry.IsEndOfFunction
ever relevant? Because right above wecontinue
for this state 🤔But I see now that most removals here are actually restoring the code to its upstream state
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.
Yes, that part was not needed, and I have removed it. I am sorry for the confusion on that.