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

[CFI] Skip zeros when entry length is zero #486

Merged
merged 1 commit into from
Apr 9, 2020

Conversation

calixteman
Copy link
Contributor

Use the same trick as in readelf:
https://github.com/bminor/binutils-gdb/blob/master/binutils/dwarf.c#L7820

It aims to fix issue #485.

@coveralls
Copy link

coveralls commented Apr 8, 2020

Coverage Status

Coverage decreased (-0.1%) to 85.371% when pulling f8c6f49 on calixteman:skip_zero into f5486d0 on gimli-rs:master.

src/read/cfi.rs Outdated Show resolved Hide resolved
src/read/cfi.rs Outdated Show resolved Hide resolved
src/read/cfi.rs Show resolved Hide resolved
@philipc
Copy link
Collaborator

philipc commented Apr 9, 2020

It'd be nice to figure out which compiler/linker is causing this and fix them too. Note that llvm-dwarfdump doesn't handle this kind of padding either.

Also please squash the commits.

Only skip null bytes when format is Dwarf32

Remove skip_null
Copy link
Collaborator

@philipc philipc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@philipc philipc merged commit 53c802a into gimli-rs:master Apr 9, 2020
@calixteman
Copy link
Contributor Author

It'd be nice to figure out which compiler/linker is causing this and fix them too. Note that llvm-dwarfdump doesn't handle this kind of padding either.

I filed a bug for that:
https://bugzilla.mozilla.org/show_bug.cgi?id=1628673

return Ok(None);
}

// Hack: skip zero padding inserted by buggy compilers/linkers.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically speaking, skipping the zeros 4 by 4 works, but I don't think it's the right thing to do. What you actually have is not padding. What you have is multiple empty CIEs one after the other.

Copy link
Collaborator

@philipc philipc Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically they are zero terminators + zero padding, not empty CIEs. And zero terminators are a .eh_frame thing, not a .debug_frame thing, so the bug is they shouldn't occur here. But why do you think that skipping them isn't the right thing to do? What should we do? Skipping them in .eh_frame would definitely be wrong, but I think it's okay to do it for .debug_frame?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the mozilla bug:

That's unfortunate, but not invalid. They "just" indicate empty records.

Where in the DWARF spec does it say these are valid?

Copy link

@glandium glandium Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd ask the opposite question: where in the DWARF spec does it say they are invalid? There is no obvious mention of CIE length not being valid if it's 0. The spec doesn't say all fields must be there, and in fact, they can't since different versions of DWARF have different number of fields.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, but different versions must at least have a version field, and a length of 0 doesn't allow for that.

Also there is no point to have a zero length:

  • it provides no benefit over just omitting it (not even for padding, because padding should be including in the CFI entry length and use DW_CFA_nop instead)
  • .eh_frame handling requires you to stop processing after a zero length, so it's not even compatible with that

And given that multiple DWARF consumers don't handle it correctly, it's not at all obvious that it is valid. (You can add ubuntu's dwarfdump to the list of consumers that don't handle it.)

I don't think it's the right thing to do

What do you think should be done instead?

@philipc
Copy link
Collaborator

philipc commented Apr 10, 2020

I filed a nasm bug: https://bugzilla.nasm.us/show_bug.cgi?id=3392657

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

Successfully merging this pull request may close these issues.

None yet

4 participants