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

Emit error when trying to use assembler syntax directives in asm! #82270

Merged
merged 4 commits into from
Mar 18, 2021

Conversation

asquared31415
Copy link
Contributor

The .intel_syntax and .att_syntax assembler directives should not be used, in favor of not specifying a syntax for intel, and in favor of the explicit att_syntax option using the inline assembly options.

Closes #79869

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @lcnr (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 18, 2021
@asquared31415
Copy link
Contributor Author

I'm not sure if I like the exact phrasing of the error messages, so if anyone has any better ideas, please state them.

compiler/rustc_builtin_macros/src/asm.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/asm.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/asm.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/asm.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/asm.rs Outdated Show resolved Hide resolved
@jyn514 jyn514 added A-inline-assembly Area: inline asm!(..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 18, 2021
@lcnr
Copy link
Contributor

lcnr commented Feb 26, 2021

@nagisa do you want to take this over?

@nagisa
Copy link
Member

nagisa commented Feb 26, 2021

Yeah, can do.

r? @nagisa

@rust-highfive rust-highfive assigned nagisa and unassigned lcnr Feb 26, 2021
@@ -0,0 +1,23 @@
#![feature(asm, llvm_asm)]
Copy link
Member

Choose a reason for hiding this comment

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

This test needs to be conditional on target, or specify via compiler-flags what target to use. In later case, you will also need to make the test no_core – you can look at the other assembly tests (such as src/test/assembly/asm/x86-types.rs) to see how to set that up.

Copy link
Member

@nagisa nagisa Mar 7, 2021

Choose a reason for hiding this comment

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

The test should also check the behaviour when the target isn't x86_64, this can be done through revisions, you can see how those are used in the same x86-types.rs test as well.

@nagisa
Copy link
Member

nagisa commented Mar 7, 2021

Sorry for taking a while to get back to you, this is looking pretty nice now!

Left some remaining nits, but the core logic looks pretty solid now.

@nagisa
Copy link
Member

nagisa commented Mar 17, 2021

@bors r+

Thank you!

@bors
Copy link
Contributor

bors commented Mar 17, 2021

📌 Commit 4b13b81 has been approved by nagisa

@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 Mar 17, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 17, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#82191 (Vec::dedup_by optimization)
 - rust-lang#82270 (Emit error when trying to use assembler syntax directives in `asm!`)
 - rust-lang#82434 (Add more links between hash and btree collections)
 - rust-lang#83080 (Make source-based code coverage compatible with MIR inlining)
 - rust-lang#83168 (Extend `proc_macro_back_compat` lint to `procedural-masquerade`)
 - rust-lang#83192 (ci/docker: Add SDK/NDK level 21 to android docker for 32bit platforms)
 - rust-lang#83204 (Simplify C compilation for Fortanix-SGX target)
 - rust-lang#83216 (Allow registering tool lints with `register_tool`)
 - rust-lang#83223 (Display error details when a `mmap` call fails)
 - rust-lang#83228 (Don't show HTML diff if tidy isn't installed for rustdoc tests)
 - rust-lang#83231 (Switch riscvgc-unknown-none-elf use lp64d ABI)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 16f6583 into rust-lang:master Mar 18, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 18, 2021
Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) => rustc_ast::LlvmAsmDialect::Intel,
_ => rustc_ast::LlvmAsmDialect::Att,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The concept of an asm dialect doesn't exist outside of x86. In fact the .att_syntax and .intel_syntax directives are x86-specific and don't exist on other targets.

@petrochenkov
Copy link
Contributor

@asquared31415
Could you add // needs-llvm-components: arm to the test?
Otherwise it fails when LLVM backend for ARM is not built.

@asquared31415 asquared31415 deleted the asm-syntax-directive-errors branch March 21, 2021 03:04
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 22, 2021
…r=Dylan-DPC

Fix test for rust-lang#82270

Fixes a test in rust-lang#82270 to require the arm llvm component
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 22, 2021
Rollup of 7 pull requests

Successful merges:

 - rust-lang#82374 (Add license metadata for std dependencies)
 - rust-lang#82683 (Document panicking cases for integer division and remainder)
 - rust-lang#83272 (Clarify non-exact length in the Iterator::take documentation)
 - rust-lang#83338 (Fix test for rust-lang#82270)
 - rust-lang#83351 (post-drop-elab check-const: explain why we still check qualifs)
 - rust-lang#83367 (Improve error message for unassigned query provider)
 - rust-lang#83372 (SplitInclusive is public API)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Amanieu added a commit to Amanieu/rust that referenced this pull request Mar 25, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 25, 2021
Refactor rust-lang#82270 as lint instead of an error

This PR fixes several issues with rust-lang#82270 which generated an error when `.intel_syntax` or `.att_syntax` was used in inline assembly:
- It is now a warn-by-default lint instead of an error.
- The lint only triggers on x86. `.intel_syntax` and `.att_syntax` are only valid on x86.
- The lint no longer provides machine-applicable suggestions for two reasons:
	- These changes should not be made automatically since changes to assembly code can be very subtle.
	- The template string is not always just a string: it can contain macro invocation (`concat!`), raw strings, escape characters, etc.

cc `@asquared31415`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 26, 2021
Refactor rust-lang#82270 as lint instead of an error

This PR fixes several issues with rust-lang#82270 which generated an error when `.intel_syntax` or `.att_syntax` was used in inline assembly:
- It is now a warn-by-default lint instead of an error.
- The lint only triggers on x86. `.intel_syntax` and `.att_syntax` are only valid on x86.
- The lint no longer provides machine-applicable suggestions for two reasons:
	- These changes should not be made automatically since changes to assembly code can be very subtle.
	- The template string is not always just a string: it can contain macro invocation (`concat!`), raw strings, escape characters, etc.

cc ``@asquared31415``
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 26, 2021
Rollup of 8 pull requests

Successful merges:

 - rust-lang#83055 ([rustdoc] Don't document stripped items in JSON renderer.)
 - rust-lang#83437 (Refactor rust-lang#82270 as lint instead of an error)
 - rust-lang#83444 (Fix bootstrap tests on beta)
 - rust-lang#83456 (Add docs for Vec::from functions)
 - rust-lang#83463 (ExitStatusExt: Fix missing word in two docs messages)
 - rust-lang#83470 (Fix patch note about rust-lang#80653 not mentioning nested nor recursive)
 - rust-lang#83485 (Mark asm tests as requiring LLVM 10.0.1)
 - rust-lang#83486 (Don't ICE when using `#[global_alloc]` on a non-item statement)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: inline asm!(..) 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.

asm! should catch attempts to use .intel_syntax or .att_syntax and suggest appropriate options instead
9 participants