Skip to content

Avoid unused Clang runtime-selection flags in rustc links - #60

Open
ghorn wants to merge 1 commit into
hermeticbuild:mainfrom
ghorn:codex/omit-unused-driver-runtime-flags
Open

ghorn wants to merge 1 commit into
hermeticbuild:mainfrom
ghorn:codex/omit-unused-driver-runtime-flags

Conversation

@ghorn

@ghorn ghorn commented Sep 11, 2026

Copy link
Copy Markdown

Rust links inherit --unwindlib=none and -rtlib=compiler-rt from LLVM Cc toolchains. With rustc's default linker libraries disabled (-nodefaultlibs), Clang does not consume these automatic runtime-selection options and rustc reports linker_messages warnings for each binary, including host tools.

Omit these exact options (including their single/double-dash aliases) from known Clang Linux/macOS rustc links when default libraries are disabled. Honor flag precedence and preserve the options when defaults are enabled, build-script/response-file/opaque flags are present, or a custom target or driver makes the configuration uncertain. Explicit runtime libraries and search paths remain intact. Filtering stays inside the existing path-mapped argument expansion; ordinary C/C++ links are unaffected.

Validation on macOS arm64 with Bazel 9.2.0:

  • 13 tests passed across //test/unit/runtime_linker_flags:all, //test/unit/rustc_flag_ordering:all, and //test/unit/extra_rustc_flags:all. The new tests inspect real LLVM link actions for both Linux and macOS, covering defaults disabled, enabled, and disabled by the final override.
  • Built and ran the macOS fixture with --extra_toolchains=@llvm//toolchain:all; neither unused-option warning was emitted, including during the process-wrapper host build.
  • Linux LLVM cross-link validation is limited by missing libgcc_s in this checkout. The same link fails on unchanged main; the baseline emits both unused-option diagnostics, while the patched link removes them. Linux action-level regressions pass.
  • Buildifier checks and git diff --check passed.

Assisted-by: OpenAI Codex

Omit redundant automatic runtime selections only for known Clang Linux/macOS links with default linker libraries disabled. Preserve explicit opt-ins and opaque configurations, and cover both platforms with link-action regression tests.

Assisted-by: OpenAI Codex
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