[llvm] a0f4526 - [WebAssembly] Fix split-dwarf not emitting DW_OP_WASM_location correctly

Wouter van Oortmerssen via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 1 11:53:53 PST 2021


Author: Wouter van Oortmerssen
Date: 2021-03-01T11:53:30-08:00
New Revision: a0f4526836a76a5e2f56d25c7e35cfd89b2d0908

URL: https://github.com/llvm/llvm-project/commit/a0f4526836a76a5e2f56d25c7e35cfd89b2d0908
DIFF: https://github.com/llvm/llvm-project/commit/a0f4526836a76a5e2f56d25c7e35cfd89b2d0908.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    llvm/test/MC/WebAssembly/dwarfdump.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 8a16b9f2fd0a..3d378df287ac 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 6a53cdd724a2..5383646220d4 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"


        


More information about the llvm-commits mailing list