[llvm] 86cd233 - [WebAssembly] Fixed DWARF DW_AT_low_pc encoded as 64-bit in wasm64
Wouter van Oortmerssen via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 30 16:43:07 PDT 2020
Author: Wouter van Oortmerssen
Date: 2020-10-30T16:42:48-07:00
New Revision: 86cd2332ce763dde0e922636bc28789d0c2ad806
URL: https://github.com/llvm/llvm-project/commit/86cd2332ce763dde0e922636bc28789d0c2ad806
DIFF: https://github.com/llvm/llvm-project/commit/86cd2332ce763dde0e922636bc28789d0c2ad806.diff
LOG: [WebAssembly] Fixed DWARF DW_AT_low_pc encoded as 64-bit in wasm64
Also added general wasm64 DWARF test
Also added asserts for unsupported reloc combinations that triggered this bug.
Differential Revision: https://reviews.llvm.org/D90503
Added:
llvm/test/MC/WebAssembly/dwarfdump64.ll
Modified:
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp
index c3d259e6ff20..7cbe9e38fb47 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp
@@ -23,7 +23,9 @@ WebAssemblyMCAsmInfo::~WebAssemblyMCAsmInfo() = default; // anchor.
WebAssemblyMCAsmInfo::WebAssemblyMCAsmInfo(const Triple &T,
const MCTargetOptions &Options) {
- CodePointerSize = CalleeSaveStackSlotSize = T.isArch64Bit() ? 8 : 4;
+ CalleeSaveStackSlotSize = T.isArch64Bit() ? 8 : 4;
+ // So far this is used for DWARF DW_AT_low_pc which is always 32-bit in Wasm.
+ CodePointerSize = 4;
// TODO: What should MaxInstLength be?
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
index db1063ce1551..3fb14c03ed4f 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
@@ -124,6 +124,15 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target,
case FK_Data_8:
if (SymA.isFunction())
return wasm::R_WASM_TABLE_INDEX_I64;
+ if (SymA.isGlobal())
+ llvm_unreachable("unimplemented R_WASM_GLOBAL_INDEX_I64");
+ if (auto Section = static_cast<const MCSectionWasm *>(
+ getFixupSection(Fixup.getValue()))) {
+ if (Section->getKind().isText())
+ llvm_unreachable("unimplemented R_WASM_FUNCTION_OFFSET_I64");
+ else if (!Section->isWasmData())
+ llvm_unreachable("unimplemented R_WASM_SECTION_OFFSET_I64");
+ }
assert(SymA.isData());
return wasm::R_WASM_MEMORY_ADDR_I64;
default:
diff --git a/llvm/test/MC/WebAssembly/dwarfdump64.ll b/llvm/test/MC/WebAssembly/dwarfdump64.ll
new file mode 100644
index 000000000000..0af2a7560516
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/dwarfdump64.ll
@@ -0,0 +1,102 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -filetype=obj %s -o - | llvm-dwarfdump --show-form - | FileCheck %s
+
+; CHECK: .debug_info contents:
+; CHECK-NEXT: 0x00000000: Compile Unit: length = 0x0000006e, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x04 (next unit at 0x00000072)
+
+; CHECK: 0x0000000b: DW_TAG_compile_unit
+; CHECK-NEXT: DW_AT_producer [DW_FORM_strp] ("clang version 6.0.0 (trunk 315924) (llvm/trunk 315960)")
+; CHECK-NEXT: DW_AT_language [DW_FORM_data2] (DW_LANG_C99)
+; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ("test.c")
+; CHECK-NEXT: DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)
+; CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strp] ("/usr/local/google/home/sbc/dev/wasm/simple")
+; CHECK-NEXT: DW_AT_GNU_pubnames [DW_FORM_flag_present] (true)
+; CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x00000002)
+; CHECK-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000002)
+
+; CHECK: 0x00000026: DW_TAG_variable
+; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ("foo")
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (0x00000037 "int*")
+; CHECK-NEXT: DW_AT_external [DW_FORM_flag_present] (true)
+; CHECK-NEXT: DW_AT_decl_file [DW_FORM_data1] ("/usr/local/google/home/sbc/dev/wasm/simple\test.c")
+; CHECK-NEXT: DW_AT_decl_line [DW_FORM_data1] (4)
+; CHECK-NEXT: DW_AT_location [DW_FORM_exprloc] (DW_OP_addr 0x0)
+
+; CHECK: 0x00000037: DW_TAG_pointer_type
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (0x0000003c "int")
+
+; CHECK: 0x0000003c: DW_TAG_base_type
+; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ("int")
+; CHECK-NEXT: DW_AT_encoding [DW_FORM_data1] (DW_ATE_signed)
+; CHECK-NEXT: DW_AT_byte_size [DW_FORM_data1] (0x04)
+
+; CHECK: 0x00000043: DW_TAG_variable
+; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ("ptr2")
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (0x00000054 "void()*")
+; CHECK-NEXT: DW_AT_external [DW_FORM_flag_present] (true)
+; CHECK-NEXT: DW_AT_decl_file [DW_FORM_data1] ("/usr/local/google/home/sbc/dev/wasm/simple\test.c")
+; CHECK-NEXT: DW_AT_decl_line [DW_FORM_data1] (5)
+
+
+
+; TODO: is this correct?
+
+; CHECK-NEXT: DW_AT_location [DW_FORM_exprloc] (DW_OP_addr 0x8)
+
+; CHECK: 0x00000054: DW_TAG_pointer_type
+; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (0x00000059 "void()")
+
+; CHECK: 0x00000059: DW_TAG_subroutine_type
+; CHECK-NEXT: DW_AT_prototyped [DW_FORM_flag_present] (true)
+
+; CHECK: 0x0000005a: DW_TAG_subprogram
+; CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x00000002)
+; CHECK-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000002)
+; CHECK-NEXT: DW_AT_frame_base [DW_FORM_exprloc] (DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value)
+; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ("f2")
+; CHECK-NEXT: DW_AT_decl_file [DW_FORM_data1] ("/usr/local/google/home/sbc/dev/wasm/simple\test.c")
+; CHECK-NEXT: DW_AT_decl_line [DW_FORM_data1] (2)
+; CHECK-NEXT: DW_AT_prototyped [DW_FORM_flag_present] (true)
+; CHECK-NEXT: DW_AT_external [DW_FORM_flag_present] (true)
+
+; CHECK: 0x00000071: NULL
+
+target triple = "wasm64-unknown-unknown"
+
+source_filename = "test.c"
+
+ at myextern = external global i32, align 4
+ at foo = hidden global i32* @myextern, align 4, !dbg !0
+ at ptr2 = hidden global void ()* @f2, align 4, !dbg !6
+
+; Function Attrs: noinline nounwind optnone
+define hidden void @f2() #0 !dbg !17 {
+entry:
+ ret void, !dbg !18
+}
+
+attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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" }
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15}
+!llvm.ident = !{!16}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 4, type: !11, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0 (trunk 315924) (llvm/trunk 315960)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "test.c", directory: "/usr/local/google/home/sbc/dev/wasm/simple")
+!4 = !{}
+!5 = !{!0, !6}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = distinct !DIGlobalVariable(name: "ptr2", scope: !2, file: !3, line: 5, type: !8, isLocal: false, isDefinition: true)
+!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
+!9 = !DISubroutineType(types: !10)
+!10 = !{null}
+!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
+!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!13 = !{i32 2, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{!"clang version 6.0.0 (trunk 315924) (llvm/trunk 315960)"}
+!17 = distinct !DISubprogram(name: "f2", scope: !3, file: !3, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4)
+!18 = !DILocation(line: 2, column: 16, scope: !17)
More information about the llvm-commits
mailing list