-
Notifications
You must be signed in to change notification settings - Fork 493
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
Clarify that asm!
blocks can be duplicated or deduplicated by the compiler
#1441
Conversation
Should we guide users to using unique section names if they need to be able to have each asm block separate? |
@@ -463,6 +463,7 @@ To avoid undefined behavior, these rules must be followed when using function-sc | |||
- The compiler cannot assume that the instructions in the asm are the ones that will actually end up executed. | |||
- This effectively means that the compiler must treat the `asm!` as a black box and only take the interface specification into account, not the instructions themselves. | |||
- Runtime code patching is allowed, via target-specific mechanisms. | |||
- However there is no guarantee that each `asm!` directly corresponds to a single instance of instructions in the object file: the compiler is free to duplicate or deduplicate `asm!` blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the lines above, we specify that the compiler is not allowed to examine the instructions. How is it possible to deduplicate asm blocks without analyzing the instructions within?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, it's that in the very end, LLVM sees two functions that have the exact same instructions emitted and then merges them. I agree that it's slightly weird that that's how it works, but I think LLVM's justification is that it doesn't analyze behavior, just the exact instructions that its assembler emits.
Ideally we would have a way to tell codegen to knock it off and really don't do anything if it sees asm!
in a function, but I'm not sure if LLVM (or other backends) support that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially deduplication can happen when the exact same asm text is generated twice. It's a bit tricky to specify since technically some extra whitespace would cause deduplication to fail, but I'm not sure we want to guarantee that.
It seems you mentioned the wrong issue/PR in the PR description. |
@@ -463,6 +463,7 @@ To avoid undefined behavior, these rules must be followed when using function-sc | |||
- The compiler cannot assume that the instructions in the asm are the ones that will actually end up executed. | |||
- This effectively means that the compiler must treat the `asm!` as a black box and only take the interface specification into account, not the instructions themselves. | |||
- Runtime code patching is allowed, via target-specific mechanisms. | |||
- However there is no guarantee that each `asm!` directly corresponds to a single instance of instructions in the object file: the compiler is free to duplicate or deduplicate `asm!` blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should explicitly specify the other direction as well (no guarantee that an instance of instructions in the object file corresponds to exactly one asm!
expression). When only stated in the current direction, the lack of guarantee could still be understood as only permitting duplication or removal of asm!
, where unification is the originating observed behavior.
Separately, it would be good to specify when disjoint asm!
are able to be unified, given the prior assertion that the compiler is not permitted to rely on the contents of the asm!
string being the instructions which get executed. I think the correct precondition would be that the instantiated asm!
strings are structurally equivalent — that the directives/instructions given to the assembler are identical.
The compiler is not permitted to interpret the effect of the directives/instructions, but it is permitted to inspect the identity of thus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should explicitly specify the other direction as well (no guarantee that an instance of instructions in the object file corresponds to exactly one
asm!
expression). When only stated in the current direction, the lack of guarantee could still be understood as only permitting duplication or removal ofasm!
, where unification is the originating observed behavior.
I think this is already covered by the word "deduplicate"?
Separately, it would be good to specify when disjoint
asm!
are able to be unified, given the prior assertion that the compiler is not permitted to rely on the contents of theasm!
string being the instructions which get executed. I think the correct precondition would be that the instantiatedasm!
strings are structurally equivalent — that the directives/instructions given to the assembler are identical.The compiler is not permitted to interpret the effect of the directives/instructions, but it is permitted to inspect the identity of thus.
I think that we may have to allow more flexibility here due to things like link-time identical code folding. This would merge separate asm that may be structurally different but end up emitting the same bytes. I'm open to suggestions on the exact wording to use here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We reviewed this in the rustdocs call. This seems like a bug fix to the documentation, given that Rust itself never actually made the guarantee that is being explicitly disclaimed here.
It's on that basis that we're going to merge this. If we ever actually wanted to make this guarantee, then that would need a separate proposal to the lang team and related compiler work.
Update books ## rust-lang/book 3 commits in f1e49bf7a8ea6c31ce016a52b8a4f6e1ffcfbc64..67fa536768013d9d5a13f3a06790521d511ef711 2024-07-12 21:21:45 UTC to 2024-07-05 17:35:06 UTC - Use Rust 2021 Edition for mdBook (rust-lang/book#3974) - Backport changes to chapter 11 (rust-lang/book#3969) - Upgrade to Rust 1.79.0 (rust-lang/book#3968) ## rust-lang/edition-guide 2 commits in 941db8b3df45fd46cd87b50a5c86714b91dcde9c..5454de3d12b9ccc6375b629cf7ccda8264640aac 2024-07-14 07:06:34 UTC to 2024-07-12 06:05:29 UTC - Update timeline etc. for Rust 2024 - 2024: Add note about never_type_fallback_flowing_into_unsafe lint level. (rust-lang/edition-guide#311) ## rust-embedded/book 1 commits in b10c6acaf0f43481f6600e95d4b5013446e29f7a..019f3928d8b939ec71b63722dcc2e46330156441 2024-07-11 17:46:10 UTC to 2024-07-11 17:46:10 UTC - typo on tooling.md (rust-embedded/book#373) ## rust-lang/reference 9 commits in 1ae3deebc3ac16e276b6558e01420f8e605def08..e2f0bdc4031866734661dcdb548184bde1450baf 2024-06-29 16:59:51 +0000 to 2024-07-15 17:52:44 +0000 - Suppress type length limit test and note that it is not enforced (rust-lang/reference#1527) - elaborate on slice wide pointer metadata (rust-lang/reference#1499) - '.inst' in inline-assembly changed to '.insn' (rust-lang/reference#1453) - Clarify that `asm!` blocks can be duplicated or deduplicated by the compiler (rust-lang/reference#1441) - Add mdbook-spec (rust-lang/reference#1520) - Add note about static libraries not linking their dependencies (rust-lang/reference#1472) - more explicitly explain the UB around immutable extern statics (rust-lang/reference#1502) - Improvements to `items/functions.md` (rust-lang/reference#1458) - Enable mdbook smart-punctuation. (rust-lang/reference#1516) ## rust-lang/rust-by-example 1 commits in 658c6c27cb975b92227936024816986c2d3716fb..89aecb6951b77bc746da73df8c9f2b2ceaad494a 2024-07-11 12:33:43 UTC to 2024-07-11 12:33:43 UTC - Update option_result.md (rust-lang/rust-by-example#1864) ## rust-lang/rustc-dev-guide 6 commits in d6e3a32a557db5902e714604def8015d6bb7e0f7..0c4d55cb59fe440d1a630e4e5774d043968edb3f 2024-07-15 15:16:43 UTC to 2024-07-01 19:05:14 UTC - Improve documentation of MIR queries & passes (rust-lang/rustc-dev-guide#1434) - Bump dependencies for date-check tool (rust-lang/rustc-dev-guide#2012) - Fix typo: lists -> lints (rust-lang/rustc-dev-guide#2011) - use "bootstrap" instead of "rustbuild" (rust-lang/rustc-dev-guide#2010) - Fix grammar issue in optimize-build.md (rust-lang/rustc-dev-guide#2009) - Update name of Fuchsia builder (rust-lang/rustc-dev-guide#2008)
Update books ## rust-lang/book 3 commits in f1e49bf7a8ea6c31ce016a52b8a4f6e1ffcfbc64..67fa536768013d9d5a13f3a06790521d511ef711 2024-07-12 21:21:45 UTC to 2024-07-05 17:35:06 UTC - Use Rust 2021 Edition for mdBook (rust-lang/book#3974) - Backport changes to chapter 11 (rust-lang/book#3969) - Upgrade to Rust 1.79.0 (rust-lang/book#3968) ## rust-lang/edition-guide 2 commits in 941db8b3df45fd46cd87b50a5c86714b91dcde9c..5454de3d12b9ccc6375b629cf7ccda8264640aac 2024-07-14 07:06:34 UTC to 2024-07-12 06:05:29 UTC - Update timeline etc. for Rust 2024 - 2024: Add note about never_type_fallback_flowing_into_unsafe lint level. (rust-lang/edition-guide#311) ## rust-embedded/book 1 commits in b10c6acaf0f43481f6600e95d4b5013446e29f7a..019f3928d8b939ec71b63722dcc2e46330156441 2024-07-11 17:46:10 UTC to 2024-07-11 17:46:10 UTC - typo on tooling.md (rust-embedded/book#373) ## rust-lang/reference 9 commits in 1ae3deebc3ac16e276b6558e01420f8e605def08..e2f0bdc4031866734661dcdb548184bde1450baf 2024-06-29 16:59:51 +0000 to 2024-07-15 17:52:44 +0000 - Suppress type length limit test and note that it is not enforced (rust-lang/reference#1527) - elaborate on slice wide pointer metadata (rust-lang/reference#1499) - '.inst' in inline-assembly changed to '.insn' (rust-lang/reference#1453) - Clarify that `asm!` blocks can be duplicated or deduplicated by the compiler (rust-lang/reference#1441) - Add mdbook-spec (rust-lang/reference#1520) - Add note about static libraries not linking their dependencies (rust-lang/reference#1472) - more explicitly explain the UB around immutable extern statics (rust-lang/reference#1502) - Improvements to `items/functions.md` (rust-lang/reference#1458) - Enable mdbook smart-punctuation. (rust-lang/reference#1516) ## rust-lang/rust-by-example 1 commits in 658c6c27cb975b92227936024816986c2d3716fb..89aecb6951b77bc746da73df8c9f2b2ceaad494a 2024-07-11 12:33:43 UTC to 2024-07-11 12:33:43 UTC - Update option_result.md (rust-lang/rust-by-example#1864) ## rust-lang/rustc-dev-guide 6 commits in d6e3a32a557db5902e714604def8015d6bb7e0f7..0c4d55cb59fe440d1a630e4e5774d043968edb3f 2024-07-15 15:16:43 UTC to 2024-07-01 19:05:14 UTC - Improve documentation of MIR queries & passes (rust-lang/rustc-dev-guide#1434) - Bump dependencies for date-check tool (rust-lang/rustc-dev-guide#2012) - Fix typo: lists -> lints (rust-lang/rustc-dev-guide#2011) - use "bootstrap" instead of "rustbuild" (rust-lang/rustc-dev-guide#2010) - Fix grammar issue in optimize-build.md (rust-lang/rustc-dev-guide#2009) - Update name of Fuchsia builder (rust-lang/rustc-dev-guide#2008)
Update books ## rust-lang/book 3 commits in f1e49bf7a8ea6c31ce016a52b8a4f6e1ffcfbc64..67fa536768013d9d5a13f3a06790521d511ef711 2024-07-12 21:21:45 UTC to 2024-07-05 17:35:06 UTC - Use Rust 2021 Edition for mdBook (rust-lang/book#3974) - Backport changes to chapter 11 (rust-lang/book#3969) - Upgrade to Rust 1.79.0 (rust-lang/book#3968) ## rust-lang/edition-guide 2 commits in 941db8b3df45fd46cd87b50a5c86714b91dcde9c..5454de3d12b9ccc6375b629cf7ccda8264640aac 2024-07-14 07:06:34 UTC to 2024-07-12 06:05:29 UTC - Update timeline etc. for Rust 2024 - 2024: Add note about never_type_fallback_flowing_into_unsafe lint level. (rust-lang/edition-guide#311) ## rust-embedded/book 1 commits in b10c6acaf0f43481f6600e95d4b5013446e29f7a..019f3928d8b939ec71b63722dcc2e46330156441 2024-07-11 17:46:10 UTC to 2024-07-11 17:46:10 UTC - typo on tooling.md (rust-embedded/book#373) ## rust-lang/reference 9 commits in 1ae3deebc3ac16e276b6558e01420f8e605def08..e2f0bdc4031866734661dcdb548184bde1450baf 2024-06-29 16:59:51 +0000 to 2024-07-15 17:52:44 +0000 - Suppress type length limit test and note that it is not enforced (rust-lang/reference#1527) - elaborate on slice wide pointer metadata (rust-lang/reference#1499) - '.inst' in inline-assembly changed to '.insn' (rust-lang/reference#1453) - Clarify that `asm!` blocks can be duplicated or deduplicated by the compiler (rust-lang/reference#1441) - Add mdbook-spec (rust-lang/reference#1520) - Add note about static libraries not linking their dependencies (rust-lang/reference#1472) - more explicitly explain the UB around immutable extern statics (rust-lang/reference#1502) - Improvements to `items/functions.md` (rust-lang/reference#1458) - Enable mdbook smart-punctuation. (rust-lang/reference#1516) ## rust-lang/rust-by-example 1 commits in 658c6c27cb975b92227936024816986c2d3716fb..89aecb6951b77bc746da73df8c9f2b2ceaad494a 2024-07-11 12:33:43 UTC to 2024-07-11 12:33:43 UTC - Update option_result.md (rust-lang/rust-by-example#1864) ## rust-lang/rustc-dev-guide 6 commits in d6e3a32a557db5902e714604def8015d6bb7e0f7..0c4d55cb59fe440d1a630e4e5774d043968edb3f 2024-07-15 15:16:43 UTC to 2024-07-01 19:05:14 UTC - Improve documentation of MIR queries & passes (rust-lang/rustc-dev-guide#1434) - Bump dependencies for date-check tool (rust-lang/rustc-dev-guide#2012) - Fix typo: lists -> lints (rust-lang/rustc-dev-guide#2011) - use "bootstrap" instead of "rustbuild" (rust-lang/rustc-dev-guide#2010) - Fix grammar issue in optimize-build.md (rust-lang/rustc-dev-guide#2009) - Update name of Fuchsia builder (rust-lang/rustc-dev-guide#2008)
Update books ## rust-lang/book 3 commits in f1e49bf7a8ea6c31ce016a52b8a4f6e1ffcfbc64..67fa536768013d9d5a13f3a06790521d511ef711 2024-07-12 21:21:45 UTC to 2024-07-05 17:35:06 UTC - Use Rust 2021 Edition for mdBook (rust-lang/book#3974) - Backport changes to chapter 11 (rust-lang/book#3969) - Upgrade to Rust 1.79.0 (rust-lang/book#3968) ## rust-lang/edition-guide 2 commits in 941db8b3df45fd46cd87b50a5c86714b91dcde9c..5454de3d12b9ccc6375b629cf7ccda8264640aac 2024-07-14 07:06:34 UTC to 2024-07-12 06:05:29 UTC - Update timeline etc. for Rust 2024 - 2024: Add note about never_type_fallback_flowing_into_unsafe lint level. (rust-lang/edition-guide#311) ## rust-embedded/book 1 commits in b10c6acaf0f43481f6600e95d4b5013446e29f7a..019f3928d8b939ec71b63722dcc2e46330156441 2024-07-11 17:46:10 UTC to 2024-07-11 17:46:10 UTC - typo on tooling.md (rust-embedded/book#373) ## rust-lang/reference 9 commits in 1ae3deebc3ac16e276b6558e01420f8e605def08..e2f0bdc4031866734661dcdb548184bde1450baf 2024-06-29 16:59:51 +0000 to 2024-07-15 17:52:44 +0000 - Suppress type length limit test and note that it is not enforced (rust-lang/reference#1527) - elaborate on slice wide pointer metadata (rust-lang/reference#1499) - '.inst' in inline-assembly changed to '.insn' (rust-lang/reference#1453) - Clarify that `asm!` blocks can be duplicated or deduplicated by the compiler (rust-lang/reference#1441) - Add mdbook-spec (rust-lang/reference#1520) - Add note about static libraries not linking their dependencies (rust-lang/reference#1472) - more explicitly explain the UB around immutable extern statics (rust-lang/reference#1502) - Improvements to `items/functions.md` (rust-lang/reference#1458) - Enable mdbook smart-punctuation. (rust-lang/reference#1516) ## rust-lang/rust-by-example 1 commits in 658c6c27cb975b92227936024816986c2d3716fb..89aecb6951b77bc746da73df8c9f2b2ceaad494a 2024-07-11 12:33:43 UTC to 2024-07-11 12:33:43 UTC - Update option_result.md (rust-lang/rust-by-example#1864) ## rust-lang/rustc-dev-guide 6 commits in d6e3a32a557db5902e714604def8015d6bb7e0f7..0c4d55cb59fe440d1a630e4e5774d043968edb3f 2024-07-15 15:16:43 UTC to 2024-07-01 19:05:14 UTC - Improve documentation of MIR queries & passes (rust-lang/rustc-dev-guide#1434) - Bump dependencies for date-check tool (rust-lang/rustc-dev-guide#2012) - Fix typo: lists -> lints (rust-lang/rustc-dev-guide#2011) - use "bootstrap" instead of "rustbuild" (rust-lang/rustc-dev-guide#2010) - Fix grammar issue in optimize-build.md (rust-lang/rustc-dev-guide#2009) - Update name of Fuchsia builder (rust-lang/rustc-dev-guide#2008)
Rollup merge of rust-lang#127770 - rustbot:docs-update, r=ehuss Update books ## rust-lang/book 3 commits in f1e49bf7a8ea6c31ce016a52b8a4f6e1ffcfbc64..67fa536768013d9d5a13f3a06790521d511ef711 2024-07-12 21:21:45 UTC to 2024-07-05 17:35:06 UTC - Use Rust 2021 Edition for mdBook (rust-lang/book#3974) - Backport changes to chapter 11 (rust-lang/book#3969) - Upgrade to Rust 1.79.0 (rust-lang/book#3968) ## rust-lang/edition-guide 2 commits in 941db8b3df45fd46cd87b50a5c86714b91dcde9c..5454de3d12b9ccc6375b629cf7ccda8264640aac 2024-07-14 07:06:34 UTC to 2024-07-12 06:05:29 UTC - Update timeline etc. for Rust 2024 - 2024: Add note about never_type_fallback_flowing_into_unsafe lint level. (rust-lang/edition-guide#311) ## rust-embedded/book 1 commits in b10c6acaf0f43481f6600e95d4b5013446e29f7a..019f3928d8b939ec71b63722dcc2e46330156441 2024-07-11 17:46:10 UTC to 2024-07-11 17:46:10 UTC - typo on tooling.md (rust-embedded/book#373) ## rust-lang/reference 9 commits in 1ae3deebc3ac16e276b6558e01420f8e605def08..e2f0bdc4031866734661dcdb548184bde1450baf 2024-06-29 16:59:51 +0000 to 2024-07-15 17:52:44 +0000 - Suppress type length limit test and note that it is not enforced (rust-lang/reference#1527) - elaborate on slice wide pointer metadata (rust-lang/reference#1499) - '.inst' in inline-assembly changed to '.insn' (rust-lang/reference#1453) - Clarify that `asm!` blocks can be duplicated or deduplicated by the compiler (rust-lang/reference#1441) - Add mdbook-spec (rust-lang/reference#1520) - Add note about static libraries not linking their dependencies (rust-lang/reference#1472) - more explicitly explain the UB around immutable extern statics (rust-lang/reference#1502) - Improvements to `items/functions.md` (rust-lang/reference#1458) - Enable mdbook smart-punctuation. (rust-lang/reference#1516) ## rust-lang/rust-by-example 1 commits in 658c6c27cb975b92227936024816986c2d3716fb..89aecb6951b77bc746da73df8c9f2b2ceaad494a 2024-07-11 12:33:43 UTC to 2024-07-11 12:33:43 UTC - Update option_result.md (rust-lang/rust-by-example#1864) ## rust-lang/rustc-dev-guide 6 commits in d6e3a32a557db5902e714604def8015d6bb7e0f7..0c4d55cb59fe440d1a630e4e5774d043968edb3f 2024-07-15 15:16:43 UTC to 2024-07-01 19:05:14 UTC - Improve documentation of MIR queries & passes (rust-lang/rustc-dev-guide#1434) - Bump dependencies for date-check tool (rust-lang/rustc-dev-guide#2012) - Fix typo: lists -> lints (rust-lang/rustc-dev-guide#2011) - use "bootstrap" instead of "rustbuild" (rust-lang/rustc-dev-guide#2010) - Fix grammar issue in optimize-build.md (rust-lang/rustc-dev-guide#2009) - Update name of Fuchsia builder (rust-lang/rustc-dev-guide#2008)
Fixes rust-lang/rust#116857