-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[DWARFVerifier] Allow overlapping ranges for ICF-merged functions #117952
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
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a5f73d2
[DWARFVerifier] Allow overlapping ranges for ICF-merged functions
a466e50
Fix Broken Test
f6daae5
Address Feedback Nr.1
0e873b7
Remove Unrelated Formatting
22f8f8a
Remove unecessary comparisson.
8fc6a58
Handle lexical blocks also
d55fd0d
temp last fix
156614b
Simplify code
a7f9e46
Fix associated test
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
131 changes: 131 additions & 0 deletions
131
llvm/test/tools/llvm-dwarfdump/X86/verify_no_overlap_error_icf.yaml
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 |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| //--- comments.txt | ||
|
|
||
| # This test verifies several scenarios with DW_TAG_subprogram address ranges: | ||
| # 1. Two subprograms can have identical ranges (shown with foo2 and foo3 having same low_pc/high_pc) | ||
| # This is valid and can happen when ICF (Identical Code Folding) merges functions. | ||
| # 2. Two subprograms can have overlapping ranges when using DW_AT_ranges | ||
| # (shown with func1_with_ranges and func2_with_ranges sharing range 0x5000-0x6000) | ||
| # This is also valid and can occur with -fbasic-block-sections=all | ||
| # 3. The test also verifies that non-identical overlapping ranges are correctly flagged as errors: | ||
| # - When modifying just the first range's high offset from 0x6000 to 0x5999, it creates an invalid subrange overlap | ||
| # - When modifying just the first instance of DW_AT_high_pc 0x77 to 0x66, it creates an invalid function overlap | ||
| # The test ensures llvm-dwarfdump --verify correctly validates these cases by: | ||
| # a) Accepting valid identical overlapping ranges | ||
| # b) Rejecting invalid non-identical overlapping ranges | ||
|
|
||
| # Need to use split-file in order for `sed` calls below to work correctly | ||
| # RUN: split-file %s %t | ||
| # RUN: yaml2obj %t/test.yaml | llvm-dwarfdump --error-display=details --verify - | FileCheck %s | ||
| # CHECK: No errors. | ||
|
|
||
| # RUN: sed '0,/HighOffset: 0x6000/{s//HighOffset: 0x5999/}' %t/test.yaml | yaml2obj | not llvm-dwarfdump --error-display=details --verify - | FileCheck %s --check-prefix=CHECK-RANGES | ||
| # CHECK-RANGES: error: DIEs have overlapping address ranges | ||
|
|
||
| # RUN: sed '0,/Value: 0x77/{s/Value: 0x77/Value: 0x66/}' %t/test.yaml | yaml2obj | not llvm-dwarfdump --error-display=details --verify - | FileCheck %s --check-prefix=CHECK-HIGH-PC | ||
| # CHECK-HIGH-PC: error: DIEs have overlapping address ranges | ||
|
|
||
| //--- test.yaml | ||
| --- !ELF | ||
| FileHeader: | ||
| Class: ELFCLASS64 | ||
| Data: ELFDATA2LSB | ||
| Type: ET_REL | ||
| Machine: EM_X86_64 | ||
| DWARF: | ||
| debug_abbrev: | ||
| - Table: | ||
| - Tag: DW_TAG_compile_unit | ||
| Children: DW_CHILDREN_yes | ||
| Attributes: | ||
| - Attribute: DW_AT_producer | ||
| Form: DW_FORM_string | ||
| - Attribute: DW_AT_language | ||
| Form: DW_FORM_data2 | ||
| - Attribute: DW_AT_name | ||
| Form: DW_FORM_string | ||
| - Attribute: DW_AT_low_pc | ||
| Form: DW_FORM_addr | ||
| - Attribute: DW_AT_high_pc | ||
| Form: DW_FORM_data8 | ||
| - Tag: DW_TAG_subprogram | ||
| Children: DW_CHILDREN_no | ||
| Attributes: | ||
| - Attribute: DW_AT_name | ||
| Form: DW_FORM_string | ||
| - Attribute: DW_AT_low_pc | ||
| Form: DW_FORM_addr | ||
| - Attribute: DW_AT_high_pc | ||
| Form: DW_FORM_data8 | ||
| - Tag: DW_TAG_subprogram | ||
| Children: DW_CHILDREN_no | ||
| Attributes: | ||
| - Attribute: DW_AT_name | ||
| Form: DW_FORM_string | ||
| - Attribute: DW_AT_ranges | ||
| Form: DW_FORM_sec_offset | ||
| - Tag: DW_TAG_base_type | ||
| Children: DW_CHILDREN_no | ||
| Attributes: | ||
| - Attribute: DW_AT_name | ||
| Form: DW_FORM_string | ||
| debug_ranges: | ||
| - Offset: 0x0 | ||
| AddrSize: 0x8 | ||
| Entries: | ||
| - LowOffset: 0x1000 | ||
| HighOffset: 0x2000 | ||
| - LowOffset: 0x3000 | ||
| HighOffset: 0x4000 | ||
| - LowOffset: 0x5000 # Overlaps with 2nd range below | ||
| HighOffset: 0x6000 | ||
| - LowOffset: 0x0 | ||
| HighOffset: 0x0 | ||
| - Offset: 0x50 | ||
| AddrSize: 0x8 | ||
| Entries: | ||
| - LowOffset: 0x2500 | ||
| HighOffset: 0x2800 | ||
| - LowOffset: 0x5000 # Overlaps with 3rd range above | ||
| HighOffset: 0x6000 | ||
| - LowOffset: 0x7000 | ||
| HighOffset: 0x8000 | ||
| - LowOffset: 0x0 | ||
| HighOffset: 0x0 | ||
| debug_info: | ||
| - Version: 4 | ||
| Entries: | ||
| - AbbrCode: 1 | ||
| Values: | ||
| - CStr: by_hand | ||
| - Value: 0x04 | ||
| - CStr: CU1 | ||
| - Value: 0x1000 | ||
| - Value: 0x100 | ||
| - AbbrCode: 4 | ||
| Values: | ||
| - CStr: int | ||
| - AbbrCode: 2 | ||
| Values: | ||
| - CStr: foo1 | ||
| - Value: 0x1000 | ||
| - Value: 0x10 | ||
| - AbbrCode: 2 | ||
| Values: | ||
| - CStr: foo2 | ||
| - Value: 0x0 # Overlaps with 'foo3' below | ||
| - Value: 0x77 | ||
| - AbbrCode: 2 | ||
| Values: | ||
| - CStr: foo3 | ||
| - Value: 0x0 # Overlaps with 'foo2' above | ||
| - Value: 0x77 | ||
| - AbbrCode: 3 | ||
| Values: | ||
| - CStr: func1_with_ranges | ||
| - Value: 0x0 | ||
| - AbbrCode: 3 | ||
| Values: | ||
| - CStr: func2_with_ranges | ||
| - Value: 0x50 | ||
| - AbbrCode: 0 | ||
| ... |
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 |
|---|---|---|
|
|
@@ -150,7 +150,7 @@ DWARF: | |
| Values: | ||
| - CStr: foo3 | ||
| - Value: 0x0 | ||
| - Value: 0x100 | ||
| - Value: 0x80 | ||
| - Value: 0x00000040 | ||
| - AbbrCode: 0 | ||
| ... | ||
Oops, something went wrong.
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.
Why restrict this to subprograms having duplicates? Presumably anything could have duplicates - if we can have subprograms with duplicates (is this duplicates within a subprogram, or between subprograms, or both?) then we can probably have lexical scopes with duplicates too? (& certainly CUs with duplicates - both within a CU and across multiple CUs)
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 was wanting to restrict this change to scenarios that I am familiar with / I'm trying to address. I am not sure about the implications for allowing duplicates for anything else. But if is clear that the right choice is to allow full overlaps for all tags - then I can make that change.
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 guess a few questions:
Is this only allowing duplicates on DW_AT_ranges of DW_AT_subprograms? Or only allowing overlap /of/ subprograms /on/ CUs? I guess the latter - so that, sufficiently generalizes, handles the case of subprograms with ranges (basic block sections) that overlap with /other/ subprograms
But presumably that /doesn't/ cover the case where a subprogram's sections might overlap with itself, due to BB sections? (or perhaps it does, if there's no "self" special case - if you're allowing a subprogram to overlap with other subprograms, including itself)
But shouldn't this apply to CUs too? a CU ranges could overlap with another CU due to a subprogram in one CU overlapping with a subprogram in a different CU? (is that tested? does that somehow come out of the subprogram-only-allowed case here?)
But, equally, this should apply to lexical scopes too - should be able to make a scope in a function compiled with basic-block sections have self-duplicate ranges, or collide/duplicate with athore lexical scope's ranges in the same subprogram (by putting the same code in different places in a function, and wrapping it in lexical scopes)
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.
So this is only relating to
DW_AT_subprogram's - allowing them to overlap like this:DW_AT_ranges's to overlap in between differentDW_AT_subprogram'sDW_AT_low_pc/DW_AT_high_pcin betweenDW_AT_subprogram'sDW_AT_ranges's in aDW_AT_subprogramoverlap - this will still raise an error. Should we cover this case also ?llvm-dwarfdump --error-display=details --verifydoes currently not raise any errors for overlapping CU's.llvm-dwarfdump --error-display=details --verifydoes currently not raise any errors for overlapping lexical blocks.I tested using this script which generates DWARF dumped here.
The output with this patch shows no errors.
The output without this patch shows the errors for overlapping
DW_AT_subprogram'sThere 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.
Ah, yeah, looks like we don't even try to apply any verification constraints to ranges between CUs shrug they should probably have the same constraints, though - that exact overlap of any range is acceptable, but partial overlap is not. But ah well, I'm not pushing for improving that.
Let's look at lexical scope overlap, then...
I think this example demonstrates almost all the overlapping cases (well, doesn't include distinct subprograms overlapping with each other, but otherwise I think it covers things):
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.
Thanks for the example - the latest version addresses this.