Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to configure always using @argfile for linker invocations #138421

Closed
weihanglo opened this issue Mar 12, 2025 · 3 comments · Fixed by #138439
Closed

A way to configure always using @argfile for linker invocations #138421

weihanglo opened this issue Mar 12, 2025 · 3 comments · Fixed by #138439
Labels
A-linkers Area: linkers... you gotta love linkers C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@weihanglo
Copy link
Member

My scenario is a bit weird.

In my build system, there is a general wrapper that disguises itself as clang. Unfortunately it doesn't really propagate the OS error well, so E2BIG won't be caught by rustc.

If the linker invocation has grown too big (which is not uncommon because Cargo always passes absolute paths for rustflags), with the general wrapper in my build system, rustc didn't know how to recover and then gave up.

error: linking with `x86_64-unknown-linux-gnu-clang` failed: exit status: 255
  |
  = note: PATH="..." "x86_64-unknown-linux-gnu-clang" "<256 object files omitted>" <1024 rlib files omitted> "-Wl,--undefined-version"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: my-wrapper: Argument list too long      

Is there a way to tell rustc always use @argfile for linker invocations?

Possible solutions

  • Provide a way to tell rustc always use @argfile for linker invocations.
  • Put my t-cargo hat on. Cargo maybe should stop using absolute paths and switch to relative paths, I know. But that won't fix the root problem if I then have 8192 rlib files…
  • Perhaps I could try find an way to estimate the arglist length also on Unix?
    // We mostly only care about Windows in this method, on Unix the limits
    // can be gargantuan anyway so we're pretty unlikely to hit them
    if cfg!(unix) {
    return false;
    }
@weihanglo weihanglo added the C-bug Category: This is a bug. label Mar 12, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 12, 2025
@jieyouxu jieyouxu added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 12, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Mar 12, 2025

I suppose it would be reasonable to add a rustc flag that tries to instruct rustc to always attempt to use @argfile for linker invocations with the explicit caveat that said linker must actually support it (and suport it well), and if it doesn't, well sorry.

The absolute path -> relative path is really at most a mitigation and doesn't actually help if the invocation would be truly massive.

@jieyouxu jieyouxu added A-linkers Area: linkers... you gotta love linkers C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-bug Category: This is a bug. labels Mar 12, 2025
@weihanglo
Copy link
Member Author

Perhaps I could try find an way to estimate the arglist length also on Unix?

What about this? Call sysconf(_SC_ARG_MAX) and don't bother the likely-to-fail attempt.

@jieyouxu
Copy link
Member

Seems reasonable

@bors bors closed this as completed in 06b135f Mar 15, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 15, 2025
Rollup merge of rust-lang#138439 - weihanglo:argmax, r=jieyouxu

feat: check ARG_MAX on Unix platforms

On Unix the limits can be gargantuan anyway so we're pretty unlikely to hit them, but might still exceed it.
We consult ARG_MAX here to get an estimate.

Fixes rust-lang#138421

r? `@jieyouxu`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkers Area: linkers... you gotta love linkers C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants