Skip to content

[core][build] Drop -Wl,-pie from vendored RocksDB WITH_TSAN link flags - #64917

Merged
elliot-barn merged 1 commit into
masterfrom
elliot-barn/rocksdb-tsan-no-pie
Jul 22, 2026
Merged

elliot-barn merged 1 commit into
masterfrom
elliot-barn/rocksdb-tsan-no-pie

Conversation

@elliot-barn

@elliot-barn elliot-barn commented Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Why are these changes needed?

The postmerge :ray: core: cpp tsan tests job has been red since #64759 (Jul 16). #64759 enabled WITH_TSAN=ON for the vendored RocksDB build (via --define=ray_rocksdb_tsan=true on --config=tsan) to get a TSan-instrumented librocksdb.a. However, RocksDB's WITH_TSAN block (CMakeLists.txt:373-378 in v10.6.2) does:

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -Wl,-pie")

-Wl,-pie passes -pie directly to the linker behind the compiler driver's back. Under the rules_foreign_cc crosstool (clang + static libc++ via BAZEL_LINKLIBS=-l%:libc++.a:-l%:libc++abi.a), the driver still emits non-PIE startup objects, so every CMake try_compile probe fails to link. Configure then aborts at the first REQUIRED check:

CMake Error at .../FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
  ...
  CMakeLists.txt:639 (find_package)

and six rocksdb-dependent test targets fail to build (rocksdb_store_client_test, rocksdb_concurrency_test, rocksdb_parity_test, rocksdb_smoke_test, gcs_client_reconnection_test, global_state_accessor_test). Every postmerge build since #64759 shows this failure (e.g. builds 18631, 18643, ... 18717); it wasn't caught premerge because the tsan job only runs postmerge.

The tell in the configure log is that checks before the WITH_TSAN block (HAVE_OMIT_LEAF_FRAME_POINTER, BUILTIN_ATOMIC) pass, while every check after it fails — including trivial ones like Looking for pthread.h - not found.

Fix

