Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid ranges read from wasm file #629

Closed
shuoli84 opened this issue Oct 26, 2022 · 2 comments · Fixed by #631
Closed

Invalid ranges read from wasm file #629

shuoli84 opened this issue Oct 26, 2022 · 2 comments · Fixed by #631

Comments

@shuoli84
Copy link
Contributor

I run dwarfdump agains a wasm file, and get invalid address ranges compare to llvm's impl.
Those entries with 0xfffffffe are invalid ones. Seems valid entries are mixed with invalid ones, is it something known?

UNIT<.debug_info+0x00000a0e>: length = 0x2cc2f, format = Dwarf32, version = 4, address_size = 4, abbrev_offset = 0x389
< 0><0x0000000b>  DW_TAG_compile_unit
                    DW_AT_producer              clang LLVM (rustc version 1.66.0-nightly (b8b5caee0 2022-10-16))
                    DW_AT_language              DW_LANG_Rust
                    DW_AT_name                  library/std/src/lib.rs/@/std.65018fcd-cgu.0
                    DW_AT_stmt_list             <.debug_line+0x0000043c>
                    DW_AT_comp_dir              /rustc/b8b5caee04116c7383eb1c6470fcf15c437a60d4
                    DW_AT_GNU_pubnames          yes
                    DW_AT_low_pc                0x00000000
                    DW_AT_ranges                <rnglist at .debug_ranges+0x0000fcc8 with 785 entries>
                        [ 0] <address pair low-off: 0xfffffffe addr 0xfffffffe high-off: 0xfffffffe addr 0xfffffffe>
                        [ 1] <address pair low-off: 0xfffffffe addr 0xfffffffe high-off: 0xfffffffe addr 0xfffffffe>
                        [ 2] <address pair low-off: 0x000002b9 addr 0x000002b9 high-off: 0x000002c6 addr 0x000002c6>
                        [ 3] <address pair low-off: 0x000002c7 addr 0x000002c7 high-off: 0x000002d4 addr 0x000002d4>
                        [ 4] <address pair low-off: 0x000002d5 addr 0x000002d5 high-off: 0x000002e1 addr 0x000002e1>
                        [ 5] <address pair low-off: 0xfffffffe addr 0xfffffffe high-off: 0xfffffffe addr 0xfffffffe>
                        [ 6] <address pair low-off: 0xfffffffe addr 0xfffffffe high-off: 0xfffffffe addr 0xfffffffe>
                        [ 7] <address pair low-off: 0xfffffffe addr 0xfffffffe high-off: 0xfffffffe addr 0xfffffffe>
                        [ 8] <address pair low-off: 0xfffffffe addr 0xfffffffe high-off: 0xfffffffe addr 0xfffffffe>
                        [ 9] <address pair low-off: 0xfffffffe addr 0xfffffffe high-off: 0xfffffffe addr 0xfffffffe>
                        [10] <address pair low-off: 0xfffffffe addr 0xfffffffe high-off: 0xfffffffe addr 0xfffffffe>

llvm dwarfdump's output

0x00000a0e: Compile Unit: length = 0x0002cc2f, format = DWARF32, version = 0x0004, abbr_offset = 0x0389, addr_size = 0x04 (next unit at 0x0002d641)

0x00000a19: DW_TAG_compile_unit
              DW_AT_producer    ("clang LLVM (rustc version 1.66.0-nightly (b8b5caee0 2022-10-16))")
              DW_AT_language    (DW_LANG_Rust)
              DW_AT_name        ("library/std/src/lib.rs/@/std.65018fcd-cgu.0")
              DW_AT_stmt_list   (0x0000043c)
              DW_AT_comp_dir    ("/rustc/b8b5caee04116c7383eb1c6470fcf15c437a60d4")
              DW_AT_GNU_pubnames        (true)
              DW_AT_low_pc      (0x00000000)
              DW_AT_ranges      (0x0000fcc8
                 [0x000002b9, 0x000002c6)
                 [0x000002c7, 0x000002d4)
                 [0x000002d5, 0x000002e1)
                 [0x000002e2, 0x000002f1)
                 [0x000002f2, 0x00000335)
                 [0x00000336, 0x0000034a)
                 [0x0000034c, 0x000004db)
                 [0x00000714, 0x00000859)
                 [0x00000944, 0x000009b5)
@shuoli84
Copy link
Contributor Author

After some investigation, I think I found the reason. In llvm's impl, there is something called address tombstone, if any address is tombstone, then it should be skipped.

Here is the code skip tombstones:
https://github.com/llvm/llvm-project/blob/2bdfececef4330b3a6489cdb67c57eb771d5f9e4/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp#L92

ref: https://llvm.org/doxygen/namespacellvm_1_1dwarf.html#ad31a7a9cab8288e009f13cfabc5afc13

@philipc
Copy link
Collaborator

philipc commented Oct 26, 2022

0xfffffffe appears to be a tombstone value that llvm uses for entries that are invalidated during linking. This is similar to a proposed addition for DWARF v6 (https://dwarfstd.org/ShowIssue.php?issue=200609.1), but llvm is using its own scheme for DWARF v4. We could add something to gimli to make it easy to skip them, or your could skip them yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants