rust-lang / rust-lang/rust

-Clinker-plugin-opt should propagate external linkage + default visibility symbols to the `MustPreserveSymbols` retained by LTO

Open
#159,683 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

(Summarized from https://g-issues.fuchsia.dev/issues/529449843)

When creating a shared library that contains a mix of LTO'd an non-LTO'd code, it's possible for rust to not retain symbols from the non-LTO'd code which should be retained since we expect to export them from the shared library. This occurs specifically when using -Clinker-plugin-opt. The scenario is LTO will remove some code in the LTO'd bitcode which would call some function in the non-LTO'd code. Now the LTO'd bitcode has no reference to that function, so it's okay to not extract that symbol from the non-LTO'd rlib. When rustc drives the link (ie. without -Clinker-plugin-lto), rustc populates the MustPreserveSymbols which forces these symbols to be retained anyway.

While we can circumvent this by just not using -Clinker-plugin-lto, this prevents a bunch of cross-language optimizations which we'd like. It seems like the right thing to do is have rust somehow propagate this information to LLD when it drives the link. Not sure of what the machinery for doing that would look like though.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how -Clinker-plugin-opt handles MustPreserveSymbols when linking a shared library with mixed LTO and non-LTO code. Reproduce the symbol-retention failure described in the issue and compare it with rustc-driven linking without -Clinker-plugin-lto. Done means the external-linkage and default-visibility symbols are propagated so LLD retains them.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.