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

Dwarf EH: enable it #5324

Merged
merged 1 commit into from
Jan 2, 2016
Merged

Conversation

WalterBright
Copy link
Member

No description provided.

@WalterBright
Copy link
Member Author

Needs dlang/druntime#1454

@WalterBright
Copy link
Member Author

I am having trouble reproducing this (though obviously the autotester doesn't). I am having a hard time figuring out which module is failing the unit test - anyone have a clue?

@WalterBright
Copy link
Member Author

Finally tracked it down to etc.linux.memoryerror

@ibuclaw
Copy link
Member

ibuclaw commented Jan 1, 2016

etc.linux.memoryerror

We still use that module?

@WalterBright
Copy link
Member Author

I tracked it down to the use of naked inline assembler in memoryerror.d. The compiler does not emit eh_frame data for naked functions, and so the unwinder failed. The 'fix' I did was to emit eh_frame data as if the stack frame was set up conventionally.

How does gdc handle this?

@WalterBright
Copy link
Member Author

Sigh, I see how gcc handles the eh_frame data for inline assembler:
http://stackoverflow.com/questions/21250626/gcc-assembly-discussion-about-the-value-in-cfa-ebp-esp-and-the-number-in-di
I.e. the assembler programmer is really punished for even trying it.

@WalterBright
Copy link
Member Author

It's working. Woo-hoo!

dwarf_CFA_set_loc(I64 ? 4 : 3);
dwarf_CFA_set_reg_offset(BP, off);
}

Copy link
Member

Choose a reason for hiding this comment

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

Don't think EH can be supported for naked functions, please don't introduce broken hacks just to make our testsuite work.
c++ - Using Try/Catch with naked functions - Stack Overflow
The main point of naked functions is to not setup a stack frame, so assuming a normal stack frame is pointless.

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing stack unwinding mechanism already assumes a normal stack frame. This does not make things worse, it brings it up to the current state by emitting eh_frame info that says it's a normal stack frame.

We can do better by extending the inline assembler to support CFA pseudo-ops, but that would break existing code, and is a non-trivial project itself.

The stack frame info is necessary only if the inline assembler does not call any functions that throw. The etc.linux.memoryerror does do this. I considered removing memoryerror, as it converts seg faults into thrown exceptions, something that doesn't belong in a systems programming language, but decided to simply make it work for now and leave that issue for a separate day.

Copy link
Member

Choose a reason for hiding this comment

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

The existing stack unwinding mechanism already assumes a normal stack frame.

OK, fine.

The stack frame info is necessary only if the inline assembler does not call any functions that throw. The etc.linux.memoryerror does do this. I considered removing memoryerror, as it converts seg faults into thrown exceptions, something that doesn't belong in a systems programming language, but decided to simply make it work for now and leave that issue for a separate day.

I tried hard to prevent memoryerror from happening but couldn't achieve more than moving it to etc. In any case people are now relying on it to get tracebacks, e.g. for server apps, so w/o an alternative it would be very rude to remove it.

@MartinNowak
Copy link
Member

Auto-merge toggled on

@@ -110,7 +112,6 @@ void out_config_init(
config.flags |= CFGalwaysframe; // PIC needs a frame for TLS fixups
}
config.objfmt = OBJ_ELF;
config.ehmethod = dwarfeh ? EH_DWARF : EH_DM;
Copy link
Member

Choose a reason for hiding this comment

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

I hope this means we can easily disable the feature if it doesn't survive the beta testing.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's exactly what it means, and one reason I did it that way. Another reason is it makes it much easier to test, because you cannot build druntime with a non-functional EH system.

MartinNowak added a commit that referenced this pull request Jan 2, 2016
@MartinNowak MartinNowak merged commit d97905e into dlang:master Jan 2, 2016
@WalterBright WalterBright deleted the enable-dwarfeh branch January 2, 2016 21:06
@dnadlinger
Copy link
Member

Nice! Shouldn't the command line option be removed, too?

@MartinNowak
Copy link
Member

Nice! Shouldn't the command line option be removed, too?

Is there a switch to toggle back to the old EH handling? That would be helpful during the beta and should stay in for a little while.

@dnadlinger
Copy link
Member

@MartinNowak: I didn't closely follow the backend implementation, but it seems as if this commit hard-codes the distinction again. But I doubt it would be very useful anyway. You'd need to rebuild druntime/Phobos to use the correct EH method anyway every time you switch. At that point, you can keep two DMD executables around just as well.

@MartinNowak
Copy link
Member

Apparently it did broke a test case that links against C++.
https://travis-ci.org/D-Programming-Language/dmd/jobs/99950483#L1970

@dnadlinger
Copy link
Member

@MartinNowak: That run is for your FreeBSD-related change, not this PR.

@wilzbach
Copy link
Member

As @JackStouffer pointed out, according to @CyberShadow's http://digger.k3.1azy.net/trend/ this caused a 85KiB increase in the hello world binary!?

@WalterBright
Copy link
Member Author

Yeah, well, the dwarf exception handling tables are rather large.

Anyhow, commenting on a PR that was closed several months ago is likely to be overlooked. It would be better to start a thread in the n.g. on it, or open a new bug report.

@wilzbach
Copy link
Member

Anyhow, commenting on a PR that was closed several months ago is likely to be overlooked. It would be better to start a thread in the n.g. on it, or open a new bug report.

Thanks for the advice - I created a bug for reference:
https://issues.dlang.org/show_bug.cgi?id=15967

@quickfur
Copy link
Member

quickfur commented Sep 2, 2016

Seems this PR caused a bug (or so it is claimed): https://issues.dlang.org/show_bug.cgi?id=15625

@schuetzm
Copy link
Contributor

... and another one: https://issues.dlang.org/show_bug.cgi?id=16699

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.

7 participants