Repository navigation
Mark arguments of main as noundef - #166428
Open
mvanbem-goog wants to merge 1 commit into
Open
mvanbem-goog wants to merge 1 commit into
mvanbem-goog wants to merge 1 commit into
Conversation
As far as I can tell, Clang applies the `noundef` attribute to the arguments of `main` because `argc` and `argv` are always initialized and have no forbidden bit patterns. The same would be true of any `main` function Rust generates, so we might as well apply it. I don't have a deep understanding of the issue, but this seems to be needed to make MemorySanitizer work reliably with Google's internal aarch64 toolchain. Without the attribute, MemorySanitizer can instrument this `main` function to check whether the parameters were initialized, but the caller is an uninstrumented libc, so the shadow values it checks were not written and are stale. It's possible (and maybe even likely?) for other code linked into the binary like C++ static initializers to update those shadow values such that the checks at the beginning of `main` pass. Applying the attribute tells MSan to skip checking the parameters.
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project has assigned @adwinwhite (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
Contributor
|
@rustbot reroll |
Member
|
This seems to be an ad-hoc fix for one instance of #165040. |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As far as I can tell, Clang applies the
noundefattribute to the arguments ofmainbecauseargcandargvare always initialized and have no forbidden bit patterns. The same would be true of anymainfunction Rust generates, so we might as well apply it.I don't have a deep understanding of the issue, but this seems to be needed to make MemorySanitizer work reliably with Google's internal aarch64 toolchain. Without the attribute, MemorySanitizer can instrument this
mainfunction to check whether the parameters were initialized, but the caller is an uninstrumented libc, so the shadow values it checks were not written and are stale. It's possible (and maybe even likely?) for other code linked into the binary like C++ static initializers to update those shadow values such that the checks at the beginning ofmainpass. Applying the attribute tells MSan to skip checking the parameters.The checks for
target.osbeing not UEFI andtarget.main_needs_argc_argvmirror the checks increate_entry_fnincompiler/rustc_codegen_ssa/src/base.rs.I'm not sure that I've updated the
16bit-c-inttest case correctly, since I don't have any compatible platforms on hand, but I suppose that's what a CI run is for.LLM disclosure: As is strongly encouraged by my employer, I had an LLM agent debug the initially observed failure and draft a change. I reviewed the change and removed all LLM-generated prose; this is mine now. And I wrote the title and description.