[lld] r333047 - [WebAssembly] Fix crash when relocation synbol is not live
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue May 22 18:38:00 PDT 2018
Author: sbc
Date: Tue May 22 18:38:00 2018
New Revision: 333047
URL: http://llvm.org/viewvc/llvm-project?rev=333047&view=rev
Log:
[WebAssembly] Fix crash when relocation synbol is not live
When a symbol is GC'd it can still be references by relocations
in the debug sections, but such symbols are not assigned virtual
addresses.
This change adds a new global data symbol which gets GC'd but
should still appears in the output debug info, albeit with a 0
address.
Fixes 37555
Differential Revision: https://reviews.llvm.org/D47238
Modified:
lld/trunk/test/wasm/Inputs/debuginfo1.ll
lld/trunk/test/wasm/Inputs/debuginfo2.ll
lld/trunk/test/wasm/debuginfo.test
lld/trunk/wasm/InputFiles.cpp
Modified: lld/trunk/test/wasm/Inputs/debuginfo1.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/Inputs/debuginfo1.ll?rev=333047&r1=333046&r2=333047&view=diff
==============================================================================
--- lld/trunk/test/wasm/Inputs/debuginfo1.ll (original)
+++ lld/trunk/test/wasm/Inputs/debuginfo1.ll Tue May 22 18:38:00 2018
@@ -5,7 +5,7 @@ target triple = "wasm32-unknown-unknown"
; // hi.c:
; extern void foo(int);
-;
+;
; int test(int t) {
; return t * t;
; }
Modified: lld/trunk/test/wasm/Inputs/debuginfo2.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/Inputs/debuginfo2.ll?rev=333047&r1=333046&r2=333047&view=diff
==============================================================================
--- lld/trunk/test/wasm/Inputs/debuginfo2.ll (original)
+++ lld/trunk/test/wasm/Inputs/debuginfo2.ll Tue May 22 18:38:00 2018
@@ -5,23 +5,27 @@ target triple = "wasm32-unknown-unknown"
; // hi_foo.c:
; int y[2] = {23, 41};
-;
+;
; void foo(int p) {
; y[p & 1]++;
; }
+;
+; // Will be GCed, but remain visible in debug info
+; int z[2] = {1, 2};
@y = hidden local_unnamed_addr global [2 x i32] [i32 23, i32 41], align 4, !dbg !0
+ at z = hidden local_unnamed_addr global [2 x i32] [i32 1, i32 2], align 4, !dbg !6
; Function Attrs: nounwind
-define hidden void @foo(i32 %p) local_unnamed_addr #0 !dbg !14 {
+define hidden void @foo(i32 %p) local_unnamed_addr #0 !dbg !16 {
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
+ call void @llvm.dbg.value(metadata i32 %p, metadata !20, metadata !DIExpression()), !dbg !21
+ %and = and i32 %p, 1, !dbg !22
+ %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* @y, i32 0, i32 %and, !dbg !23
+ %0 = load i32, i32* %arrayidx, align 4, !dbg !24, !tbaa !25
+ %inc = add nsw i32 %0, 1, !dbg !24
+ store i32 %inc, i32* %arrayidx, align 4, !dbg !24, !tbaa !25
+ ret void, !dbg !29
}
; Function Attrs: nounwind readnone speculatable
@@ -31,34 +35,36 @@ attributes #0 = { nounwind "correctly-ro
attributes #1 = { nounwind readnone speculatable }
!llvm.dbg.cu = !{!2}
-!llvm.module.flags = !{!10, !11, !12}
-!llvm.ident = !{!13}
+!llvm.module.flags = !{!12, !13, !14}
+!llvm.ident = !{!15}
!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")
+!1 = distinct !DIGlobalVariable(name: "y", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (trunk 332913) (llvm/trunk 332919)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "hi_foo.c", directory: "/usr/local/google/home/sbc/dev/wasm/llvm-build")
!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, retainedNodes: !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)
+!5 = !{!0, !6}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = distinct !DIGlobalVariable(name: "z", scope: !2, file: !3, line: 8, type: !8, isLocal: false, isDefinition: true)
+!8 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 64, elements: !10)
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !{!11}
+!11 = !DISubrange(count: 2)
+!12 = !{i32 2, !"Dwarf Version", i32 4}
+!13 = !{i32 2, !"Debug Info Version", i32 3}
+!14 = !{i32 1, !"wchar_size", i32 4}
+!15 = !{!"clang version 7.0.0 (trunk 332913) (llvm/trunk 332919)"}
+!16 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 3, type: !17, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !19)
+!17 = !DISubroutineType(types: !18)
+!18 = !{null, !9}
+!19 = !{!20}
+!20 = !DILocalVariable(name: "p", arg: 1, scope: !16, file: !3, line: 3, type: !9)
+!21 = !DILocation(line: 3, column: 14, scope: !16)
+!22 = !DILocation(line: 4, column: 7, scope: !16)
+!23 = !DILocation(line: 4, column: 3, scope: !16)
+!24 = !DILocation(line: 4, column: 11, scope: !16)
+!25 = !{!26, !26, i64 0}
+!26 = !{!"int", !27, i64 0}
+!27 = !{!"omnipotent char", !28, i64 0}
+!28 = !{!"Simple C/C++ TBAA"}
+!29 = !DILocation(line: 5, column: 1, scope: !16)
Modified: lld/trunk/test/wasm/debuginfo.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/debuginfo.test?rev=333047&r1=333046&r2=333047&view=diff
==============================================================================
--- lld/trunk/test/wasm/debuginfo.test (original)
+++ lld/trunk/test/wasm/debuginfo.test Tue May 22 18:38:00 2018
@@ -1,13 +1,13 @@
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: wasm-ld -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_producer ("clang version 7.0.0 (trunk {{.*}})")
CHECK-NEXT: DW_AT_language (DW_LANG_C99)
CHECK-NEXT: DW_AT_name ("hi.c")
@@ -37,13 +37,17 @@ CHECK-NEXT: DW_AT_encodin
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_producer ("clang version 7.0.0 (trunk {{.*}})")
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-NEXT: DW_AT_type (0x00000097 "int[]")
+CHECK-NEXT: DW_AT_external (true)
+CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
+CHECK-NEXT: DW_AT_decl_line (1)
+CHECK: DW_AT_location (DW_OP_addr 0x400)
CHECK: DW_TAG_array_type
@@ -59,15 +63,23 @@ CHECK-NEXT: DW_AT_name ("
CHECK-NEXT: DW_AT_byte_size (0x08)
CHECK-NEXT: DW_AT_encoding (DW_ATE_unsigned)
+CHECK: DW_TAG_variable
+CHECK-NEXT: DW_AT_name ("z")
+CHECK-NEXT: DW_AT_type (0x00000097 "int[]")
+CHECK-NEXT: DW_AT_external (true)
+CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
+CHECK-NEXT: DW_AT_decl_line (8)
+CHECK-NEXT: DW_AT_location (DW_OP_addr 0x0)
+
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_file ("{{.*}}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_file ("{{.*}}hi_foo.c")
CHECK-NEXT: DW_AT_decl_line (3)
Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=333047&r1=333046&r2=333047&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Tue May 22 18:38:00 2018
@@ -126,7 +126,8 @@ uint32_t ObjFile::calcNewValue(const Was
case R_WEBASSEMBLY_MEMORY_ADDR_I32:
case R_WEBASSEMBLY_MEMORY_ADDR_LEB:
if (auto *Sym = dyn_cast<DefinedData>(getDataSymbol(Reloc.Index)))
- return Sym->getVirtualAddress() + Reloc.Addend;
+ if (Sym->isLive())
+ return Sym->getVirtualAddress() + Reloc.Addend;
return 0;
case R_WEBASSEMBLY_TYPE_INDEX_LEB:
return TypeMap[Reloc.Index];
More information about the llvm-commits
mailing list