-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Add lint about redefining runtime symbols #146505
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
base: master
Are you sure you want to change the base?
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…<try> Add lint warn about clashing function names with fundamental functions
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (fb73ebd): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (secondary -0.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -2.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 468.794s -> 471.13s (0.50%) |
9943712 to
e2446d7
Compare
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
This comment has been minimized.
This comment has been minimized.
|
To bikeshed the name: I wouldn't call this "clashing" unless the lint is checking specifically that the signature doesn't match what is expected for each symbol. We have an existing I wouldn't refer to "function names" here because a "function name" in Rust refers to the name of the function in Rust rather than to the symbol name, and we want to focus on the symbol name here. Also, shouldn't we be checking for more than just functions? This breaks things too: #[unsafe(no_mangle)]
static read: () = ();I probably wouldn't call these functions "fundamental". Maybe "runtime", "system", "platform", "builtin", "libc", or similar would work. Perhaps |
e2446d7 to
e0952b2
Compare
Indeed, forgot that statics also have a symbol. Fixed. Regarding the lint level, I made it warn-by-default since there are legitimate reasons to implement those symbols (like when implementing a libc), but maybe it should be deny-by-default? |
|
Given that we have the list in https://doc.rust-lang.org/stable/core/#how-to-use-the-core-library, I think having this be deny-by-default to define these things might even be good -- we can (Speaking for me, not the team.) |
|
Three potential improvements to this: Could we detect whether the signature of the exported function is compatible with what Rust's standard library expects (e.g. Also, could we somehow suppress the warning for symbols only used by std, if Finally, could we allow-by-default this lint if you're in a "standalone"/"freestanding" mode (e.g. you're on a Note that there are legitimate reasons for people to define these symbols, and we want to avoid giving people the impression that Rust is the wrong language to write such code in. For instance, OS kernels, or intentional interposing of these symbols. |
|
Wishlist: it'd be really nice if rustc looked at the things that you are |
|
One further note: once we have the |
|
Here's a thought I mentioned in the meeting. @scottmcm, in particular, suggested it was a strong point and encouraged capturing it here. I see it as important to the statement of what Rust is -- to our story -- that you can use Rust to write a kernel or a libc -- that it's a C competitor in that sense. It's for this reason that, unless we've targeted the lint such that we're sure that we're detecting actual UB, I wouldn't want to ever go deny-by-default with this. I don't want us to suggest, with our linting, that "Rust isn't the language for you if you want to do this kind of work." |
This PR adds lint to warn about redefinition of runtime symbols1 that are assumed and used by
core2 andstd.We have had multiple reports of users tripping over this:
#[no_mangle] fn open() {}makecargo thang?no_mangleredefining_runtime_symbolsOld proposed name:
clashing_function_names_with_fundamental_functions(warn-by-default)
The
redefining_runtime_symbolslint checks for items whose symbol name redefines a runtime symbols expected bycoreand/orstd.Example
Explanation
Up-most care is required when redefining runtime symbols assumed and used by the standard library. They must follow the C specification, not use any standard-library facility or undefined behavior may occur.
The symbols currently checked are respectively:
core2:memcpy,memmove,memset,memcmp,bcmp,strlenstd:open/open64,read,write,close@rustbot labels +I-lang-nominated +T-lang +needs-fcp +A-lints
cc @traviscross
r? compiler
Footnotes
previous lint name
clashing_function_names_with_fundamental_functions, bike-shed at https://github.com/rust-lang/rust/pull/146505#issuecomment-3288716835 ↩https://doc.rust-lang.org/core/index.html#how-to-use-the-core-library ↩ ↩2