Skip to content

Conditionally export libprofiler_builtins from rust_library CcInfo #4178

Description

@StephanDollberg

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:

libprofiler_builtins-<hash>.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: #1324 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions