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

gimli-symbolize fails with compressed debug info #342

Closed
benesch opened this issue Jun 9, 2020 · 4 comments · Fixed by #344
Closed

gimli-symbolize fails with compressed debug info #342

benesch opened this issue Jun 9, 2020 · 4 comments · Fixed by #344
Labels
gimli Related to the gimli implementation

Comments

@benesch
Copy link
Contributor

benesch commented Jun 9, 2020

I've put together a full reproduction, with commentary, here: https://github.com/benesch/rust-zdebuginfo

The gist is that Rust generates an absolutely massive amount of debug info by default. (For a deep dive into why, see MaterializeInc/materialize#2691.) One easy workaround is to compress the debug info sections, which you can accomplish on Linux with a .cargo/config like the following:

rustflags = ["-C", "link-arg=-Wl,--compress-debug-sections=zlib-gabi"]

Unfortunately, with the new gimli-symbolizer feature, backtraces produced by such a binary fail to symbolicate, though the libbacktrace-based implementation handles them fine.

@alexcrichton
Copy link
Member

Thanks for the report! I learned today that libbacktrace embedded a zlib inflater. That's something I never knew before, and is quite surprising to me!

In any case given that this is supported by libbacktrace this definitely seems worthwhile to support with gimli too.

@benesch
Copy link
Contributor Author

benesch commented Jun 9, 2020

I learned today that libbacktrace embedded a zlib inflater. That's something I never knew before, and is quite surprising to me!

libbacktrace is a pretty wild piece of software, isn't it? :) It's amazing how much software you have to vendor to get reliable backtraces across the various platforms/compiler toolchains that it supports.

I'm happy to take a stab at this, @alexcrichton. Let me pop over to gimli and have a look around—unless you're already working on this?

@alexcrichton
Copy link
Member

Nah feel free!

I'll warn you though that this crate is semi-nonstandard in that I've been trying to keep the dependencies super slim for eventual inclusion of gimli into libstd. In that sense the implementation may duplicate a bit what's already in the object crate or be a bit verbose, but that's ok! In general I'd recommend getting something working and then we can always work to slim it down later. Fixing crates.io seems like a good primary goal in the meantime.

@benesch
Copy link
Contributor Author

benesch commented Jun 9, 2020

I'll warn you though that this crate is semi-nonstandard in that I've been trying to keep the dependencies super slim for eventual inclusion of gimli into libstd.

Heh, that was actually what motivated me to file this issue! It's easy enough for us to opt-into the old implementation at Materialize when using the library from crates.io, but we'll be in trouble if this winds up in libstd, where we can't twiddle the knobs.

In general I'd recommend getting something working and then we can always work to slim it down later.

👍 thanks for the heads up!

benesch added a commit to benesch/backtrace-rs that referenced this issue Jun 10, 2020
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 rust-lang#342.
benesch added a commit to benesch/backtrace-rs that referenced this issue Jun 10, 2020
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 rust-lang#342.
benesch added a commit to benesch/backtrace-rs that referenced this issue Jun 10, 2020
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 rust-lang#342.
benesch added a commit to benesch/backtrace-rs that referenced this issue Jun 10, 2020
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 rust-lang#342.
benesch added a commit to benesch/backtrace-rs that referenced this issue Jun 10, 2020
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 rust-lang#342.
@alexcrichton alexcrichton added the gimli Related to the gimli implementation label Jun 10, 2020
benesch added a commit to benesch/backtrace-rs that referenced this issue Jun 10, 2020
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 rust-lang#342.
benesch added a commit to benesch/backtrace-rs that referenced this issue Jun 10, 2020
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 rust-lang#342.
benesch added a commit to benesch/backtrace-rs that referenced this issue Jun 11, 2020
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.
benesch added a commit to benesch/backtrace-rs that referenced this issue Jun 11, 2020
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.
alexcrichton pushed a commit that referenced this issue Jun 11, 2020
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 #342.
benesch added a commit to benesch/materialize that referenced this issue Jun 17, 2020
Switch over to the new Gimli-based backtrace symbolicator. Gimli is a
pure-Rust reimplementation of libbacktrace that will soon be the default
backtrace implementation in the Rust standard library [0]. Switching to
it now means we can help shake out problems, like [1], before it ships
in the standard library, where fixing problems will require a full six
week release cycle.

This switch has the side effect of fixing backtraces on macOS, which
seem to be broken at the moment because the backtrace crate is picking
libbacktrace over coresymbolication. There isn't a good way of fixing
that because Cargo doesn't support per-platform features [2]; using
neither libbacktrace or coresymbolicator is a kind of stupid but
effective way of sidestepping the problem.

[0]: rust-lang/rust#73441
[1]: rust-lang/backtrace-rs#342
[2]: rust-lang/cargo#1197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gimli Related to the gimli implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants