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

Let arithmetic overflows wrap when executing line programs #508

Merged
merged 1 commit into from
May 18, 2020

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented May 15, 2020

The DWARF spec isn't clear on how to handle overflow, but there is a small
chance some random toolchain in the wild relies on overflow to do hacky
subtraction of the current row's address. And wrapping is faster than checking
for overflow and returning an error anyways. So we just do wrapping.

/me shrugs

Fixes #506

@fitzgen fitzgen requested a review from philipc May 15, 2020 20:35
fitzgen added a commit to fitzgen/gimli that referenced this pull request May 15, 2020
Similar to gimli-rs#508: The DWARF and `.eh_frame` specs don't specify how to handle
overflows. So we will use wrapping.
@bjorn3
Copy link
Contributor

bjorn3 commented May 15, 2020

In case of fields represented as uleb128 data, shouldn't overflow be impossible from a spec point of view? (bigint)

@philipc
Copy link
Collaborator

philipc commented May 16, 2020

In case of fields represented as uleb128 data, shouldn't overflow be impossible from a spec point of view? (bigint)

Yes, and related to that, it probably also makes more sense for us to use u32 for line numbers. e.g that's all the backtrace-rs ends up returning. Not something for this PR though.

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.

I said in #506 that I think returning an error is better, but I'm not so sure now. This is performance sensitive and doesn't currently need any error handling so I'm not keen on adding it. I also think it's quite unlikely that toolchains will intentionally do this, but maybe they do unintentionally, and it's better for us to cope as best we can? I'm pretty sure that all other consumers are going to be doing wrapping arithmetic, so if toolchains do emit this then we'd be the only ones failing to consume it.

@philipc
Copy link
Collaborator

philipc commented May 16, 2020

Btw, CI failed (in addition to not reporting the result again...)

@fitzgen
Copy link
Member Author

fitzgen commented May 18, 2020

In case of fields represented as uleb128 data, shouldn't overflow be impossible from a spec point of view? (bigint)

This makes sense when not considering what semantic data is encoded in leb128.

For line numbers, I see the argument for big int semantically (but I don't think we should actually use big ints here).

However PCs in the line table are not big ints, they are fixed size words of the target architecture's pointer width. To be maximally correct, I think we would want to wrap or error on overflow at that target pointer width, rather than u64.

@fitzgen
Copy link
Member Author

fitzgen commented May 18, 2020

This is performance sensitive and doesn't currently need any error handling so I'm not keen on adding it. I also think it's quite unlikely that toolchains will intentionally do this, but maybe they do unintentionally, and it's better for us to cope as best we can? I'm pretty sure that all other consumers are going to be doing wrapping arithmetic, so if toolchains do emit this then we'd be the only ones failing to consume it.

Yeah, this was basically my logic as well.

The DWARF spec isn't clear on how to handle overflow, but there is a small
chance some random toolchain in the wild relies on overflow to do hacky
subtraction of the current row's address. And wrapping is faster than checking
for overflow and returning an error anyways. So we just do wrapping.

/me shrugs

Fixes gimli-rs#506
@fitzgen fitzgen force-pushed the debug-line-wrap-overflows branch from e101773 to 2b23089 Compare May 18, 2020 16:49
@fitzgen fitzgen merged commit 1ff72fe into gimli-rs:master May 18, 2020
@fitzgen fitzgen deleted the debug-line-wrap-overflows branch May 18, 2020 18:00
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.

Add with overflow when executing .debug_line programs
3 participants