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

Change binary_asm_labels to only fire on x86 and x86_64 #127935

Merged
merged 3 commits into from
Jul 19, 2024

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Jul 18, 2024

In #126922, the binary_asm_labels lint was added which flags labels such as 0: and 1:. Before that change, LLVM was giving a confusing error on x86/x86_64 because of an incorrect interpretation.

However, targets other than x86 and x86_64 never had the error message and have not been a problem. This means that the lint was causing code that previously worked to start failing (e.g. compiler_builtins), rather than only providing a more clear messages where there has always been an error.

Adjust the lint to only fire on x86 and x86_64 assembly to avoid this regression.

Also update the help message.

Fixes: #127821

In <rust-lang#126922>, the
`binary_asm_labels` lint was added which flags labels such as `0:` and
`1:`. Before that change, LLVM was giving a confusing error on
x86/x86_64 because of an incorrect interpretation.

However, targets other than x86 and x86_64 never had the error message
and have not been a problem. This means that the lint was causing code
that previously worked to start failing (e.g. `compiler_builtins`),
rather than only providing a more clear messages where there has always
been an error.

Adjust the lint to only fire on x86 and x86_64 assembly to avoid this
regression.
@rustbot
Copy link
Collaborator

rustbot commented Jul 18, 2024

r? @estebank

rustbot has assigned @estebank.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Jul 18, 2024
compiler/rustc_lint/messages.ftl Outdated Show resolved Hide resolved
compiler/rustc_lint/messages.ftl Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

The link pointed to a closed issue. Create a new one and point the link
to it.

Also add a help message to hint what change the user could make.

Fixes: rust-lang#127821
@tgross35
Copy link
Contributor Author

tgross35 commented Jul 18, 2024

Seems to work now, tested locally on both x86 and aarch64.

r? @Urgau

@rustbot rustbot assigned Urgau and unassigned estebank Jul 18, 2024
@estebank
Copy link
Contributor

Ideally, the lint would not gate on the platform being compiled, but rather gated on whether the code could be run from x86. Namely, if the asm is behind a cfg flag that limits the code to anything other than x86. That being said, I believe that for now this is a reasonable compromise.

@bors r+

@bors
Copy link
Contributor

bors commented Jul 18, 2024

📌 Commit 8410348 has been approved by estebank

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 Jul 18, 2024
@tgross35
Copy link
Contributor Author

tgross35 commented Jul 18, 2024

Ideally, the lint would not gate on the platform being compiled, but rather gated on whether the code could be run from x86. Namely, if the asm is behind a cfg flag that limits the code to anything other than x86.

Do you mean that you would expect the following to lint even if building on aarch64 or other targets?

#[cfg(target_arch = "x86")]
fn foo() {
    unsafe { asm!("0: jmp 0b") };
}

Does that kind of machinery exist? I thought if it was behind a cfg then it doesn't even know the asm is there.

Thanks for the review

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 18, 2024
…y, r=estebank

Change `binary_asm_labels` to only fire on x86 and x86_64

In <rust-lang#126922>, the `binary_asm_labels` lint was added which flags labels such as `0:` and `1:`. Before that change, LLVM was giving a confusing error on x86/x86_64 because of an incorrect interpretation.

However, targets other than x86 and x86_64 never had the error message and have not been a problem. This means that the lint was causing code that previously worked to start failing (e.g. `compiler_builtins`), rather than only providing a more clear messages where there has always been an error.

Adjust the lint to only fire on x86 and x86_64 assembly to avoid this regression.

Also update the help message.

Fixes: rust-lang#127821
@estebank
Copy link
Contributor

Does that kind of machinery exist? I thought if it was behind a cfg then it doesn't even know the asm is there.

We have a very basic collection of items that got cfg'd out for the purposes of telling users that an item that wasn't found is behind a feature flag. We collect those during expansion, which would make my request harder to accomplish, as you would need to implement the lint to be able to work with an ast::ExprKind::InlineAsm (as opposed to the current hir::ExprKind::InlineAsm) but there's precedent.

@tgross35
Copy link
Contributor Author

For this specific lint, it seems like effort is probably better spent fixing LLVM than attempting to improve the ergonomics much more. But being able to leverage that for other inline asm sounds amazing, since it is so platform dependent and easy to make mistakes, we should be able to at least perform Rust's validation on it.

