WebAssembly / binaryen

Optimizer and compiler/toolchain library for WebAssembly
Apache License 2.0
7.5k stars 743 forks source link

s2wasm problem with debug information #842

Closed tsavola closed 2 years ago

tsavola commented 7 years ago

I've tested this with the latest LLVM/clang trunk and binaryen master, built a few moments ago.

C source:

#include <stddef.h>

size_t bug(void)
{
    return 0;
}

Build commands:

clang --target=wasm32 -g -S -o bug.s bug.c
s2wasm bug.s

Error from s2wasm:

[[object_alias:]]:
==========
2 "/home/user/wag-toolchain/llvm-build/bin/../lib/clang/4.0.
==========
Aborted (core dumped)

The problem goes away when removing the -g option from clang invocation, or changing the size_t result type to something else.

bug.s looks like this:

    .text
    .file   "bug.c"
    .section    .text.bug,"ax",@progbits
    .hidden bug
    .globl  bug
    .type   bug,@function
bug:                                    # @bug
.Lfunc_begin0:
    .file   1 "bug.c"
    .loc    1 4 0                   # bug.c:4:0
    .result     i32
    .local      i32
# BB#0:                                 # %entry
    i32.const   $0=, 0
.Ltmp0:
    .loc    1 5 2 prologue_end      # bug.c:5:2
    return      $0
.Ltmp1:
    .endfunc
.Lfunc_end0:
    .size   bug, .Lfunc_end0-bug

    .file   2 "/home/user/wag-toolchain/llvm-build/bin/../lib/clang/4.0.0/include" "stddef.h"
    .section    .debug_str,"MS",@progbits,1
.Linfo_string0:
    .asciz  "clang version 4.0.0 "  # string offset=0
.Linfo_string1:
    .asciz  "bug.c"                 # string offset=21
.Linfo_string2:
    .asciz  "/home/user/sync/llvm-bug" # string offset=27
.Linfo_string3:
    .asciz  "bug"                   # string offset=52
.Linfo_string4:
    .asciz  "unsigned int"          # string offset=56
.Linfo_string5:
    .asciz  "size_t"                # string offset=69
    .section    .debug_loc,"",@progbits
    .section    .debug_abbrev,"",@progbits
.Lsection_abbrev:
    .int8   1                       # Abbreviation Code
    .int8   17                      # DW_TAG_compile_unit
    .int8   1                       # DW_CHILDREN_yes
    .int8   37                      # DW_AT_producer
    .int8   14                      # DW_FORM_strp
    .int8   19                      # DW_AT_language
    .int8   5                       # DW_FORM_data2
    .int8   3                       # DW_AT_name
    .int8   14                      # DW_FORM_strp
    .int8   16                      # DW_AT_stmt_list
    .int8   23                      # DW_FORM_sec_offset
    .int8   27                      # DW_AT_comp_dir
    .int8   14                      # DW_FORM_strp
    .int8   17                      # DW_AT_low_pc
    .int8   1                       # DW_FORM_addr
    .int8   18                      # DW_AT_high_pc
    .int8   6                       # DW_FORM_data4
    .int8   0                       # EOM(1)
    .int8   0                       # EOM(2)
    .int8   2                       # Abbreviation Code
    .int8   46                      # DW_TAG_subprogram
    .int8   0                       # DW_CHILDREN_no
    .int8   17                      # DW_AT_low_pc
    .int8   1                       # DW_FORM_addr
    .int8   18                      # DW_AT_high_pc
    .int8   6                       # DW_FORM_data4
    .int8   64                      # DW_AT_frame_base
    .int8   24                      # DW_FORM_exprloc
    .int8   3                       # DW_AT_name
    .int8   14                      # DW_FORM_strp
    .int8   58                      # DW_AT_decl_file
    .int8   11                      # DW_FORM_data1
    .int8   59                      # DW_AT_decl_line
    .int8   11                      # DW_FORM_data1
    .int8   39                      # DW_AT_prototyped
    .int8   25                      # DW_FORM_flag_present
    .int8   73                      # DW_AT_type
    .int8   19                      # DW_FORM_ref4
    .int8   63                      # DW_AT_external
    .int8   25                      # DW_FORM_flag_present
    .int8   0                       # EOM(1)
    .int8   0                       # EOM(2)
    .int8   3                       # Abbreviation Code
    .int8   22                      # DW_TAG_typedef
    .int8   0                       # DW_CHILDREN_no
    .int8   73                      # DW_AT_type
    .int8   19                      # DW_FORM_ref4
    .int8   3                       # DW_AT_name
    .int8   14                      # DW_FORM_strp
    .int8   58                      # DW_AT_decl_file
    .int8   11                      # DW_FORM_data1
    .int8   59                      # DW_AT_decl_line
    .int8   11                      # DW_FORM_data1
    .int8   0                       # EOM(1)
    .int8   0                       # EOM(2)
    .int8   4                       # Abbreviation Code
    .int8   36                      # DW_TAG_base_type
    .int8   0                       # DW_CHILDREN_no
    .int8   3                       # DW_AT_name
    .int8   14                      # DW_FORM_strp
    .int8   62                      # DW_AT_encoding
    .int8   11                      # DW_FORM_data1
    .int8   11                      # DW_AT_byte_size
    .int8   11                      # DW_FORM_data1
    .int8   0                       # EOM(1)
    .int8   0                       # EOM(2)
    .int8   0                       # EOM(3)
    .section    .debug_info,"",@progbits