Patch the vendored RocksDB archive to drop -Wl,-pie from the WITH_TSAN linker flags. -fsanitize=thread is kept in both compile and link flags, so the library is still fully TSan-instrumented (the original goal of #64759). TSan does not require PIE with modern clang/gcc on x86_64/aarch64 Linux; when a driver does need PIE it adds it itself via -fsanitize=thread at link time.

This only affects the WITH_TSAN=ON path (--config=tsan); regular builds use the non-TSAN cache entries and are untouched.

Related issue number

N/A — no issue filed for the postmerge breakage; this PR documents it. Root-caused from postmerge build logs (18631/18643/18717) and anyscale/rayturbo build 13564 which inherited the failure.

Checks

  • Duplicate-work check: searched open PRs/issues for tsan/rocksdb — the most recent related change is [core][build] Fix TSAN false-positive data races in RocksDB GCS backend #64759 itself; no open PR addresses this configure failure.

  • AI assistance was used to root-cause the CI failure and draft this change; a human (submitter) reviewed every line.

  • Local validation:

    • patch -p1 applies cleanly to pristine rocksdb v10.6.2.
    • bazel build @com_github_facebook_rocksdb//:rocksdb --define=ray_rocksdb_tsan=true — with the patch, CMake configure proceeds past find_package(Threads) and the TSan-instrumented librocksdb.a builds (validated on Linux x86_64 with the gcc host toolchain; the exact CI failure mode is clang+static-libc++-specific — gcc defaults to PIE so -Wl,-pie is benign there — so the postmerge-config tsan CI job is the authoritative check).
    • The unpatched failure is reproduced by every postmerge tsan run since Jul 16 (identical Could NOT find Threads at CMakeLists.txt:639).
  • I've run scripts/format.sh to lint the changes in this PR.

  • I've included any doc changes needed for https://docs.ray.io/en/master/.

  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/

  • Testing Strategy

    • Unit tests (existing cpp tsan test targets; this PR unblocks their build)
    • Release tests
    • This PR is not tested :(

🤖 Generated with Claude Code

Postmerge run: https://buildkite.com/ray-project/postmerge/builds/18725/canvas

The postmerge cpp tsan job has been failing since #64759 enabled
WITH_TSAN=ON for the vendored RocksDB. RocksDB's WITH_TSAN block appends
-Wl,-pie to CMAKE_EXE_LINKER_FLAGS, passing -pie to the linker behind
the compiler driver's back. Under the rules_foreign_cc crosstool
(clang + static libc++), the driver still emits non-PIE startup objects,
so every CMake try_compile probe fails to link and configure aborts at
find_package(Threads REQUIRED), breaking the build of all
rocksdb-dependent test targets.

Patch the vendored archive to drop -Wl,-pie. -fsanitize=thread is kept
in compile and link flags, so librocksdb.a remains TSan-instrumented.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
@elliot-barn
elliot-barn requested review from a team as code owners July 21, 2026 23:50

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a patch to the RocksDB dependency in bazel/ray_deps_setup.bzl to resolve a build configuration issue when compiling with ThreadSanitizer (TSan). Specifically, the patch removes the -Wl,-pie flag from CMAKE_EXE_LINKER_FLAGS in RocksDB's CMake configuration, which previously caused CMake's try_compile checks to fail under the rules_foreign_cc toolchain. There are no review comments, and I have no feedback to provide.

@elliot-barn

Copy link
Copy Markdown
Collaborator Author

Local validation completed: bazel build @com_github_facebook_rocksdb//:rocksdb --define=ray_rocksdb_tsan=true with this patch — CMake configure proceeds past find_package(Threads) (the exact point where postmerge fails) and the build produces librocksdb.a with 4,644 __tsan_* references, confirming the library remains fully TSan-instrumented with -Wl,-pie removed. (Host gcc toolchain; the clang+static-libc++ CI config is still the authoritative check — the cpp tsan job is behind the "run cpp sanitizer tests" block step and needs a manual unblock on this PR's premerge build.)

@edoakes edoakes added the go add ONLY when ready to merge, run all tests label Jul 22, 2026
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Jul 22, 2026
@elliot-barn
elliot-barn enabled auto-merge (squash) July 22, 2026 01:39
@elliot-barn
elliot-barn merged commit 9ec3757 into master Jul 22, 2026
5 checks passed
@elliot-barn
elliot-barn deleted the elliot-barn/rocksdb-tsan-no-pie branch July 22, 2026 03:41
elliot-barn added a commit that referenced this pull request Jul 23, 2026
…B WITH_TSAN link flags (#64917) (#64937)

Cherry-pick of #64917 (9ec3757) onto
`releases/2.57.0`. Clean cherry-pick, no conflicts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: elliot-barn <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
ray-project#64917)

## Why are these changes needed?

The postmerge `:ray: core: cpp tsan tests` job has been red since ray-project#64759
(Jul 16). ray-project#64759 enabled `WITH_TSAN=ON` for the vendored RocksDB build
(via `--define=ray_rocksdb_tsan=true` on `--config=tsan`) to get a
TSan-instrumented `librocksdb.a`. However, RocksDB's `WITH_TSAN` block
(CMakeLists.txt:373-378 in v10.6.2) does:

```cmake
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -Wl,-pie")
```

`-Wl,-pie` passes `-pie` directly to the linker behind the compiler
driver's back. Under the rules_foreign_cc crosstool (clang + static
libc++ via `BAZEL_LINKLIBS=-l%:libc++.a:-l%:libc++abi.a`), the driver
still emits non-PIE startup objects, so **every CMake `try_compile`
probe fails to link**. Configure then aborts at the first `REQUIRED`
check:

```
CMake Error at .../FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
  ...
  CMakeLists.txt:639 (find_package)
```

and six rocksdb-dependent test targets fail to build
(`rocksdb_store_client_test`, `rocksdb_concurrency_test`,
`rocksdb_parity_test`, `rocksdb_smoke_test`,
`gcs_client_reconnection_test`, `global_state_accessor_test`). Every
postmerge build since ray-project#64759 shows this failure (e.g. builds 18631,
18643, ... 18717); it wasn't caught premerge because the tsan job only
runs postmerge.

The tell in the configure log is that checks *before* the `WITH_TSAN`
block (`HAVE_OMIT_LEAF_FRAME_POINTER`, `BUILTIN_ATOMIC`) pass, while
every check *after* it fails — including trivial ones like `Looking for
pthread.h - not found`.

### Fix

Patch the vendored RocksDB archive to drop ` -Wl,-pie` from the
`WITH_TSAN` linker flags. `-fsanitize=thread` is kept in both compile
and link flags, so the library is still fully TSan-instrumented (the
original goal of ray-project#64759). TSan does not require PIE with modern
clang/gcc on x86_64/aarch64 Linux; when a driver does need PIE it adds
it itself via `-fsanitize=thread` at link time.

This only affects the `WITH_TSAN=ON` path (`--config=tsan`); regular
builds use the non-TSAN cache entries and are untouched.

## Related issue number

N/A — no issue filed for the postmerge breakage; this PR documents it.
Root-caused from postmerge build logs (18631/18643/18717) and
anyscale/rayturbo build 13564 which inherited the failure.

## Checks

- Duplicate-work check: searched open PRs/issues for `tsan`/`rocksdb` —
the most recent related change is ray-project#64759 itself; no open PR addresses
this configure failure.
- AI assistance was used to root-cause the CI failure and draft this
change; a human (submitter) reviewed every line.
- Local validation:
  - `patch -p1` applies cleanly to pristine rocksdb v10.6.2.
- `bazel build @com_github_facebook_rocksdb//:rocksdb
--define=ray_rocksdb_tsan=true` — with the patch, CMake configure
proceeds past `find_package(Threads)` and the TSan-instrumented
`librocksdb.a` builds (validated on Linux x86_64 with the gcc host
toolchain; the exact CI failure mode is clang+static-libc++-specific —
gcc defaults to PIE so `-Wl,-pie` is benign there — so the
postmerge-config tsan CI job is the authoritative check).
- The unpatched failure is reproduced by every postmerge tsan run since
Jul 16 (identical `Could NOT find Threads` at CMakeLists.txt:639).

- [ ] I've run scripts/format.sh to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [x] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
- [x] Unit tests (existing cpp tsan test targets; this PR unblocks their
build)
   - [ ] Release tests
   - [ ] This PR is not tested :(

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Postmerge run:
https://buildkite.com/ray-project/postmerge/builds/18725/canvas

Signed-off-by: elliot-barn <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
Signed-off-by: 400Ping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants