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

Error "Found an abbreviation code that has already been used" #668

Open
xtuc opened this issue Jul 27, 2023 · 6 comments
Open

Error "Found an abbreviation code that has already been used" #668

xtuc opened this issue Jul 27, 2023 · 6 comments

Comments

@xtuc
Copy link

xtuc commented Jul 27, 2023

Hi,

When compiling from Rust to Wasm, the DWARF info are sometimes invalid to gimli and throw "Found an abbreviation code that has already been used". It seems to happen only with larger codebases and I don't have a good way to reproduce at the moment.

Is that a know issue by any chance? Please let me know what you need to debug.

@philipc
Copy link
Collaborator

philipc commented Jul 28, 2023

Can you provide a file that this occurs for, or otherwise provide steps to reproduce the error? Do other tools work on the file, such as llvm-dwarfdump?

@xtuc
Copy link
Author

xtuc commented Jul 28, 2023

llvm-dwarfdump crashes as well:


...
warning: mismatching address size at offset 0x00274d05 expected 0x04 found 0x4f
warning: address size 0x4f of DW_LNE_set_address opcode at offset 0x00274d05 is unsupported
warning: unexpected line op length at offset 0x002d8dc4 expected 0x03 found 0x02
warning: mismatching address size at offset 0x002dc17b expected 0x04 found 0x02
warning: unexpected line op length at offset 0x002ec1a9 expected 0x03 found 0x0a
warning: unexpected line op length at offset 0x00321947 expected 0x29 found 0x02
warning: mismatching address size at offset 0x00470ae0 expected 0x04 found 0x02
...

0x000002eb:         DW_TAG_structure_type
                      DW_AT_name        ("NonNull<u64>")
                      DW_AT_byte_size   (0x04)
                      DW_AT_alignment   (4)

0x000002f2:           DW_TAG_template_type_parameter
                        DW_AT_type      (0x0000053b "
Program received signal SIGSEGV, Segmentation fault.

(gdb) bt
#0  0x00007ffff3d19145 in llvm::DWARFAbbreviationDeclaration::getAttributeOffsetFromIndex(unsigned int, unsigned long, llvm::DWARFUnit const&) const () from /lib/x86_64-linux-gnu/libLLVM-14.so.1
#1  0x00007ffff3d1943f in llvm::DWARFAbbreviationDeclaration::getAttributeValue(unsigned long, llvm::dwarf::Attribute, llvm::DWARFUnit const&) const () from /lib/x86_64-linux-gnu/libLLVM-14.so.1

I'll try to send a repro.

@xtuc
Copy link
Author

xtuc commented Jul 28, 2023

I can reproduce on another project that I can share. This time llvm-dwarfdump doesn't crash, it stops with:

0x002f1083: Compile Unit: length = 0x0000063c, format = DWARF32, version = 0x0004, abbr_offset = 0x31d6a, addr_size = 0x04 (next unit at 0x002f16c3)
warning: DWARF unit at offset 0x002f1083 contains invalid abbreviation 1 at offset 0x002f108f, valid abbreviations are 
<compile unit can't be parsed!>

See debug-58a3a4f8-21c4-49da-936c-974edf11f21d.wasm.zip

Since llvm-dwarfdump also failed to decode DWARF, this is more a Rust issue no?

@philipc
Copy link
Collaborator

philipc commented Jul 28, 2023

Yes, I'll have a look later, but it sounds like this is a bug in the compiler producing the DWARF, and it is correct for gimli to give an error for this.

@xtuc
Copy link
Author

xtuc commented Aug 4, 2023

Should I report the issue to Rust, since it seems to be emitting invalid DWARF?

@philipc
Copy link
Collaborator

philipc commented Aug 5, 2023

Yes, this looks like a compiler bug or linker bug. The .debug_abbrev section is missing the final null code byte at the end of an abbreviation list for the first unit, so gimli continues parsing the abbreviations for the following unit and encounters a duplicate. Additionally, the abbreviation offset for the second unit is set as if there was an null code byte (the duplicate occurs at offset 0x27c, but the second unit specifies an abbrev_offset of 0x27d), so parsing abbreviations for the second unit fails due to an invalid DW_CHILDREN value.

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

No branches or pull requests

2 participants