Skip to content

Avoid unused unwindlib flag in rustc links - #38

Open
pdeva wants to merge 4 commits into
hermeticbuild:mainfrom
pdeva:pdeva/skip-unused-unwindlib-for-rustc-link
Open

Avoid unused unwindlib flag in rustc links#38
pdeva wants to merge 4 commits into
hermeticbuild:mainfrom
pdeva:pdeva/skip-unused-unwindlib-for-rustc-link

Conversation

@pdeva

@pdeva pdeva commented Aug 7, 2026

Copy link
Copy Markdown

Summary

  • stop forwarding Clang's -unwindlib=none / --unwindlib=none arguments through rustc when rustc disables the linker's default libraries
  • preserve both spellings when the effective rustc flags enable default linker libraries
  • preserve them conservatively when opaque Args or @response-file contents leave the effective setting unknown
  • preserve every other C++ linker-driver argument

Root cause

rules_rust asks Bazel's C++ toolchain for its executable-link command line and forwards those arguments to rustc as -C link-arg. Hermetic Clang toolchains can include an unwind-library selection in that command line.

By default, rustc invokes a compiler driver with -nodefaultlibs and supplies the Rust runtime and unwind library explicitly. Clang therefore cannot act on -unwindlib=none or --unwindlib=none and correctly reports an unused-command-line warning.

Rust 1.97's linker_messages lint surfaces successful-link stderr as a Rust warning, so the redundant toolchain argument became visible across every Rust binary and test link. See rust-lang/rust#136096 for the linker-message behavior.

Conditional behavior

Targets can opt back into compiler-driver defaults with bare -Cdefault-linker-libraries or an affirmative value such as -Cdefault-linker-libraries=yes. In those modes Clang can use the unwind-library selection, so this change preserves it.

Rustc uses the last occurrence of the option. The implementation therefore evaluates statically available flag sources in their real command-line order, including later disabling values such as =no. Opaque Args and @response-file contents are treated as unknown; the unwind selection is preserved unless a later static option establishes that default linker libraries are disabled.

Why remove the arguments conditionally

Adding -Wno-unused-command-line-argument would hide an accurate diagnostic and could conceal other genuinely stale linker-driver options. This change removes only the two accepted spellings of the known-inapplicable unwind option when rustc's effective behavior makes them unusable. All other toolchain arguments remain intact.

Verbose-link inspection confirmed that removing these arguments in the default mode does not change the final LLD inputs: rustc still links the explicit unwind runtime.

Validation

  • bazelisk test //test/unit/... — 404 tests passed, 24 skipped
  • analysis tests verify:
    • normal rustc links remove both unwind-option spellings while retaining an unrelated linker argument
    • bare and explicit-yes default-linker-library modes retain both spellings
    • a later =no overrides an earlier =yes and removes both spellings
    • response-file flags conservatively retain both spellings
  • reproduced rustc 1.97.1 linker invocations directly: the default mode passes -nodefaultlibs, while both the bare and =yes forms omit it
  • built //services/oriel/pid-gen:pid-gen-test in the downstream monorepo using this checkout via --override_repository, with unused-command-line warnings explicitly re-enabled; the target built successfully without the warning
  • formatting and typo hooks pass; repository-wide buildifier lint reports only warnings already present on main

AI assistance

OpenAI Codex assisted with diagnosis, implementation, and test construction. I reviewed the resulting code and validated it against both the upstream unit suite and the downstream reproducer.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd9a6c651a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rust/private/rustc.bzl Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e3b9f08d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rust/private/rustc.bzl Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a7d5db6a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rust/private/rustc.bzl Outdated
Comment thread rust/private/rustc.bzl Outdated
Comment thread rust/private/rustc.bzl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant