Repository navigation
Pin the CPU baseline of all natives; align branches for the Intel JCC erratum - #187
Merged
Merged
Conversation
The amd64 and i386 natives were built without -march, so the CPU baseline was whatever the runner's GCC defaults to. Since ubuntu-latest moved to Ubuntu 26.04, whose GCC defaults to x86-64-v3, liblz4-java.so for amd64 contains AVX2/BMI2/LZCNT/MOVBE instructions and crashes with SIGILL on CPUs without them. Set -march=x86-64 (amd64) and -march=i686 (i386) explicitly, and fail the build if the library contains AVX, BMI or MOVBE instructions. Fixes #186 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pass -Wa,-mbranches-within-32B-boundaries for amd64 and i386, as upstream lz4 does by default since 1.11 (JCC_FLAGS / LZ4_JCC_ERRATUM / jcc-erratum in its Make, CMake and Meson builds). The microcode fix for the erratum makes branches that cross or end on a 32-byte boundary slow on Skylake-family Intel CPUs; the assembler pads code to avoid that. On an i9-10920X (Cascade Lake), with 64 KiB blocks of the Calgary corpus and of the lz4 source tree: fast compression +10-14%, HC9 compression +6-8%, decompress_safe +16-20%, xxhash unchanged. Upstream reports no change on AMD Zen 4/5 and Intel Lunar Lake. -O3 was measured too and made decompression ~10% slower, so the natives stay at -O2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ubuntu 26.04's cross compilers default to z15 (s390x) and RVA23 (riscv64), so the 1.13.0 natives for those also require newer CPUs than 1.12.0 did (z13, rv64gc). Its libgcc and CRT objects are built for the same baselines and get linked into the library even with -march set (e.g. Zbb rev8 in __bswapdi2 on riscv64), so build the Linux natives on ubuntu-24.04 and set the baseline explicitly for each arch at the level 1.12.0 had: armv8-a, power9, z13, rv64gc. Extend the baseline check to s390x (z14/z15 mnemonics) and riscv64 (Tag_RISCV_arch), and fix the mnemonic extraction for objdump targets that put a tab between mnemonic and operands, which hid s390x hits. Apply the JCC erratum mitigation to macOS x86_64 (clang: +14-26% decompression, +4-10% compression on Cascade Lake, -O3 kept as it is faster than -O2 with clang) and Windows, where -O2 replaces the profile's -O3 as with GCC on Linux. Windows also gets an explicit x86-64 baseline and the instruction check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Building on ubuntu-24.04 only postpones the problem: the toolchain's compiler defaults, libgcc and CRT objects decide the baseline, and Ubuntu 26.04 raised them. Build in a digest-pinned debian:trixie container on ubuntu-latest instead. Debian keeps x86-64, i686, armv8-a, POWER8, z196 and rv64gc, and its libgcc/CRT objects are built for those; Renovate updates the digest and the baseline check guards release bumps. Lower ppc64le from POWER9 to POWER8, which Debian, RHEL 8 and OpenJDK support, and check for POWER9 (ISA 3.0) mnemonics. 1.12.0 and 1.13.0 both already required POWER9. Make the baseline check fail if objdump/readelf fail, and use bash, which is not the default shell in container jobs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The -march/-mcpu baseline and the JCC erratum alignment were only set in the release workflow, so the PR test workflow and local builds compiled different code than what ships. Set them per arch.id in the native-linux, native-macos and native-windows profiles (native.arch.cflags, before native.cflags, overridable with -Dnative.arch.cflags), and build Windows with -O2 in the profile instead of overriding its -O3 from CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the inline per-job baseline checks and the inline architecture check with scripts/check_natives.py, run once on the collected natives that go into the jar. Besides the format of each expected library it checks: - instructions above the baseline of every arch, now including x86-64-v2 and SSE3 (amd64, Windows), any MMX/SSE (i386), SSE4.1+ (macOS x86_64), Armv8.1+ and SVE (aarch64), POWER9/POWER10, z14-z16 vector enhancements, and an rv64gc allowlist for Tag_RISCV_arch; - glibc symbol versions (at most 2.17, 2.27 on riscv64) and DT_NEEDED; - minimum macOS version and dylibs, imported Windows DLLs. It can also be run on a jar. On the published jars it flags the 1.13.0 amd64, s390x, riscv64 and ppc64le libraries, the 1.12.0 ppc64le library, and SSE3 in the 1.12.0 and 1.13.0 Windows DLLs (MinGW-Builds defaults to nocona). The Linux container installs the native gcc only for amd64/i386, runs apt non-interactively and retries downloads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- pom.xml: GCC only takes -Wa,-mbranches-within-32B-boundaries and clang only the driver option, so the hard-coded GCC spelling broke clang builds (the fuzz profile) on x86, and the macOS spelling GCC builds. Probe both against native.cc in each profile like upstream lz4 does, falling back to none. - check_natives.py: skip the jump tables clang puts into __text on macOS x86_64 (found through RIP-relative lea), which were decoded as junk instructions; report libraries anywhere under the root, not only at <os>/<arch>/; pin the glibc limits to what the libraries need today; add --targets and an --expect-failing self-test mode; find a versioned llvm-objdump-<N>. - test.yml: check the native library each test job builds, and self-test the script against the published 1.13.0 jar. - Install llvm in the assemble job only if no llvm-objdump is present. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #186.
Since 1.13.0 the natives are built on Ubuntu 26.04 (
ubuntu-latest). On 26.04 both the compiler defaults and the prebuiltlibgcc/CRT objects linked into the library target newer CPUs than before, so some 1.13.0/1.14.0 natives crash with SIGILL on older CPUs:glibc symbol requirements (at most GLIBC_2.27 on riscv64), macOS minimum versions and Windows DLL imports are unchanged.
Toolchain: Debian stable instead of the runner's Ubuntu
-marchalone is not enough, because the toolchain'slibgccand CRT objects end up in the.so. For example, on 26.04 riscv64 calls__bswapdi2/__ctzdi2from alibgccbuilt with Zbb (rev8).The Linux natives are now built on
ubuntu-latestinside a digest-pinneddebian:trixiecontainer:libgcc/CRT objects are built for them.Container-specific fixes:
bashis set as the default shell, since it isn't the default in containers.setup-java'stoolchains.xmlexplicitly, because the container's$HOMEis not Maven'suser.home.Baselines and
scripts/check_natives.pyThe baseline flags now live in the
pom.xmlnative profiles (native.arch.cflags, keyed onarch.id), so the PR test workflow and local builds compile the same code that ships. They come beforenative.cflags, and-Dnative.arch.cflags=overrides them.-march=x86-64 -mtune=generic,-march=i686 -mtune=generic,-march=armv8-a,-mcpu=power8,-march=z13,-march=rv64gc -mabi=lp64d.-march=x86-64 -mtune=generic. MinGW-Builds GCC defaults tonocona, so the 1.12.0 and 1.13.0 DLLs contained SSE3 (movddup).ppc64le moves from POWER9 down to POWER8, which Debian, RHEL 8 and OpenJDK support. 1.12.0 already required POWER9.
scripts/check_natives.pyruns once in the assemble job on the collected natives, and can also be run on a jar. It replaces the previous inlinefile-based architecture check. It checks:Tag_RISCV_arch;libc/ld.soare needed, and no glibc symbol version newer than 2.17 (2.27 on riscv64);libSystemis needed;It uses
binutils-multiarch, plusllvm-objdumpfor Mach-O. Run on the published jars, it flags:JCC erratum alignment
Adds (in the profiles)
-Wa,-mbranches-within-32B-boundaries(-mbranches-within-32B-boundarieswith clang) for Linux amd64/i386, macOS x86_64 and Windows. Upstream lz4 enables this by default since 1.11.Measured on an i9-10920X (Cascade Lake), 64 KiB blocks, median of 5 interleaved runs:
-O2+ JCC-O3+ JCCdecompress_safe-O3made GCC decompression ~10% slower, so:-O2.-O3to-O2.-O3, which is faster than-O2there.Testing
scripts/check_natives.pyin the assemble job (run). Every Linux library reportsGCC: (Debian 14.2.0-19).SandyBridgerv64without V/Zba/Zbb/Zbs/Zbc/Zicondpower8pentium3/cortex-a53s390x can't be tested this way, because QEMU 8.2's TCG doesn't enforce the z14/z15 facilities. The static check covers it.
Not covered
🤖 Generated with Claude Code