Skip to content

Commit c450e47

Browse files
author
djtodoro
committed
[llvm-dwarfdump] Fix unsigned overflow when calculating stats
This fixes https://bugs.llvm.org/show_bug.cgi?id=51652. The idea is to bump all the stat fields to 64-bit wide unsigned integers. I've confirmed this resolves the use case for chromium. Differential Revision: https://reviews.llvm.org/D109217
1 parent a4f42a3 commit c450e47

File tree

8 files changed

+382
-139
lines changed

8 files changed

+382
-139
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# RUN: yaml2obj %s | llvm-dwarfdump --statistics - | FileCheck %s
2+
3+
## Check that we are covering the situation when
4+
## sum of bytes in scope is a huge (uint64_t) number.
5+
##
6+
## The yaml represents this DWARF:
7+
##
8+
## DW_TAG_compile_unit
9+
## DW_AT_low_pc (0x0000000000000000)
10+
## DW_AT_high_pc (0x000000000000000b)
11+
##
12+
## DW_TAG_subprogram
13+
## DW_AT_low_pc (0x0000000000000000)
14+
## DW_AT_high_pc (0x00000000ffffffff)
15+
## DW_TAG_variable
16+
## DW_AT_location (0x00000023:
17+
## [0x0000000000000003, 0x0000000000000005): DW_OP_reg2 RCX)
18+
## DW_TAG_subprogram
19+
## DW_AT_low_pc (0x0000000000000000)
20+
## DW_AT_high_pc (0x00000000ffffffff)
21+
## DW_TAG_variable
22+
## DW_AT_location (0x00000023:
23+
## [0x0000000000000003, 0x0000000000000005): DW_OP_reg2 RCX)
24+
25+
# CHECK: "version": 9,
26+
# CHECK: "sum_all_variables(#bytes in parent scope)": 8589934590
27+
28+
--- !ELF
29+
FileHeader:
30+
Class: ELFCLASS64
31+
Data: ELFDATA2LSB
32+
Type: ET_EXEC
33+
Machine: EM_X86_64
34+
Sections:
35+
- Name: .debug_loc
36+
Type: SHT_PROGBITS
37+
AddressAlign: 0x01
38+
Content: '00000000000000000600000000000000010055000000000000000000000000000000000300000000000000050000000000000001005200000000000000000000000000000000'
39+
- Name: .debug_ranges
40+
Type: SHT_PROGBITS
41+
AddressAlign: 0x01
42+
Content: '000000000000000003000000000000000500000000000000080000000000000000000000000000000000000000000000'
43+
DWARF:
44+
debug_abbrev:
45+
- Table:
46+
- Code: 1
47+
Tag: DW_TAG_compile_unit
48+
Children: DW_CHILDREN_yes
49+
Attributes:
50+
- Attribute: DW_AT_low_pc
51+
Form: DW_FORM_addr
52+
- Attribute: DW_AT_high_pc
53+
Form: DW_FORM_data4
54+
- Code: 2
55+
Tag: DW_TAG_subprogram
56+
Children: DW_CHILDREN_yes
57+
Attributes:
58+
- Attribute: DW_AT_low_pc
59+
Form: DW_FORM_addr
60+
- Attribute: DW_AT_high_pc
61+
Form: DW_FORM_data4
62+
- Code: 3
63+
Tag: DW_TAG_variable
64+
Children: DW_CHILDREN_no
65+
Attributes:
66+
- Attribute: DW_AT_location
67+
Form: DW_FORM_sec_offset
68+
debug_info:
69+
- Version: 4
70+
AbbrOffset: 0x00
71+
Entries:
72+
- AbbrCode: 1 ## DW_TAG_compile_unit
73+
Values:
74+
- Value: 0x00 ## DW_AT_low_pc
75+
- Value: 0x0b ## DW_AT_high_pc
76+
- AbbrCode: 2 ## DW_TAG_subprogram
77+
Values:
78+
- Value: 0x00 ## DW_AT_low_pc
79+
- Value: 0xFFFFFFFF ## DW_AT_high_pc
80+
- AbbrCode: 3 ## DW_TAG_variable
81+
Values:
82+
- Value: 0x23 ## DW_AT_sec_offset
83+
- AbbrCode: 0 ## NULL
84+
- AbbrCode: 2 ## DW_TAG_subprogram
85+
Values:
86+
- Value: 0x00 ## DW_AT_low_pc
87+
- Value: 0xFFFFFFFF ## DW_AT_high_pc
88+
- AbbrCode: 3 ## DW_TAG_variable
89+
Values:
90+
- Value: 0x23 ## DW_AT_sec_offset
91+
- AbbrCode: 0 ## NULL
92+
- AbbrCode: 0 ## NULL
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# RUN: yaml2obj %s | llvm-dwarfdump --statistics - 2>&1 | FileCheck %s
2+
3+
## Check that we are covering the situation when a stat field overflows.
4+
##
5+
## The yaml represents this DWARF:
6+
##
7+
## DW_TAG_compile_unit
8+
## DW_AT_low_pc (0x0000000000000000)
9+
## DW_AT_high_pc (0x000000000000000b)
10+
##
11+
## DW_TAG_subprogram
12+
## DW_AT_low_pc (0x0000000000000000)
13+
## DW_AT_high_pc (0xffffffffffffffff)
14+
## DW_TAG_variable
15+
## DW_AT_location (0x00000023:
16+
## [0x0000000000000003, 0x0000000000000005): DW_OP_reg2 RCX)
17+
## DW_TAG_subprogram
18+
## DW_AT_low_pc (0x0000000000000000)
19+
## DW_AT_high_pc (0xffffffffffffffff)
20+
## DW_TAG_variable
21+
## DW_AT_location (0x00000023:
22+
## [0x0000000000000003, 0x0000000000000005): DW_OP_reg2 RCX)
23+
24+
# CHECK: "sum_all_variables(#bytes in parent scope)": "overflowed"
25+
26+
--- !ELF
27+
FileHeader:
28+
Class: ELFCLASS[[BITS=64]]
29+
Data: ELFDATA2LSB
30+
Type: ET_EXEC
31+
Machine: EM_X86_64
32+
Sections:
33+
- Name: .debug_loc
34+
Type: SHT_PROGBITS
35+
AddressAlign: 0x01
36+
Content: '00000000000000000600000000000000010055000000000000000000000000000000000300000000000000050000000000000001005200000000000000000000000000000000'
37+
- Name: .debug_ranges
38+
Type: SHT_PROGBITS
39+
AddressAlign: 0x01
40+
Content: '000000000000000003000000000000000500000000000000080000000000000000000000000000000000000000000000'
41+
DWARF:
42+
debug_abbrev:
43+
- Table:
44+
- Code: 1
45+
Tag: DW_TAG_compile_unit
46+
Children: DW_CHILDREN_yes
47+
Attributes:
48+
- Attribute: DW_AT_low_pc
49+
Form: DW_FORM_addr
50+
- Attribute: DW_AT_high_pc
51+
Form: DW_FORM_data8
52+
- Code: 2
53+
Tag: DW_TAG_subprogram
54+
Children: DW_CHILDREN_yes
55+
Attributes:
56+
- Attribute: DW_AT_low_pc
57+
Form: DW_FORM_addr
58+
- Attribute: DW_AT_high_pc
59+
Form: DW_FORM_data8
60+
- Code: 3
61+
Tag: DW_TAG_variable
62+
Children: DW_CHILDREN_no
63+
Attributes:
64+
- Attribute: DW_AT_location
65+
Form: DW_FORM_sec_offset
66+
debug_info:
67+
- Version: 4
68+
AbbrOffset: 0x00
69+
Entries:
70+
- AbbrCode: 1 ## DW_TAG_compile_unit
71+
Values:
72+
- Value: 0x00 ## DW_AT_low_pc
73+
- Value: 0x0b ## DW_AT_high_pc
74+
- AbbrCode: 2 ## DW_TAG_subprogram
75+
Values:
76+
- Value: 0x00 ## DW_AT_low_pc
77+
- Value: 0xFFFFFFFFFFFFFFFF ## DW_AT_high_pc
78+
- AbbrCode: 3 ## DW_TAG_variable
79+
Values:
80+
- Value: 0x23 ## DW_AT_sec_offset
81+
- AbbrCode: 0 ## NULL
82+
- AbbrCode: 2 ## DW_TAG_subprogram
83+
Values:
84+
- Value: 0x00 ## DW_AT_low_pc
85+
- Value: 0xFFFFFFFFFFFFFFFF ## DW_AT_high_pc
86+
- AbbrCode: 3 ## DW_TAG_variable
87+
Values:
88+
- Value: 0x23 ## DW_AT_sec_offset
89+
- AbbrCode: 0 ## NULL
90+
- AbbrCode: 0 ## NULL