.Lsection_info:
.Lcu_begin0:
    .int32  73                      # Length of Unit
    .int16  4                       # DWARF version number
    .int32  .Lsection_abbrev        # Offset Into Abbrev. Section
    .int8   4                       # Address Size (in bytes)
    .int8   1                       # Abbrev [1] 0xb:0x42 DW_TAG_compile_unit
    .int32  .Linfo_string0          # DW_AT_producer
    .int16  12                      # DW_AT_language
    .int32  .Linfo_string1          # DW_AT_name
    .int32  .Lline_table_start0     # DW_AT_stmt_list
    .int32  .Linfo_string2          # DW_AT_comp_dir
    .int32  .Lfunc_begin0           # DW_AT_low_pc
    .int32  .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
    .int8   2                       # Abbrev [2] 0x26:0x14 DW_TAG_subprogram
    .int32  .Lfunc_begin0           # DW_AT_low_pc
    .int32  .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
    .int8   0                       # DW_AT_frame_base
    .int32  .Linfo_string3          # DW_AT_name
    .int8   1                       # DW_AT_decl_file
    .int8   3                       # DW_AT_decl_line
                                        # DW_AT_prototyped
    .int32  58                      # DW_AT_type
                                        # DW_AT_external
    .int8   3                       # Abbrev [3] 0x3a:0xb DW_TAG_typedef
    .int32  69                      # DW_AT_type
    .int32  .Linfo_string5          # DW_AT_name
    .int8   2                       # DW_AT_decl_file
    .int8   62                      # DW_AT_decl_line
    .int8   4                       # Abbrev [4] 0x45:0x7 DW_TAG_base_type
    .int32  .Linfo_string4          # DW_AT_name
    .int8   7                       # DW_AT_encoding
    .int8   4                       # DW_AT_byte_size
    .int8   0                       # End Of Children Mark
    .section    .debug_ranges,"",@progbits
.Ldebug_range:
    .section    .debug_macinfo,"",@progbits
.Ldebug_macinfo:
.Lcu_macro_begin0:
    .int8   0                       # End Of Macro List Mark
    .section    .debug_pubnames,"",@progbits
    .int32  .LpubNames_end0-.LpubNames_begin0 # Length of Public Names Info
.LpubNames_begin0:
    .int16  2                       # DWARF Version
    .int32  .Lcu_begin0             # Offset of Compilation Unit Info
    .int32  77                      # Compilation Unit Length
    .int32  38                      # DIE offset
    .asciz  "bug"                   # External Name
    .int32  0                       # End Mark
.LpubNames_end0:
    .section    .debug_pubtypes,"",@progbits
    .int32  .LpubTypes_end0-.LpubTypes_begin0 # Length of Public Types Info
.LpubTypes_begin0:
    .int16  2                       # DWARF Version
    .int32  .Lcu_begin0             # Offset of Compilation Unit Info
    .int32  77                      # Compilation Unit Length
    .int32  69                      # DIE offset
    .asciz  "unsigned int"          # External Name
    .int32  58                      # DIE offset
    .asciz  "size_t"                # External Name
    .int32  0                       # End Mark
.LpubTypes_end0:

    .ident  "clang version 4.0.0 "
    .section    .debug_line,"",@progbits
.Lline_table_start0:
dschuff commented 7 years ago

Debug info is something we don't really have good support for (or really, any support for) in s2wasm right now. Currently we are focusing on making proper use of LLVM's MC infrastructure (e.g. https://reviews.llvm.org/D26722) along with wasm binary format support in LLVM. That will be the useful base on which we can build debug info support. There is a ways to go before we have something useful (ultimately we want to provide primitives which will make it possible to implement debuggers for any language in JS or wasm), although we may end up supporting something like source maps in the interim.

aheejin commented 2 years ago

We deleted s2wasm a long time ago, so closing this.