-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebAssembly] Add support for debug (DWARF) sections
Specifically add support for custom sections that contain relocations, and for the two new relocation types needed by DWARF sections. See: https://reviews.llvm.org/D44184 Patch by Yury Delendik! Differential Revision: https://reviews.llvm.org/D44184 llvm-svn: 331566
- Loading branch information
Showing
12 changed files
with
391 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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,68 @@ | ||
| ; ModuleID = 'hi.c' | ||
| source_filename = "hi.c" | ||
| target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" | ||
| target triple = "wasm32-unknown-unknown-wasm" | ||
|
|
||
| ; // hi.c: | ||
| ; extern void foo(int); | ||
| ; | ||
| ; int test(int t) { | ||
| ; return t * t; | ||
| ; } | ||
| ; | ||
| ; int _start() { | ||
| ; foo(test(10)); | ||
| ; return 0; | ||
| ; } | ||
|
|
||
| ; Function Attrs: nounwind readnone | ||
| define hidden i32 @test(i32 %t) local_unnamed_addr #0 !dbg !7 { | ||
| entry: | ||
| call void @llvm.dbg.value(metadata i32 %t, metadata !12, metadata !DIExpression()), !dbg !13 | ||
| %mul = mul nsw i32 %t, %t, !dbg !14 | ||
| ret i32 %mul, !dbg !15 | ||
| } | ||
|
|
||
| ; Function Attrs: nounwind | ||
| define hidden i32 @_start() local_unnamed_addr #1 !dbg !16 { | ||
| entry: | ||
| tail call void @foo(i32 100) #4, !dbg !19 | ||
| ret i32 0, !dbg !20 | ||
| } | ||
|
|
||
| declare void @foo(i32) local_unnamed_addr #2 | ||
|
|
||
| ; Function Attrs: nounwind readnone speculatable | ||
| declare void @llvm.dbg.value(metadata, metadata, metadata) #3 | ||
|
|
||
| attributes #0 = { nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" } | ||
| attributes #1 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" } | ||
| attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" } | ||
| attributes #3 = { nounwind readnone speculatable } | ||
| attributes #4 = { nounwind } | ||
|
|
||
| !llvm.dbg.cu = !{!0} | ||
| !llvm.module.flags = !{!3, !4, !5} | ||
| !llvm.ident = !{!6} | ||
|
|
||
| !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (trunk 331321)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) | ||
| !1 = !DIFile(filename: "hi.c", directory: "/Users/yury/llvmwasm") | ||
| !2 = !{} | ||
| !3 = !{i32 2, !"Dwarf Version", i32 4} | ||
| !4 = !{i32 2, !"Debug Info Version", i32 3} | ||
| !5 = !{i32 1, !"wchar_size", i32 4} | ||
| !6 = !{!"clang version 7.0.0 (trunk 331321)"} | ||
| !7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !11) | ||
| !8 = !DISubroutineType(types: !9) | ||
| !9 = !{!10, !10} | ||
| !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) | ||
| !11 = !{!12} | ||
| !12 = !DILocalVariable(name: "t", arg: 1, scope: !7, file: !1, line: 3, type: !10) | ||
| !13 = !DILocation(line: 3, column: 14, scope: !7) | ||
| !14 = !DILocation(line: 4, column: 12, scope: !7) | ||
| !15 = !DILocation(line: 4, column: 3, scope: !7) | ||
| !16 = distinct !DISubprogram(name: "_start", scope: !1, file: !1, line: 7, type: !17, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: true, unit: !0, variables: !2) | ||
| !17 = !DISubroutineType(types: !18) | ||
| !18 = !{!10} | ||
| !19 = !DILocation(line: 8, column: 3, scope: !16) | ||
| !20 = !DILocation(line: 9, column: 3, scope: !16) |
This file contains 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,64 @@ | ||
| ; ModuleID = 'hi_foo.c' | ||
| source_filename = "hi_foo.c" | ||
| target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" | ||
| target triple = "wasm32-unknown-unknown-wasm" | ||
|
|
||
| ; // hi_foo.c: | ||
| ; int y[2] = {23, 41}; | ||
| ; | ||
| ; void foo(int p) { | ||
| ; y[p & 1]++; | ||
| ; } | ||
|
|
||
| @y = hidden local_unnamed_addr global [2 x i32] [i32 23, i32 41], align 4, !dbg !0 | ||
|
|
||
| ; Function Attrs: nounwind | ||
| define hidden void @foo(i32 %p) local_unnamed_addr #0 !dbg !14 { | ||
| entry: | ||
| call void @llvm.dbg.value(metadata i32 %p, metadata !18, metadata !DIExpression()), !dbg !19 | ||
| %and = and i32 %p, 1, !dbg !20 | ||
| %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* @y, i32 0, i32 %and, !dbg !21 | ||
| %0 = load i32, i32* %arrayidx, align 4, !dbg !22, !tbaa !23 | ||
| %inc = add nsw i32 %0, 1, !dbg !22 | ||
| store i32 %inc, i32* %arrayidx, align 4, !dbg !22, !tbaa !23 | ||
| ret void, !dbg !27 | ||
| } | ||
|
|
||
| ; Function Attrs: nounwind readnone speculatable | ||
| declare void @llvm.dbg.value(metadata, metadata, metadata) #1 | ||
|
|
||
| attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" } | ||
| attributes #1 = { nounwind readnone speculatable } | ||
|
|
||
| !llvm.dbg.cu = !{!2} | ||
| !llvm.module.flags = !{!10, !11, !12} | ||
| !llvm.ident = !{!13} | ||
|
|
||
| !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) | ||
| !1 = distinct !DIGlobalVariable(name: "y", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) | ||
| !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (trunk 331321)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) | ||
| !3 = !DIFile(filename: "hi_foo.c", directory: "/Users/yury/llvmwasm") | ||
| !4 = !{} | ||
| !5 = !{!0} | ||
| !6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 64, elements: !8) | ||
| !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) | ||
| !8 = !{!9} | ||
| !9 = !DISubrange(count: 2) | ||
| !10 = !{i32 2, !"Dwarf Version", i32 4} | ||
| !11 = !{i32 2, !"Debug Info Version", i32 3} | ||
| !12 = !{i32 1, !"wchar_size", i32 4} | ||
| !13 = !{!"clang version 7.0.0 (trunk 331321)"} | ||
| !14 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 3, type: !15, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !2, variables: !17) | ||
| !15 = !DISubroutineType(types: !16) | ||
| !16 = !{null, !7} | ||
| !17 = !{!18} | ||
| !18 = !DILocalVariable(name: "p", arg: 1, scope: !14, file: !3, line: 3, type: !7) | ||
| !19 = !DILocation(line: 3, column: 14, scope: !14) | ||
| !20 = !DILocation(line: 4, column: 7, scope: !14) | ||
| !21 = !DILocation(line: 4, column: 3, scope: !14) | ||
| !22 = !DILocation(line: 4, column: 11, scope: !14) | ||
| !23 = !{!24, !24, i64 0} | ||
| !24 = !{!"int", !25, i64 0} | ||
| !25 = !{!"omnipotent char", !26, i64 0} | ||
| !26 = !{!"Simple C/C++ TBAA"} | ||
| !27 = !DILocation(line: 5, column: 1, scope: !14) |
This file contains 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,73 @@ | ||
| RUN: llc -filetype=obj %p/Inputs/debuginfo1.ll -o %t.debuginfo1.o | ||
| RUN: llc -filetype=obj %p/Inputs/debuginfo2.ll -o %t.debuginfo2.o | ||
| RUN: wasm-ld -r -o %t.wasm %t.debuginfo1.o %t.debuginfo2.o | ||
| RUN: llvm-dwarfdump %t.wasm | FileCheck %s | ||
|
|
||
| CHECK: file format WASM | ||
|
|
||
| CHECK: .debug_info contents: | ||
| CHECK: DW_TAG_compile_unit | ||
| CHECK-NEXT: DW_AT_producer ("clang version 7.0.0 (trunk 331321)") | ||
| CHECK-NEXT: DW_AT_language (DW_LANG_C99) | ||
| CHECK-NEXT: DW_AT_name ("hi.c") | ||
|
|
||
| CHECK: DW_TAG_subprogram | ||
| CHECK-NEXT: DW_AT_low_pc | ||
| CHECK-NEXT: DW_AT_high_pc | ||
| CHECK-NEXT: DW_AT_name ("test") | ||
| CHECK-NEXT: DW_AT_decl_file ("/Users/yury/llvmwasm/hi.c") | ||
| CHECK-NEXT: DW_AT_decl_line (3) | ||
| CHECK-NEXT: DW_AT_prototyped (true) | ||
|
|
||
| CHECK: DW_TAG_formal_parameter | ||
| CHECK-NEXT: DW_AT_name ("t") | ||
| CHECK-NEXT: DW_AT_decl_file ("/Users/yury/llvmwasm/hi.c") | ||
| CHECK-NEXT: DW_AT_decl_line (3) | ||
|
|
||
| CHECK: DW_TAG_subprogram | ||
| CHECK-NEXT: DW_AT_low_pc | ||
| CHECK-NEXT: DW_AT_high_pc | ||
| CHECK-NEXT: DW_AT_name ("_start") | ||
| CHECK-NEXT: DW_AT_decl_file ("/Users/yury/llvmwasm/hi.c") | ||
| CHECK-NEXT: DW_AT_decl_line (7) | ||
|
|
||
| CHECK: DW_TAG_base_type | ||
| CHECK-NEXT: DW_AT_name ("int") | ||
| CHECK-NEXT: DW_AT_encoding (DW_ATE_signed) | ||
| CHECK-NEXT: DW_AT_byte_size (0x04) | ||
|
|
||
| CHECK: DW_TAG_compile_unit | ||
| CHECK-NEXT: DW_AT_producer ("clang version 7.0.0 (trunk 331321)") | ||
| CHECK-NEXT: DW_AT_language (DW_LANG_C99) | ||
| CHECK-NEXT: DW_AT_name ("hi_foo.c") | ||
|
|
||
| CHECK: DW_TAG_variable | ||
| CHECK-NEXT: DW_AT_name ("y") | ||
| CHECK-NEXT: "int[]" | ||
|
|
||
| CHECK: DW_TAG_array_type | ||
|
|
||
| CHECK: DW_TAG_subrange_type | ||
|
|
||
| CHECK: DW_TAG_base_type | ||
| CHECK-NEXT: DW_AT_name ("int") | ||
| CHECK-NEXT: DW_AT_encoding (DW_ATE_signed) | ||
| CHECK-NEXT: DW_AT_byte_size (0x04) | ||
|
|
||
| CHECK: DW_TAG_base_type | ||
| CHECK-NEXT: DW_AT_name ("__ARRAY_SIZE_TYPE__") | ||
| CHECK-NEXT: DW_AT_byte_size (0x08) | ||
| CHECK-NEXT: DW_AT_encoding (DW_ATE_unsigned) | ||
|
|
||
| CHECK: DW_TAG_subprogram | ||
| CHECK-NEXT: DW_AT_low_pc | ||
| CHECK-NEXT: DW_AT_high_pc | ||
| CHECK-NEXT: DW_AT_name ("foo") | ||
| CHECK-NEXT: DW_AT_decl_file ("/Users/yury/llvmwasm/hi_foo.c") | ||
| CHECK-NEXT: DW_AT_decl_line (3) | ||
|
|
||
| CHECK: DW_TAG_formal_parameter | ||
| CHECK-NEXT: DW_AT_name ("p") | ||
| CHECK-NEXT: DW_AT_decl_file ("/Users/yury/llvmwasm/hi_foo.c") | ||
| CHECK-NEXT: DW_AT_decl_line (3) | ||
|
|
This file contains 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 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 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
Oops, something went wrong.