[llvm] [LLVM] Add zstd compressed frame magic to LLVM magic (PR #222773)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 01:03:53 PDT 2026


https://github.com/jh7370 commented:

Personally, I think this makes sense in general, but we should probably do zlib as well as zstd, so that consumers can identify either (assuming zlib has unambiguous magic anyway).

I don't really agree with @MaskRay's reasoning that this doesn't belong in `identify_magic` in the general case. Consider the hypothetical example where we want to support objects that have been fully compressed in llvm-readobj without knowing up front that they are: we'd spot the zstd magic and then decompress it before re-identifying the decompressed stream. We wouldn't need to do extra work up front to determine "is it compressed or not". Equally, tools already have to handle objects that they don't support, so it's not impacting other consumers.

That being said, I'm not convinced that the subsequent usage in the next PR is the correct approach, since it isn't doing this - it already knows the stream is a compressed stream. In fact, the downstream PR would treat any identified-by-LLVM object as a zlib stream (except for zstd), which is clearly nonsense if it was e.g. an ELF object, and could produce surprising failures if a new compression type was added later without this block of code being handled. If the stream is already supposed to be a compressed stream, it should be fed to a function that decompresses a stream of any type and returns an error if it isn't available/a known type. This would internally use a switch that covers the known compression types within LLVM (possibly even `identify_magic`, but that's debatable). A quick search shows that the clang AST reader already does precisely this. Moving that code into Compression.cpp would obviously be needed.

https://github.com/llvm/llvm-project/pull/222773


More information about the llvm-commits mailing list