I'll update #127938 to reflect that if it sounds accurate.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 19, 2024
…llaumeGomez

Rollup of 5 pull requests

Successful merges:

 - rust-lang#121533 (Handle .init_array link_section specially on wasm)
 - rust-lang#123196 (Add Process support for UEFI)
 - rust-lang#127621 (Rewrite and rename `issue-22131` and `issue-26006` `run-make` tests to rmake)
 - rust-lang#127928 (Migrate `lto-smoke-c` and `link-path-order` `run-make` tests to rmake)
 - rust-lang#127935 (Change `binary_asm_labels` to only fire on x86 and x86_64)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 19, 2024
…llaumeGomez

Rollup of 5 pull requests

Successful merges:

 - rust-lang#121533 (Handle .init_array link_section specially on wasm)
 - rust-lang#123196 (Add Process support for UEFI)
 - rust-lang#127621 (Rewrite and rename `issue-22131` and `issue-26006` `run-make` tests to rmake)
 - rust-lang#127928 (Migrate `lto-smoke-c` and `link-path-order` `run-make` tests to rmake)
 - rust-lang#127935 (Change `binary_asm_labels` to only fire on x86 and x86_64)

r? `@ghost`
`@rustbot` modify labels: rollup
@tgross35
Copy link
Contributor Author

@bors r- failed rollup #127941 (comment)

@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 Jul 19, 2024
Disable a test that now only passes on x86 and make the link point to
the new (open) LLVM bug.
@tgross35
Copy link
Contributor Author

tgross35 commented Jul 19, 2024

I didn't update the docs so it tried to run the assembly example on all platforms. Added a commit to fix this, looking at other tests I guess the best thing we can do is ignore the doctest and update the output manually. lint-docs tests pass locally on my aarch64 machine now.

I'll let somebody double check the third commit changes (@estebank), @rustbot 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 Jul 19, 2024
@Urgau
Copy link
Member

Urgau commented Jul 19, 2024

Changes looks good.

@bors r=estebank,Urgau

@bors
Copy link
Contributor

bors commented Jul 19, 2024

📌 Commit 5686720 has been approved by estebank,Urgau

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 Jul 19, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 19, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#121533 (Handle .init_array link_section specially on wasm)
 - rust-lang#127825 (Migrate `macos-fat-archive`, `manual-link` and `archive-duplicate-names` `run-make` tests to rmake)
 - rust-lang#127891 (Tweak suggestions when using incorrect type of enum literal)
 - rust-lang#127902 (`collect_tokens_trailing_token` cleanups)
 - rust-lang#127928 (Migrate `lto-smoke-c` and `link-path-order` `run-make` tests to rmake)
 - rust-lang#127935 (Change `binary_asm_labels` to only fire on x86 and x86_64)
 - rust-lang#127953 ([compiletest] Search *.a when getting dynamic libraries on AIX)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6bdf9bd into rust-lang:master Jul 19, 2024
6 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jul 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jul 19, 2024
Rollup merge of rust-lang#127935 - tgross35:binary_asm_labels-x86-only, r=estebank,Urgau

Change `binary_asm_labels` to only fire on x86 and x86_64

In <rust-lang#126922>, the `binary_asm_labels` lint was added which flags labels such as `0:` and `1:`. Before that change, LLVM was giving a confusing error on x86/x86_64 because of an incorrect interpretation.

However, targets other than x86 and x86_64 never had the error message and have not been a problem. This means that the lint was causing code that previously worked to start failing (e.g. `compiler_builtins`), rather than only providing a more clear messages where there has always been an error.

Adjust the lint to only fire on x86 and x86_64 assembly to avoid this regression.

Also update the help message.

Fixes: rust-lang#127821
@tgross35 tgross35 deleted the binary_asm_labels-x86-only branch July 19, 2024 17:53
@workingjubilee workingjubilee added L-binary_asm_labels Lint: LLVM parses labels like 0, 1, 10, 11, etc. oddly O-x86_64 Target: x86-64 processors (like x86_64-*) O-x86_32 Target: x86 processors, 32 bit (like i686-*) labels Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L-binary_asm_labels Lint: LLVM parses labels like 0, 1, 10, 11, etc. oddly O-x86_32 Target: x86 processors, 32 bit (like i686-*) O-x86_64 Target: x86-64 processors (like x86_64-*) 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

binary_asm_labels should suggest a change
7 participants