llvm/test/tools/llvm-dwarfdump/X86/locstats-for-absctract-origin-vars.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
## DW_TAG_subprogram
121121
## DW_AT_abstract_origin (0x000000f0)
122122

123-
# CHECK: "version": 8,
123+
# CHECK: "version": 9,
124124
# CHECK: "#variables processed by location statistics": 17,
125125
# CHECK: "#variables with 0% of parent scope covered by DW_AT_location": 13,
126126
# CHECK: "#variables with 100% of parent scope covered by DW_AT_location": 4,

llvm/test/tools/llvm-dwarfdump/X86/statistics-dwo.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ RUN: llvm-dwarfdump --statistics statistics-fib.split-dwarf.o | FileCheck %s
6969
# }
7070
#
7171

72-
CHECK: "version": 8,
72+
CHECK: "version": 9,
7373
CHECK: "#functions": 3,
7474
CHECK: "#functions with location": 3,
7575
CHECK: "#inlined functions": 7,

llvm/test/tools/llvm-dwarfdump/X86/statistics-v3.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ RUN: llvm-dwarfdump --statistics %t-statistics-fib.o | FileCheck %s
6464
# }
6565
#
6666

67-
CHECK: "version": 8,
67+
CHECK: "version": 9,
6868
CHECK: "#functions": 3,
6969
CHECK: "#functions with location": 3,
7070
CHECK: "#inlined functions": 8,

llvm/test/tools/llvm-dwarfdump/X86/statistics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: llc -O0 %s -o - -filetype=obj \
22
; RUN: | llvm-dwarfdump -statistics - | FileCheck %s
3-
; CHECK: "version": 8,
3+
; CHECK: "version": 9,
44

55
; namespace test {
66
; extern int a;

llvm/test/tools/llvm-dwarfdump/X86/stats-scope-bytes-covered.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
## DW_AT_location (0x00000023:
3434
## [0x0000000000000003, 0x0000000000000005): DW_OP_reg2 RCX)
3535

36-
# CHECK: "version": 8,
36+
# CHECK: "version": 9,
3737
# CHECK: "sum_all_variables(#bytes in parent scope)": 12,
3838
# CHECK: "sum_all_variables(#bytes in any scope covered by DW_AT_location)": 8
3939
# CHECK: "sum_all_variables(#bytes in parent scope covered by DW_AT_location)": 4

0 commit comments

Comments
 (0)