Skip to content

ppc64le: bundled libunwind unw_getcontext leaves callee-saved vector registers byte-swapped (fixed in LLVM main, not backported) #127366

Closed

Description

@jsc0218

On little-endian ppc64le, unw_getcontext in contrib/llvm-project/libunwind/src/UnwindRegistersSave.S
corrupts the caller's callee-saved vector registers. PPC64_STVS(n) does
xxswapd n,n; stxvd2x n,0,4 and never swaps back, so v20-v31 and f14-f31 come back
byte-swapped.

Fixed in LLVM main: llvm/llvm-project@6b0a46958c (#198371, 2026-07-25).
Not in the LLVM release/21.x, 22.x or 23.x branches, nor in ClickHouse/llvm-project
(release-22.x, clickhouse1, or the pin used by master, daf4510c). The fix is one line:
a second xxswapd n, n after the store.

Effect we saw: ClickHouse v26.8.15.10-lts cross-compiled for ppc64le (clang-22, -O3,
-mcpu=power8) failed to start in about 10-19% of runs under qemu-user: an SLP-vectorized
constant held in v28 across a stack-trace capture in SystemLogs::SystemLogs came back
swapped, a string header was read as empty, and start failed with UNKNOWN_TABLE
("Both table name and UUID are empty"). Not tested on native ppc64le hardware.

Evidence (same harness, qemu 8.2.2):

  • ClickHouse's UnwindRegistersSave.S in isolation: 12/12 callee-saved vector registers
    corrupted; 0/12 with the fix.
  • 120 server starts: 14 failures unpatched, 0 patched. Our CI smoke step passed 22/22
    with the patch applied.

Proposed fix: backport 6b0a46958c to ClickHouse/llvm-project release-22.x (the branch master
tracks), then bump contrib/llvm-project. The backport is a clean cherry-pick (+4 lines,
identical to upstream): ClickHouse/llvm-project#142

Version info

Activity

  1. added
    comp-external-dependencies
    on Oct 22, 2026
  2. jsc0218 commented on Oct 23, 2026

    @jsc0218
    ContributorAuthor

    Follow-up on why this went unnoticed: ClickHouse CI builds ppc64le (BuildTypes.PPC64LE in
    ci/defs/job_configs.py, cross-compiled) but I could not find a job that runs the resulting
    binary, so a bug that only shows at runtime on ppc64le would not be caught. We hit it
    because our packaging pipeline starts the ppc64le server under qemu-user; there it failed
    in about 10-19% of starts before we patched libunwind.

    A cheap guard would be a QEMU smoke start of the ppc64le build, or a small test that calls
    unw_getcontext and checks v20-v31 are unchanged. The standalone check we used is: load known
    values into v20-v31, call __unw_getcontext, read them back, compare (12/12 corrupted
    without the fix, 0/12 with it). I can share it if useful.

    I may have missed a ppc64le test job in the CI definitions; corrections welcome.

  3. added
    external
    on Oct 23, 2026
  4. PedroTadim commented on Oct 26, 2026

    @PedroTadim
    Member

    Releases before 26.3 are no longer supported

  5. jsc0218 commented on Nov 5, 2026

    @jsc0218
    ContributorAuthor

    @groeneai Please review this issue against current master. Confirm whether contrib/llvm-project (the pin master uses) still lacks llvm/llvm-project@6b0a46958c, and whether the cherry-pick in ClickHouse/llvm-project#142 is the right fix. Also say whether CI has any job that runs the ppc64le binary (not just builds it).

  6. groeneai commented on Nov 5, 2026

    @groeneai
    Collaborator

    I checked this against current master (bc84b09d).

    1. Master still lacks the fix. contrib/llvm-project is pinned at fa3910d6, which is the current tip of ClickHouse/release-22.x (compare: identical). Its libunwind/src/UnwindRegistersSave.S still has the LE PPC64_STVS as xxswapd n, n; stxvd2x n, 0, 4 with no swap back. The ppc64le build uses -mcpu=power8 (cmake/cpu_features.cmake), so this __VSX__ + __LITTLE_ENDIAN__ path is the one compiled. ClickHouse/release-23.x (5a736e6e), where Use clang-23 #117346 (Use clang-23) moves the pin, lacks it too.

    2. [libunwind][PPC64] Backport: fix unw_getcontext corrupting callee-saved VSX registers on LE llvm-project#142 looks like the right fix. Its diff is identical to upstream 6b0a46958c (one xxswapd n, n after the store, plus the comment). Its base is ClickHouse/release-22.x, the branch master's pin tracks; the branch has moved since only by [msan] Keep the stack when an async signal arrives during a report llvm-project#118, which master already pins, so a bump after merging it would carry nothing else. The restore side needs no change: PPC64_LVS and PPC64_CLVS_RESTORE swap the register right after loading it, which is correct, and PPC64_STVS is the only in-place swap in the save file.
      I reproduced it independently: I assembled UnwindRegistersSave.S with clang-22 (--target=powerpc64le-linux-gnu -mcpu=power8) and called __unw_getcontext from a harness that loads known values into v20-v31 and f14-f31, under qemu-ppc64le with -cpu power8, power9 and power10. At the master pin, 12/12 vector registers and 18/18 FPRs differ after the call; with the file from jsonRowOutputStream compile error #142, 0/12 and 0/18. The VS save area written to the context is byte-identical in both, so the fix changes only the live registers, not what the unwinder reads.
      Merging jsonRowOutputStream compile error #142 and bumping the submodule is a maintainer's call; if master moves to release-23.x, the same cherry-pick is needed there.

    3. No CI job runs the ppc64le binary. On master, BuildTypes.PPC64LE is only a parameter of the special build job in ci/defs/job_configs.py (cross-compiled on an ARM runner, -DENABLE_TESTS=0, provides=[ArtifactNames.CH_PPC64LE]). No job in ci/defs/job_configs.py or ci/workflows/*.py consumes CH_PPC64LE; its only other use is build_master_head_hook.py, which uploads master builds to the powerpc64le static location. The only post-build execution in ci/jobs/build_clickhouse.py is the wasm64 clickhouse local smoke under Node.js, with nothing equivalent for ppc64le, so a runtime-only ppc64le bug like this one is not caught by CI.

  7. PedroTadim commented on Nov 6, 2026

    @PedroTadim
    Member

    @jsc0218 you can now create the bump PR for the submodule

  8. jsc0218 commented on Nov 10, 2026

    @jsc0218
    ContributorAuthor

    @PedroTadim I bumped here #129808, thanks for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai_p2comp-external-dependenciesexternal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions