build: native build flags from #70 (asm, arch baseline, hardening)#71
Merged
Conversation
Drop -DZSTD_DISABLE_ASM=1 and include huf_decompress_amd64.S in the build. Its body is entirely wrapped in `#if ZSTD_ENABLE_ASM_X86_64_BMI2` (gated on __x86_64__), so it compiles to a no-op on every non-x86_64 classifier and only activates there via zstd's own runtime BMI2 detection — safe to always include. Verified it cross-compiles cleanly for all six classifiers. No measurable effect on this aarch64 host (confirmed byte-identical object code with/without the flag here), but linux-x86_64, osx-x86_64, and windows-x86_64 builds gain the hand-tuned asm decode path, matching what zstd's own Makefile enables by default. Ref #70
Add -mcpu=generic+crc for aarch64 classifiers (zig's syntax for the issue's -march=armv8-a+crc; clang's GCC-style -march= isn't accepted by zig's driver). "generic" keeps every aarch64 CPU supported, unlike pinning to e.g. apple_m1. Confirmed real codegen changes (compiled object sizes differ) and measurable throughput gains on this arm64 host: compress +6.9%, decompress +12-14% for our native path (zstdJavaBytes/zstdJavaSegment) in a quick JMH smoke run, with unaffected baselines (zstdJni, aircompressor) flat as a sanity check. Cross-compiles cleanly for all six classifiers; local unit + integration tests pass. Ref #70
Add -Wl,-z,relro,-z,now for linux-* classifiers: the GOT is remapped read-only once startup relocation completes, closing off the classic GOT-overwrite exploit primitive. ELF-only — -z is a GNU ld/lld concept with no Mach-O or PE equivalent, so osx-*/windows-* are unaffected. Not a throughput lever (eager symbol binding, not codec hot path), so verified directly instead of via benchmark: llvm-readelf confirms a GNU_RELRO program header and BIND_NOW/FLAGS_1 NOW on both linux-x86_64 and linux-aarch64. Cross-compiles cleanly for all six classifiers; local unit + integration tests pass. Ref #70
This was referenced Jul 17, 2026
dfa1
added a commit
that referenced
this pull request
Jul 17, 2026
Add -flto for linux-* classifiers only. zig's Mach-O backend is a
self-hosted linker with no LTO support ("error: LTO requires using
LLD" even at the -c compile stage) — confirmed no workaround exists
locally (no real ld64.lld available, zig cc doesn't expose a linker
toggle). ELF is different: zig 0.16 still links it through the
bundled real lld by default, and -flto compiles and links cleanly
when cross-compiled to x86_64-linux-gnu/aarch64-linux-gnu from this
host, with the full public API surface (verified via
llvm-readelf --dyn-syms) intact after LTO.
What isn't verified locally: whether the LTO-linked library is
actually correct at runtime — this Mac can't execute Linux ELF
binaries. zstd/pom.xml and integration-tests/pom.xml activate their
native-classifier profile by host OS/arch, so ci.yml's ubuntu-latest
job will natively build and test-run exactly the linux-x86_64
classifier this touches. Marking this experimental pending that
signal, rather than folding it into #71 (asm/arch/hardening), which
only contains changes verified end-to-end on this host.
osx-*/windows-* classifiers are untouched (LTO_FLAG stays empty);
confirmed unaffected locally (rebuilt + zstd/integration-tests suite
passes on osx-aarch64, all six classifiers still cross-compile).
Ref #70
dfa1
added a commit
that referenced
this pull request
Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three flags from #70, each landed and verified independently:
3a4c32b): drop-DZSTD_DISABLE_ASM=1, includehuf_decompress_amd64.S. Its body is entirely wrapped in#if ZSTD_ENABLE_ASM_X86_64_BMI2(gated on__x86_64__), so it's a no-op on non-x86_64 targets and activates via zstd's own runtime BMI2 detection where it matters. Confirmed byte-identical object code on this arm64 host; benefitslinux-x86_64/osx-x86_64/windows-x86_64.6b9e622):-mcpu=generic+crc(zig's syntax for the issue's-march=armv8-a+crc). Measured on this host with a quick JMH smoke run: compress +6.9%, decompress +12-14% for our native path, with unaffected baselines (zstdJni,aircompressor) flat as a sanity check.a55266c):-Wl,-z,relro,-z,now, ELF-only. Not a throughput lever, so verified directly withllvm-readelf(GNU_RELROsegment +BIND_NOW) rather than benchmarked.Not landed: LTO (
-flto) — zig's Mach-O backend is a self-hosted linker with no LTO support (error: LTO requires using LLD), confirmed with no local workaround (nold64.lldavailable, no Docker to validate the Linux/Windows side where zig's bundled lld does support it). Left for follow-up if a real LLD Mach-O linker becomes available.Test plan
./mvnw -q validate(checkstyle) clean./mvnw -q -pl zstd,integration-tests -am testpasses on osx-aarch64 (golden-corpus interop included)osx-aarch64,osx-x86_64,linux-x86_64,linux-aarch64,windows-x86_64,windows-aarch64) cross-compile cleanly withzig ccllvm-readelfconfirmsGNU_RELRO/BIND_NOWon both Linux classifiers🤖 Generated with Claude Code