-
Notifications
You must be signed in to change notification settings - Fork 255
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
Handle compressed debug sections in ELF files #344
Conversation
10cb939
to
a2253e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow very nice! That was a lot easier than I expected it to be :)
For alignment, I see that at least for gabi there's ch_addralign
. Could that perhaps be used to properly align the Vec
allocation? (we may need to more manually manage it). In any case though turning on the unaligned
feature and having a little bit of unsafe
here I believe is fine.
For the zlib dependency, I think for inclusion into libstd we'll probably want to avoid flate2
itself and instead use miniz-oxide
directly (less dependencies). That being said I'd be happy to take that as a future action item for myself, no need to tackle that here.
a2253e1
to
6308da3
Compare
ch_addralign is actually a requirement on the alignment of the uncompressed data. Probably we should be handling that. I pushed up a commit to at least bail out if we see a ch_addralign value of anything besides 1. (I haven't seen anything like that in practice.) But if you think we should, we could try to get a vector of the alignment required by ch_addralign. It was just surprisingly annoying to do so. The I pushed up a potential fix for the memory unsafely. Need to think on whether it's sound a little bit harder, and also presumably fix up whatever breakages I introduced for Mach-O/COFF—the fix required touching API shared between the different platforms. |
6308da3
to
87156e4
Compare
Ah ok I see, so the If we're adding the In that case I think it should be ok to remove the align of 1 check. That alignment is something we could respect with the |
Agree that we don't need to check |
d'oh, right! I suppose that because this seems like a general ELF thing that maybe non-dwarf sections may need more alignment, but for our use cases definitely doesn't matter much! |
87156e4
to
e270b89
Compare
ELF files allow debug info sections to be compressed. The libbacktrace backed supported these compressed sections, but the Gimli backend did not. This commit adds that support to the Gimli backend. In my tests (with the BFD linker, lld, and gold) these debug info sections do not obey the alignment requirements that the object crate expects for the gABI compression header, so this commit additionally enables the "unaligned" feature in the upcoming version of the object crate. There is a bit of unsafe to ensure the lifetime of the decompressed sections matches the lifetime of the mmap'd file. I don't think there is a way around this unsafe code, unless we are willing to ditch Gimli's EndianSlice for an (apparently slower) EndianReader backed by a Cow<[u8]>. Fix rust-lang#342.
e270b89
to
5af532b
Compare
👍 I've removed the check on |
Looks great to me, thanks so much again for your help on this! |
Absolutely! Thanks very much for the quick review and merge! It occurs to me that the master branch of backtrace now depends on the |
Ah yeah I'm not too worried about that. @philipc would you be ok making a new publish of |
Yep I can do that. |
|
Thanks! This support is now published with 0.3.49 |
@alexcrichton this will need to wait for the
unaligned
feature to land in an actual release of the object crate, but otherwise it's ready to go from my perspective. Let me know what you think! Don't think there's a good way around theflate2
dependency (I guess we could depend on mini_oxide directly?). Do you think that'll be a showstopper for inclusion in libstd?ELF files allow debug info sections to be compressed. The libbacktrace
backed supported these compressed sections, but the Gimli backend did
not. This commit adds that support to the Gimli backend.
In my tests these debug info sections do not obey the alignment
requirements that the object crate expects for the gABI compression
header (nor can I find a source documenting any alignment requirements),
so this commit additionally enables the "unaligned" feature in the
upcoming version of the object crate.
There is a bit of unsafe to ensure the lifetime of the decompressed
sections matches the lifetime of the mmap'd file. I don't think there is
a way around this unsafe code, unless we are willing to ditch Gimli's
EndianSlice for an (apparently slower) EndianReader backed by a
Cow<[u8]>.
Fix #342.