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

Support zstd-compressed ELF sections. #626

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

khuey
Copy link
Contributor

@khuey khuey commented May 25, 2024

zstd has been introduced as an alternative to zlib for the compression of debug sections.[0] Toolchain support is widely present at this time but lack of support in backtrace is a severe limitation on using this feature in Rust programs.

This uses a Rust reimplementation of zstd (the ruzstd crate). This has the benefit of simplifying the build process, but this crate is less used and admittedly slower than the zstd crate that binds to the C libzstd.

[0] https://maskray.me/blog/2022-09-09-zstd-compressed-debug-sections

@workingjubilee
Copy link
Contributor

workingjubilee commented May 27, 2024

This itself will also wait for a bit due to dependency chains. I would rather not have two syns in my dependency tree, so I will be waiting for a version with KillingSpark/zstd-rs#60

@bjorn3
Copy link
Member

bjorn3 commented May 27, 2024

It also needs rustc-dep-of-std support, right?

@workingjubilee
Copy link
Contributor

hmm probably.

Comment on lines 100 to 99
- run: cargo test
if: contains(matrix.os, 'ubuntu-24.04')
env:
RUSTFLAGS: "-C link-arg=-Wl,--compress-debug-sections=zstd"
Copy link
Contributor

Choose a reason for hiding this comment

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

see #627

Comment on lines +25 to +30
- os: ubuntu-24.04
rust: stable
- os: ubuntu-24.04
rust: beta
- os: ubuntu-24.04
rust: nightly
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, why are we bumping this? I kinda think we should just bump ahead to a recent ubuntu if we gotta?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

--compress-debug-sections=zstd is only available in the binutils/etc that ships with 24.04, not with 20.04 or 22.04.

Copy link
Contributor

Choose a reason for hiding this comment

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

And no chance of installing that stuff on ubuntu 20 without exploding the world, huh?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would be scared to try :)

If rust-lld propagates out to the stable branches I think it'll just work there though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh cool. Can you give that a whirl against our CI for nightly + ubuntu 20.04, then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like that's rust-lang/rust#120953

Copy link
Contributor

Choose a reason for hiding this comment

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

huh.

Copy link
Contributor

@workingjubilee workingjubilee May 28, 2024

Choose a reason for hiding this comment

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

...wait, can we just install lld and test with that or something? (not sure if that actually works out with all the versions involved...)

Copy link
Contributor

Choose a reason for hiding this comment

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

rust-lang/rust#125642 is also good lmao.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to rust-lang/rust#124129 we can just use -Zlinker-features=-lld but I feel like rust-lld should be fixed.

Comment on lines +57 to +60
# Starting with Ubuntu 22.04 libc6-dbg is needed.
- name: Install libc debug info
run: sudo apt-get install -y libc6-dbg
shell: bash
Copy link
Contributor

Choose a reason for hiding this comment

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

which would make this unconditional.

Comment on lines +184 to +197
match header.ch_type(self.endian) {
ELFCOMPRESS_ZLIB => {
let size = usize::try_from(header.ch_size(self.endian)).ok()?;
let buf = stash.allocate(size);
decompress_zlib(data.0, buf)?;
return Some(buf);
}
ELFCOMPRESS_ZSTD => {
let size = usize::try_from(header.ch_size(self.endian)).ok()?;
let buf = stash.allocate(size);
decompress_zstd(data.0, buf)?;
return Some(buf);
}
_ => return None, // Unknown compression type.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the actual implementation seems basically fine.

@workingjubilee
Copy link
Contributor

It's also ever-so-slightly nicer to be able to submit PRs to a Rust crate if I want their code to operate differently somehow (run faster, jump higher, whatever) rather than have to also dive into a tangled pile of C, y'know?

@khuey
Copy link
Contributor Author

khuey commented May 28, 2024

It's also ever-so-slightly nicer to be able to submit PRs to a Rust crate if I want their code to operate differently somehow (run faster, jump higher, whatever) rather than have to also dive into a tangled pile of C, y'know?

Personally I'd take the dependency that's professionally maintained and used by everyone else on the planet but it's not my crate.

@workingjubilee
Copy link
Contributor

Alas, no one is really paying for professional maintenance of backtrace-rs, unfortunately.

khuey added 2 commits May 27, 2024 19:36
zstd has been introduced as an alternative to zlib for the compression of debug
sections.[0] Toolchain support is widely present at this time but lack of
support in backtrace is a severe limitation on using this feature in Rust
programs.

This uses a Rust reimplementation of zstd (the ruzstd crate). This has the
benefit of simplifying the build process, but this crate is less used and
admittedly slower than the zstd crate that binds to the C libzstd.

[0] https://maskray.me/blog/2022-09-09-zstd-compressed-debug-sections
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

3 participants