xref: /llvm-project/llvm/test/DebugInfo/X86/range_reloc.ll (revision ab093bfed7602b74913cc448ad70e27f65aefc28)
1bb279116SDavid Blaikie; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu %s -o - | FileCheck %s
271812e30SDavid Blaikie; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu %s -o - -dwarf-version 5 | FileCheck --check-prefix=DWARF5 %s
389c81a0bSDavid Blaikie
489c81a0bSDavid Blaikie; Group ranges in a range list that apply to the same section and use a base
589c81a0bSDavid Blaikie; address selection entry to reduce the number of relocations to one reloc per
6d6614051SDavid Blaikie; section per range list. DWARF5 debug_rnglist (with *x variants) are more
7d6614051SDavid Blaikie; efficient than this in terms of relocations, but it's still better than one
8d6614051SDavid Blaikie; reloc per entry in a range list.
989c81a0bSDavid Blaikie
1089c81a0bSDavid Blaikie; This is an object/executable size tradeoff - shrinking objects, but growing
1189c81a0bSDavid Blaikie; the linked executable. In one large binary tested, total object size (not just
1289c81a0bSDavid Blaikie; debug info) shrank by 16%, entirely relocation entries. Linked executable
1389c81a0bSDavid Blaikie; grew by 4%. This was with compressed debug info in the objects, uncompressed
1489c81a0bSDavid Blaikie; in the linked executable. Without compression in the objects, the win would be
1589c81a0bSDavid Blaikie; smaller (the growth of debug_ranges itself would be more significant).
1689c81a0bSDavid Blaikie
17bb279116SDavid Blaikie; This is a merged module containing two CUs, one that uses range base address
18bb279116SDavid Blaikie; specifiers and exercises different cases there, and another that does not
1914cfa0dcSDavid Blaikie
20bb279116SDavid Blaikie; ranges.cpp
21bb279116SDavid Blaikie; Single range entry
22bb279116SDavid Blaikie; __attribute__((section("a"))) void f1() {}
23bb279116SDavid Blaikie; Single address with two ranges due to the whole caused by f3
24bb279116SDavid Blaikie; __attribute__((section("b"))) void f2() {}
25bb279116SDavid Blaikie; __attribute__((section("b"))) __attribute__((nodebug)) void f3() {}
26bb279116SDavid Blaikie; __attribute__((section("b"))) void f4() {}
27bb279116SDavid Blaikie; Reset the base address & emit a couple more single range entries
28bb279116SDavid Blaikie; __attribute__((section("c"))) void f5() {}
29bb279116SDavid Blaikie; __attribute__((section("d"))) void f6() {}
30bb279116SDavid Blaikie; ranges_no_base.cpp:
31bb279116SDavid Blaikie; Include enough complexity to cause ranges to be emitted, so it can be checked
32bb279116SDavid Blaikie; that those ranges don't use base address specifiers
33bb279116SDavid Blaikie; __attribute__((section("e"))) void f7() {}
34bb279116SDavid Blaikie; __attribute__((section("f"))) void f8() {}
35bb279116SDavid Blaikie
36bb279116SDavid Blaikie; CHECK: {{^.Ldebug_ranges0}}
37bb279116SDavid Blaikie; CHECK-NEXT:   .quad   -1
38bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin0
39bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin0-.Lfunc_begin0
40bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_end0-.Lfunc_begin0
41bb279116SDavid Blaikie; CHECK-NEXT:   .quad   -1
42bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin1
43bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin1-.Lfunc_begin1
44bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_end1-.Lfunc_begin1
45bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin3-.Lfunc_begin1
46bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_end3-.Lfunc_begin1
47bb279116SDavid Blaikie; CHECK-NEXT:   .quad   -1
48bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin4
49bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin4-.Lfunc_begin4
50bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_end4-.Lfunc_begin4
51bb279116SDavid Blaikie; CHECK-NEXT:   .quad   -1
52bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin5
53bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin5-.Lfunc_begin5
54bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_end5-.Lfunc_begin5
55bb279116SDavid Blaikie; CHECK-NEXT:   .quad   0
56bb279116SDavid Blaikie; CHECK-NEXT:   .quad   0
57bb279116SDavid Blaikie; CHECK-NEXT: {{^.Ldebug_ranges1}}
58bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin6
59bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_end6
60bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_begin7
61bb279116SDavid Blaikie; CHECK-NEXT:   .quad   .Lfunc_end7
6289c81a0bSDavid Blaikie
63d6614051SDavid Blaikie; DWARF5: {{^.Ldebug_ranges0}}
64c4af8bf2SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_startx_length
65c4af8bf2SDavid Blaikie; DWARF5-NEXT: .byte 0                              #   start index
66d6614051SDavid Blaikie; DWARF5-NEXT: .uleb128 .Lfunc_end0-.Lfunc_begin0   #   length
67c4af8bf2SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_base_addressx
68c4af8bf2SDavid Blaikie; DWARF5-NEXT: .byte 1                              #   base address index
69d6614051SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_offset_pair
70d6614051SDavid Blaikie; DWARF5-NEXT: .uleb128 .Lfunc_begin1-.Lfunc_begin1 #   starting offset
71d6614051SDavid Blaikie; DWARF5-NEXT: .uleb128 .Lfunc_end1-.Lfunc_begin1   #   ending offset
72d6614051SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_offset_pair
73d6614051SDavid Blaikie; DWARF5-NEXT: .uleb128 .Lfunc_begin3-.Lfunc_begin1 #   starting offset
74d6614051SDavid Blaikie; DWARF5-NEXT: .uleb128 .Lfunc_end3-.Lfunc_begin1   #   ending offset
75c4af8bf2SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_startx_length
76c4af8bf2SDavid Blaikie; DWARF5-NEXT: .byte 3                              #   start index
77d6614051SDavid Blaikie; DWARF5-NEXT: .uleb128 .Lfunc_end4-.Lfunc_begin4   #   length
78c4af8bf2SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_startx_length
79c4af8bf2SDavid Blaikie; DWARF5-NEXT: .byte 4                              #   start index
80d6614051SDavid Blaikie; DWARF5-NEXT: .uleb128 .Lfunc_end5-.Lfunc_begin5   #   length
81d6614051SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_end_of_list
82bb279116SDavid Blaikie; DWARF5-NEXT: {{^.Ldebug_ranges1}}
83bb279116SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_startx_length
84bb279116SDavid Blaikie; DWARF5-NEXT: .byte 5                              #   start index
85bb279116SDavid Blaikie; DWARF5-NEXT: .uleb128 .Lfunc_end6-.Lfunc_begin6   #   length
86bb279116SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_startx_length
87bb279116SDavid Blaikie; DWARF5-NEXT: .byte 6                              #   start index
88bb279116SDavid Blaikie; DWARF5-NEXT: .uleb128 .Lfunc_end7-.Lfunc_begin7   #   length
89bb279116SDavid Blaikie; DWARF5-NEXT:                                      # DW_RLE_end_of_list
90d6614051SDavid Blaikie
9189c81a0bSDavid Blaikie; Function Attrs: noinline nounwind optnone uwtable
92bb279116SDavid Blaikiedefine dso_local void @_Z2f1v() section "a" !dbg !9 {
9389c81a0bSDavid Blaikieentry:
9489c81a0bSDavid Blaikie  ret void, !dbg !12
9589c81a0bSDavid Blaikie}
9689c81a0bSDavid Blaikie
9789c81a0bSDavid Blaikie; Function Attrs: noinline nounwind optnone uwtable
98bb279116SDavid Blaikiedefine dso_local void @_Z2f2v() section "b" !dbg !13 {
9989c81a0bSDavid Blaikieentry:
10089c81a0bSDavid Blaikie  ret void, !dbg !14
10189c81a0bSDavid Blaikie}
10289c81a0bSDavid Blaikie
1034dd66375SDavid Blaikie; Function Attrs: noinline nounwind optnone uwtable
104bb279116SDavid Blaikiedefine dso_local void @_Z2f3v() section "b" {
105bb279116SDavid Blaikieentry:
106bb279116SDavid Blaikie  ret void
107bb279116SDavid Blaikie}
108bb279116SDavid Blaikie
109bb279116SDavid Blaikie; Function Attrs: noinline nounwind optnone uwtable
110bb279116SDavid Blaikiedefine dso_local void @_Z2f4v() section "b" !dbg !15 {
1114dd66375SDavid Blaikieentry:
1124dd66375SDavid Blaikie  ret void, !dbg !16
1134dd66375SDavid Blaikie}
1144dd66375SDavid Blaikie
1154dd66375SDavid Blaikie; Function Attrs: noinline nounwind optnone uwtable
116bb279116SDavid Blaikiedefine dso_local void @_Z2f5v() section "c" !dbg !17 {
1174dd66375SDavid Blaikieentry:
1184dd66375SDavid Blaikie  ret void, !dbg !18
1194dd66375SDavid Blaikie}
1204dd66375SDavid Blaikie
121bb279116SDavid Blaikie; Function Attrs: noinline nounwind optnone uwtable
122bb279116SDavid Blaikiedefine dso_local void @_Z2f6v() section "d" !dbg !19 {
123bb279116SDavid Blaikieentry:
124bb279116SDavid Blaikie  ret void, !dbg !20
125bb279116SDavid Blaikie}
12689c81a0bSDavid Blaikie
127bb279116SDavid Blaikie; Function Attrs: noinline nounwind optnone uwtable
128bb279116SDavid Blaikiedefine dso_local void @_Z2f7v() section "e" !dbg !21 {
129bb279116SDavid Blaikieentry:
130bb279116SDavid Blaikie  ret void, !dbg !22
131bb279116SDavid Blaikie}
13289c81a0bSDavid Blaikie
133bb279116SDavid Blaikie; Function Attrs: noinline nounwind optnone uwtable
134bb279116SDavid Blaikiedefine dso_local void @_Z2f8v() section "f" !dbg !23 {
135bb279116SDavid Blaikieentry:
136bb279116SDavid Blaikie  ret void, !dbg !24
137bb279116SDavid Blaikie}
138bb279116SDavid Blaikie
139bb279116SDavid Blaikie!llvm.dbg.cu = !{!0, !3}
140bb279116SDavid Blaikie!llvm.ident = !{!5, !5}
141bb279116SDavid Blaikie!llvm.module.flags = !{!6, !7, !8}
142bb279116SDavid Blaikie
143*ab093bfeSDavid Blaikie!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 (trunk 346343) (llvm/trunk 346350)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None, rangesBaseAddress: true)
144bb279116SDavid Blaikie!1 = !DIFile(filename: "ranges.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
14589c81a0bSDavid Blaikie!2 = !{}
146bb279116SDavid Blaikie!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !4, producer: "clang version 8.0.0 (trunk 346343) (llvm/trunk 346350)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
147bb279116SDavid Blaikie!4 = !DIFile(filename: "ranges_no_base.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
148bb279116SDavid Blaikie!5 = !{!"clang version 8.0.0 (trunk 346343) (llvm/trunk 346350)"}
149bb279116SDavid Blaikie!6 = !{i32 2, !"Dwarf Version", i32 4}
150bb279116SDavid Blaikie!7 = !{i32 2, !"Debug Info Version", i32 3}
151bb279116SDavid Blaikie!8 = !{i32 1, !"wchar_size", i32 4}
152bb279116SDavid Blaikie!9 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v", scope: !1, file: !1, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
153bb279116SDavid Blaikie!10 = !DISubroutineType(types: !11)
154bb279116SDavid Blaikie!11 = !{null}
155bb279116SDavid Blaikie!12 = !DILocation(line: 1, column: 42, scope: !9)
156bb279116SDavid Blaikie!13 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
157bb279116SDavid Blaikie!14 = !DILocation(line: 2, column: 42, scope: !13)
158bb279116SDavid Blaikie!15 = distinct !DISubprogram(name: "f4", linkageName: "_Z2f4v", scope: !1, file: !1, line: 4, type: !10, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
159bb279116SDavid Blaikie!16 = !DILocation(line: 4, column: 42, scope: !15)
160bb279116SDavid Blaikie!17 = distinct !DISubprogram(name: "f5", linkageName: "_Z2f5v", scope: !1, file: !1, line: 5, type: !10, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
161bb279116SDavid Blaikie!18 = !DILocation(line: 5, column: 42, scope: !17)
162bb279116SDavid Blaikie!19 = distinct !DISubprogram(name: "f6", linkageName: "_Z2f6v", scope: !1, file: !1, line: 6, type: !10, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
163bb279116SDavid Blaikie!20 = !DILocation(line: 6, column: 42, scope: !19)
164bb279116SDavid Blaikie!21 = distinct !DISubprogram(name: "f7", linkageName: "_Z2f7v", scope: !4, file: !4, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !3, retainedNodes: !2)
165bb279116SDavid Blaikie!22 = !DILocation(line: 1, column: 42, scope: !21)
166bb279116SDavid Blaikie!23 = distinct !DISubprogram(name: "f8", linkageName: "_Z2f8v", scope: !4, file: !4, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !3, retainedNodes: !2)
167bb279116SDavid Blaikie!24 = !DILocation(line: 2, column: 42, scope: !23)
168