-
Notifications
You must be signed in to change notification settings - Fork 15.2k
DWARF CFI Checker prototype #148296
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
Draft
amsen20
wants to merge
22
commits into
llvm:main
Choose a base branch
from
amsen20:cfi-validation-prototype
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
DWARF CFI Checker prototype #148296
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
211ec57
Forward CFI directives alongside their associated instruction to a si…
29325f7
Create a new CFI analysis for each dwarf separately
946b5c6
Separate the logic and display
2376ee8
Compile llvm mc depending on bolt
2cfa1be
Extract semantic info on MCInst from bolt
f01a9fd
Typo in evaluateStackOffsetExpr doc
610e393
Add a DS to keep track of each register CFI state
ccf43ad
Check if the CFA change is correct or not
aa95e82
Add the CFI validation as a option to llvm-mc tool
fc88bfa
Provide the directives as an arrayref instead of index range
832d5a6
Remove TODOs
5271303
Wrap all the MCPB info needed into a ExtendedMCInstrAnalysis class
84f8d18
Use extended MCAnalysis instead of MCplus (directly)
37186b8
Make the CFA checker to first generate, if not matched check the Read…
203a238
Check register states as well
5389a61
Process prologue as well
fe03122
Ignore flag registers as well
9ded4f3
Enable dump
6b7dd6a
Enable getting flag register through extended MCInstrAnalysis
9724907
Move the isolated MC semantic methods to ExtendedMCAnalysis
6a58a99
Remove unused includes
63b8cfb
Test cfi validator on following cases:
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
33 changes: 33 additions & 0 deletions
33
llvm/test/tools/llvm-mc/cfi-validation/single-func-cfa-mistake.s
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,33 @@ | ||
| # RUN: not llvm-mc %s --validate-cfi --filetype=null 2>&1 \ | ||
| # RUN: | FileCheck %s | ||
| .text | ||
| .globl f | ||
| .type f,@function | ||
| f: | ||
| .cfi_startproc | ||
|
|
||
| .cfi_undefined %rax | ||
|
|
||
| pushq %rbp | ||
| # CHECK: error: Expected CFA [reg: 61, offset: 16] but got [reg: 61, offset: 17] | ||
| .cfi_def_cfa_offset 17 | ||
| .cfi_offset %rbp, -16 | ||
|
|
||
| movq %rsp, %rbp | ||
| .cfi_def_cfa_register %rbp | ||
|
|
||
| movl %edi, -4(%rbp) | ||
|
|
||
| movl -4(%rbp), %eax | ||
|
|
||
| addl $10, %eax | ||
|
|
||
| popq %rbp | ||
| .cfi_def_cfa %rsp, 8 | ||
|
|
||
| retq | ||
|
|
||
| .Lfunc_end0: | ||
| .size f, .Lfunc_end0-f | ||
|
|
||
| .cfi_endproc |
32 changes: 32 additions & 0 deletions
32
llvm/test/tools/llvm-mc/cfi-validation/single-func-missed-cfi-directive.s
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,32 @@ | ||
| # RUN: not llvm-mc %s --validate-cfi --filetype=null 2>&1 \ | ||
| # RUN: | FileCheck %s | ||
| .text | ||
| .globl f | ||
| .type f,@function | ||
| f: | ||
| .cfi_startproc | ||
|
|
||
| .cfi_undefined %rax | ||
|
|
||
| pushq %rbp | ||
| .cfi_def_cfa_offset 16 | ||
|
|
||
| movq %rsp, %rbp | ||
| # CHECK: error: Reg#52 caller's value is in reg#52 which is changed by this instruction, but not changed in CFI directives | ||
| .cfi_def_cfa_register %rbp | ||
|
|
||
| movl %edi, -4(%rbp) | ||
|
|
||
| movl -4(%rbp), %eax | ||
|
|
||
| addl $10, %eax | ||
|
|
||
| popq %rbp | ||
| .cfi_def_cfa %rsp, 8 | ||
|
|
||
| retq | ||
|
|
||
| .Lfunc_end0: | ||
| .size f, .Lfunc_end0-f | ||
|
|
||
| .cfi_endproc |
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,31 @@ | ||
| # RUN: llvm-mc %s --validate-cfi --filetype=null | ||
| .text | ||
| .globl f | ||
| .type f,@function | ||
| f: | ||
| .cfi_startproc | ||
|
|
||
| .cfi_undefined %rax | ||
|
|
||
| pushq %rbp | ||
| .cfi_def_cfa_offset 16 | ||
| .cfi_offset %rbp, -16 | ||
|
|
||
| movq %rsp, %rbp | ||
| .cfi_def_cfa_register %rbp | ||
|
|
||
| movl %edi, -4(%rbp) | ||
|
|
||
| movl -4(%rbp), %eax | ||
|
|
||
| addl $10, %eax | ||
|
|
||
| popq %rbp | ||
| .cfi_def_cfa %rsp, 8 | ||
|
|
||
| retq | ||
|
|
||
| .Lfunc_end0: | ||
| .size f, .Lfunc_end0-f | ||
|
|
||
| .cfi_endproc |
47 changes: 47 additions & 0 deletions
47
llvm/test/tools/llvm-mc/cfi-validation/spill-two-reg-reversed.s
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,47 @@ | ||
| # RUN: not llvm-mc %s --validate-cfi --filetype=null 2>&1 \ | ||
| # RUN: | FileCheck %s | ||
| .text | ||
| .type _start,@function | ||
| .globl _start | ||
| .hidden _start | ||
| _start: | ||
| .cfi_startproc | ||
|
|
||
| .cfi_same_value %rdi | ||
| .cfi_same_value %rsi | ||
|
|
||
| pushq %rbp | ||
| .cfi_adjust_cfa_offset 8 | ||
| .cfi_offset %rbp, -16 | ||
|
|
||
| movq %rsp, %rbp | ||
|
|
||
| pushq %rdi | ||
| .cfi_adjust_cfa_offset 8 | ||
| .cfi_rel_offset %rdi, 0 | ||
|
|
||
| pushq %rsi | ||
| .cfi_adjust_cfa_offset 8 | ||
| .cfi_rel_offset %rsi, 0 | ||
|
|
||
| popq %rsi | ||
| # CHECK: warning: The reg#55 CFI state is changed | ||
| .cfi_adjust_cfa_offset -8 | ||
| .cfi_same_value %rdi | ||
|
|
||
| popq %rdi | ||
| # CHECK: warning: The reg#60 CFI state is changed | ||
| # CHECK: Reg#55 caller's value is in reg#55 which is changed by this instruction, but not changed in CFI directives | ||
| .cfi_adjust_cfa_offset -8 | ||
| .cfi_same_value %rsi | ||
|
|
||
| popq %rbp | ||
| .cfi_adjust_cfa_offset -8 | ||
| .cfi_same_value %rbp | ||
|
|
||
| retq | ||
|
|
||
| .cfi_endproc | ||
| .Ltmp0: | ||
| .size _start, .Ltmp0-_start | ||
| .text |
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,43 @@ | ||
| # RUN: llvm-mc %s --validate-cfi --filetype=null | ||
| .text | ||
| .type _start,@function | ||
| .globl _start | ||
| .hidden _start | ||
| _start: | ||
| .cfi_startproc | ||
|
|
||
| .cfi_same_value %rdi | ||
| .cfi_same_value %rsi | ||
|
|
||
| pushq %rbp | ||
| .cfi_adjust_cfa_offset 8 | ||
| .cfi_offset %rbp, -16 | ||
|
|
||
| movq %rsp, %rbp | ||
|
|
||
| pushq %rdi | ||
| .cfi_adjust_cfa_offset 8 | ||
| .cfi_rel_offset %rdi, 0 | ||
|
|
||
| pushq %rsi | ||
| .cfi_adjust_cfa_offset 8 | ||
| .cfi_rel_offset %rsi, 0 | ||
|
|
||
| popq %rsi | ||
| .cfi_adjust_cfa_offset -8 | ||
| .cfi_same_value %rsi | ||
|
|
||
| popq %rdi | ||
| .cfi_adjust_cfa_offset -8 | ||
| .cfi_same_value %rdi | ||
|
|
||
| popq %rbp | ||
| .cfi_adjust_cfa_offset -8 | ||
| .cfi_same_value %rbp | ||
|
|
||
| retq | ||
|
|
||
| .cfi_endproc | ||
| .Ltmp0: | ||
| .size _start, .Ltmp0-_start | ||
| .text |
31 changes: 31 additions & 0 deletions
31
llvm/test/tools/llvm-mc/cfi-validation/update-with-no-cfi.s
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,31 @@ | ||
| # RUN: not llvm-mc %s --validate-cfi --filetype=null 2>&1 \ | ||
| # RUN: | FileCheck %s | ||
| .text | ||
| .globl f | ||
| .type f,@function | ||
| f: | ||
| .cfi_startproc | ||
|
|
||
| .cfi_same_value %rax | ||
| .cfi_same_value %rbx | ||
| .cfi_same_value %rcx | ||
| .cfi_same_value %rdx | ||
|
|
||
| movq $10, %rax | ||
| # CHECK: error: Reg#51 caller's value is in reg#51 which is changed by this instruction, but not changed in CFI directives | ||
|
|
||
| movq $10, %rbx | ||
| # CHECK: error: Reg#53 caller's value is in reg#53 which is changed by this instruction, but not changed in CFI directives | ||
|
|
||
| movq $10, %rcx | ||
| # CHECK: error: Reg#54 caller's value is in reg#54 which is changed by this instruction, but not changed in CFI directives | ||
|
|
||
| movq $10, %rdx | ||
| # CHECK: error: Reg#56 caller's value is in reg#56 which is changed by this instruction, but not changed in CFI directives | ||
|
|
||
| retq | ||
|
|
||
| .Lfunc_end0: | ||
| .size f, .Lfunc_end0-f | ||
|
|
||
| .cfi_endproc |
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.
Maybe this is renamed by mistake?
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.
It was a temporary fix for linking the
llvm-mctool with BOLT, when the linker tried to link them, having the same CL option with the same value caused errors.