Fix linker detection for linker (drivers) with a version postfix (e.g. clang-12 instead of clang) by jschwe · Pull Request #106489 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation30 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

jschwe

Linker (drivers) such as clang / gcc or lld often have a version postfix matching the regex "-\d+$".
Previously, linker detection did not account for the possible version postfix and the fallback value was used, which can cause linker errors due to wrong arguments.
Also remove the check for -clang, since there are no architecture specific variants of clang (to my knowledge).

Fixes #106454

@rustbot

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

labels

Jan 5, 2023

@jackh726

oli-obk

@oli-obk

@bors

📌 Commit 41672bf5e5e2946e684ec5b0639863b0f789621f has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Jan 9, 2023

@oli-obk

@bors bors added S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

and removed S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

labels

Jan 9, 2023

@oli-obk

@rust-log-analyzer

This comment was marked as resolved.

@jschwe

Would it make sense to add detection for g++ and clang++ (which should be treated the same as gcc/clang) in this PR, or should that be a seperate PR?

@petrochenkov

@jschwe

Would it make sense to add detection for g++ and clang++ (which should be treated the same as gcc/clang) in this PR, or should that be a seperate PR?

Yeah, these can also be added.
This stuff is not strictly necessary because -C linker-flavor can be added explicitly if it's not inferred correctly, so not everything is added, but adding obvious cases like g++ or clang++ should be fine.

petrochenkov

@jschwe

This stuff is not strictly necessary because -C linker-flavor can be added explicitly if it's not inferred correctly

This requires using either RUSTFLAGS (or one of the other ways to modify the rustflags for the crate and ALL dependencies) or cargo rustc right? I.e. there is no way to set -C linker-flavor for cargo test without also setting the flag for all dependencies (where it might not be wanted).

@jschwe

I pushed a commit which strips the possible version postfix, but without using a regex this time. This makes the matching a bit nicer.

@petrochenkov

Ok, let's just land this as is.
r=me after squashing commits.
@rustbot author

@rustbot rustbot added S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Jan 13, 2023

@jschwe

Linker drivers such as gcc, clang or lld often have a version postfix, e.g clang-12. The previous logic would not account for this and would fall back to guessing the linker flavor to be the default linker flavor for the target, which causes linker errors when this is not the case. By accounting for the possible version postfix and also considering g++ and clang++, we considerably reduce the amount of times the fallback guess has to be used.

To simplify matching check for a version postfix and match against the linker stem without any version postfix. In contrast to gcc, clang supports all architectures in one binary. This means there are no variants like aarch64-linux-gnu-clang and there is no need to check for -clang variants.

@jschwe

Rebased, squashed and adjusted the commit message.

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

and removed S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Jan 13, 2023

@petrochenkov

@bors

📌 Commit 3bc2970 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Jan 13, 2023

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jan 13, 2023

@matthiaskrgr

…rochenkov

Fix linker detection for linker (drivers) with a version postfix (e.g. clang-12 instead of clang)

Linker (drivers) such as clang / gcc or lld often have a version postfix matching the regex "-\d+$". Previously, linker detection did not account for the possible version postfix and the fallback value was used, which can cause linker errors due to wrong arguments. Also remove the check for -clang, since there are no architecture specific variants of clang (to my knowledge).

Fixes rust-lang#106454

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 13, 2023

@bors

…iaskrgr

Rollup of 10 pull requests

Successful merges:

Failed merges:

r? @ghost @rustbot modify labels: rollup

@jschwe jschwe deleted the fix_linker_detection branch

January 18, 2023 13:34

taiki-e added a commit to taiki-e/setup-cross-toolchain-action that referenced this pull request

Mar 12, 2023

@taiki-e

Rust 1.68 (rust-lang/rust#106489) broke this:

= note: clang-15: error: unsupported option '--export'
        clang-15: error: unsupported option '--stack-first'
        clang-15: error: unsupported option '--allow-undefined'
        clang-15: error: unsupported option '--fatal-warnings'
        clang-15: error: unsupported option '--no-demangle'
        clang-15: error: unsupported option '--gc-sections'
        clang-15: error: unknown argument: '-flavor'
        clang-15: error: no such file or directory: 'wasm'
        clang-15: error: no such file or directory: '__main_void'

taiki-e added a commit to taiki-e/rust-cross-toolchain that referenced this pull request

Mar 12, 2023

@taiki-e

Rust 1.68 (rust-lang/rust#106489) broke this:

= note: clang-15: error: unsupported option '--export'
        clang-15: error: unsupported option '--stack-first'
        clang-15: error: unsupported option '--allow-undefined'
        clang-15: error: unsupported option '--fatal-warnings'
        clang-15: error: unsupported option '--no-demangle'
        clang-15: error: unsupported option '--gc-sections'
        clang-15: error: unknown argument: '-flavor'
        clang-15: error: no such file or directory: 'wasm'
        clang-15: error: no such file or directory: '__main_void'

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Mar 16, 2023

@matthiaskrgr

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Mar 17, 2023

@matthiaskrgr

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Mar 17, 2023

@matthiaskrgr

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Mar 17, 2023

@matthiaskrgr

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.