bazelbuild / bazelbuild/rules_rust

Conditionally export `libprofiler_builtins` from `rust_library` CcInfo

Open
#4,178 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

**Is your feature request related to a problem? Please describe.**

A C++ executable built with Clang PGO can depend on an uninstrumented
`rust_library`. Today that Rust target unconditionally propagates the Rust
toolchain's `libprofiler_builtins` through `CcInfo`. The archive can appear
before Clang's driver-provided `libclang_rt.profile.a` and satisfy the same
`__llvm_profile_*` symbols first.

If rustc and Clang use different LLVM profile ABIs, the resulting executable
links successfully but uses a runtime that cannot interpret the C++
instrumentation data and very likely crashes on startup.

Our concrete configuration is:

- `rules_rust` 0.70.0; current upstream has the same propagation behavior
- Rust 1.91.0 using LLVM 21.1.2
- Clang 23
- C++ compiled with `-fprofile-generate`
- Rust dependencies intentionally not PGO-instrumented

`rust_stdlib_filegroup` places `libprofiler_builtins-*.rlib` in
`between_core_and_std_files`. `make_libstd_and_allocator_ccinfo` exports every
archive in that collection, and `establish_cc_info` attaches the resulting
standard-library `CcInfo` to `rust_library` targets.

The final link is effectively ordered as follows:

```text
libprofiler_builtins-.rlib
...
-u__llvm_profile_runtime
libclang_rt.profile.a
```

Because static archives are extracted lazily, Rust's LLVM 21 runtime satisfies
the profile symbols and Clang 23's runtime is not extracted.

This issue has already been described in other semi-related issues like: https://github.com/bazelbuild/rules_rust/pull/1324#issuecomment-1120291490

**Describe the solution you'd like**

An uninstrumented `rust_library` should not export `libprofiler_builtins`
through `CcInfo`.

**Describe alternatives you've considered**
Hacking around on our side.

**Additional context**

Contributor guide

Open the contributing guide

Research direction

Trace rust_stdlib_filegroup, make_libstd_and_allocator_ccinfo, and establish_cc_info to see how libprofiler_builtins-*.rlib enters the standard-library CcInfo for rust_library targets. Reproduce or inspect the Clang PGO link scenario, then verify that an uninstrumented rust_library no longer exports libprofiler_builtins while other standard-library archives remain available.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.