diff options
author | Wouter van Oortmerssen <aardappel@gmail.com> | 2021-02-26 09:53:16 -0800 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2021-03-01 11:53:30 -0800 |
commit | a0f4526836a76a5e2f56d25c7e35cfd89b2d0908 (patch) | |
tree | 539987713b08312d093fcf847afcca8220c9909d | |
parent | 011e7bcaa3194ed4ca3fec48263f5ef69fc1813c (diff) | |
download | llvm-a0f4526836a76a5e2f56d25c7e35cfd89b2d0908.zip llvm-a0f4526836a76a5e2f56d25c7e35cfd89b2d0908.tar.gz llvm-a0f4526836a76a5e2f56d25c7e35cfd89b2d0908.tar.bz2 |
[WebAssembly] Fix split-dwarf not emitting DW_OP_WASM_location correctly
It was using the regular path for target indices that uses uleb, but TI_GLOBAL_RELOC needs to be uint32_t.
Introduced here: https://reviews.llvm.org/D85685
Fixes: https://github.com/emscripten-core/emscripten/issues/13240
Differential Revision: https://reviews.llvm.org/D97564
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 17 | ||||
-rw-r--r-- | llvm/test/MC/WebAssembly/dwarfdump.ll | 56 |
2 files changed, 67 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index 8a16b9f..3d378df 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -447,10 +447,7 @@ DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) { // FIXME: duplicated from Target/WebAssembly/WebAssembly.h // don't want to depend on target specific headers in this code? const unsigned TI_GLOBAL_RELOC = 3; - // FIXME: when writing dwo, we need to avoid relocations. Probably - // the "right" solution is to treat globals the way func and data symbols - // are (with entries in .debug_addr). - if (FrameBase.Location.WasmLoc.Kind == TI_GLOBAL_RELOC && !isDwoUnit()) { + if (FrameBase.Location.WasmLoc.Kind == TI_GLOBAL_RELOC) { // These need to be relocatable. assert(FrameBase.Location.WasmLoc.Index == 0); // Only SP so far. auto SPSym = cast<MCSymbolWasm>( @@ -468,8 +465,16 @@ DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) { DIELoc *Loc = new (DIEValueAllocator) DIELoc; addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_WASM_location); addSInt(*Loc, dwarf::DW_FORM_sdata, TI_GLOBAL_RELOC); - addLabel(*Loc, dwarf::DW_FORM_data4, SPSym); - DD->addArangeLabel(SymbolCU(this, SPSym)); + if (!isDwoUnit()) { + addLabel(*Loc, dwarf::DW_FORM_data4, SPSym); + DD->addArangeLabel(SymbolCU(this, SPSym)); + } else { + // FIXME: when writing dwo, we need to avoid relocations. Probably + // the "right" solution is to treat globals the way func and data + // symbols are (with entries in .debug_addr). + // For now, since we only ever use index 0, this should work as-is. + addUInt(*Loc, dwarf::DW_FORM_data4, FrameBase.Location.WasmLoc.Index); + } addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value); addBlock(*SPDie, dwarf::DW_AT_frame_base, Loc); } else { diff --git a/llvm/test/MC/WebAssembly/dwarfdump.ll b/llvm/test/MC/WebAssembly/dwarfdump.ll index 6a53cdd..5383646 100644 --- a/llvm/test/MC/WebAssembly/dwarfdump.ll +++ b/llvm/test/MC/WebAssembly/dwarfdump.ll @@ -1,4 +1,6 @@ ; RUN: llc -filetype=obj %s -o - | llvm-dwarfdump - | FileCheck %s +; RUN: llc -filetype=obj --split-dwarf-file=%t.dwo --split-dwarf-output=%t.dwo %s -o %t.o +; RUN: llvm-dwarfdump %t.dwo | FileCheck %s -check-prefix=SPLIT ; 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) @@ -55,6 +57,60 @@ ; CHECK: 0x00000071: NULL + +; SPLIT: .debug_info.dwo contents: +; SPLIT-NEXT: 0x00000000: Compile Unit: length = 0x0000004c, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x04 (next unit at 0x00000050) + +; SPLIT: 0x0000000b: DW_TAG_compile_unit +; SPLIT-NEXT: DW_AT_producer ("clang version 6.0.0 (trunk 315924) (llvm/trunk 315960)") +; SPLIT-NEXT: DW_AT_language (DW_LANG_C99) +; SPLIT-NEXT: DW_AT_name ("test.c") +; SPLIT-NEXT: DW_AT_GNU_dwo_name ("{{.*}}dwarfdump.ll.tmp.dwo") +; SPLIT-NEXT: DW_AT_GNU_dwo_id (0xad3151f12153fa17) + +; SPLIT: 0x00000019: DW_TAG_variable +; SPLIT-NEXT: DW_AT_name ("foo") +; SPLIT-NEXT: DW_AT_type (0x00000024 "int*") +; SPLIT-NEXT: DW_AT_external (true) +; SPLIT-NEXT: DW_AT_decl_file (0x01) +; SPLIT-NEXT: DW_AT_decl_line (4) +; SPLIT-NEXT: DW_AT_location (DW_OP_GNU_addr_index 0x0) + +; SPLIT: 0x00000024: DW_TAG_pointer_type +; SPLIT-NEXT: DW_AT_type (0x00000029 "int") + +; SPLIT: 0x00000029: DW_TAG_base_type +; SPLIT-NEXT: DW_AT_name ("int") +; SPLIT-NEXT: DW_AT_encoding (DW_ATE_signed) +; SPLIT-NEXT: DW_AT_byte_size (0x04) + +; SPLIT: 0x0000002d: DW_TAG_variable +; SPLIT-NEXT: DW_AT_name ("ptr2") +; SPLIT-NEXT: DW_AT_type (0x00000038 "void()*") +; SPLIT-NEXT: DW_AT_external (true) +; SPLIT-NEXT: DW_AT_decl_file (0x01) +; SPLIT-NEXT: DW_AT_decl_line (5) +; SPLIT-NEXT: DW_AT_location (DW_OP_GNU_addr_index 0x1) + +; SPLIT: 0x00000038: DW_TAG_pointer_type +; SPLIT-NEXT: DW_AT_type (0x0000003d "void()") + +; SPLIT: 0x0000003d: DW_TAG_subroutine_type +; SPLIT-NEXT: DW_AT_prototyped (true) + +; SPLIT: 0x0000003e: DW_TAG_subprogram +; SPLIT-NEXT: DW_AT_low_pc (indexed (00000002) address = <unresolved>) +; SPLIT-NEXT: DW_AT_high_pc (0x00000002) +; SPLIT-NEXT: DW_AT_frame_base (DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value) +; SPLIT-NEXT: DW_AT_name ("f2") +; SPLIT-NEXT: DW_AT_decl_file (0x01) +; SPLIT-NEXT: DW_AT_decl_line (2) +; SPLIT-NEXT: DW_AT_prototyped (true) +; SPLIT-NEXT: DW_AT_external (true) + +; SPLIT: 0x0000004f: NULL + + target triple = "wasm32-unknown-unknown" source_filename = "test.c" |