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.
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
RFC: Add
no_entry
attribute to omit entry point symbol #2735RFC: Add
no_entry
attribute to omit entry point symbol #2735Changes from all commits
e4ad78d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Elaborate on typically?
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.
Elaborate re. typically.
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.
@Centril I understood "typically" here to mean the same thing as it does, for example, when we say that
main
is typically a function. The symbol must exist, whether its a function, a static, or "something else" in some future version of Rust is up to the user.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.
@gnzlbg sure; I'm asking for textual changes tho to clarify what it means. :)
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.
Examples of both include?
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 don't think any C library supports being invoked without its initialization code. One job of the initialization code is to initialize thread-local storage for the main thread, which is needed for
errno
in particular. This means that calling a C library function that setserrno
(which is pretty much all of them) will most likely segfault due to TLS not being initialized.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.
This also entails that supporting
no_entry
is optional for a Rust compiler in terms of static semantics and that the attribute has primarily implementation defined semantics, right? Would be good to spell that out if so.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.
More than "optional", I understand this document to specify the behavior of
#![no_entry]
as implementation-defined, meaning that the implementation must document what the behavior is.Often, the language spec constraints the sets of behaviors that can be implemented for implementation-defined behavior, and I believe that it is in the "spirit" of this document to constraint the behaviors that a Rust implementation can provide to:
#![no_entry]
for a target#![no_entry]
for a target but using it requires#![no_std]
#![no_entry]
does not instantaneously trigger a compilation error, but is handled according to the semantics of the target, which must be documented by the implementation for the particular target according to the text above. This might mean that compilation might fail later, e.g., if some symbol is missing.That is, a Rust implementation cannot just choose to completely ignore
#![no_entry]
and, e.g., not being even able to parse it. It must explicitly support it in a minimal way at least, however, what#![no_entry]
actually then does will depend on the implementation and the target.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.
To ascertain the motivation/rationale of this proposal relative to the complexity cost to the compiler (not users) it would be good to include examples of both to see how much of a hassle existing solutions are. Examples could be included in an appendix to this RFC or inline depending on how much space it takes textually.
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.
Provide said examples and let them speak for themselves. :)
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.
To better understand the cost of this proposal, I would like to see an appendix of all the current knobs (stable and unstable, with a note of which is which) regarding startup / entrypoint behavior. Ideally appendix would include a "flow chart" description.
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 it would be reasonable to have all the current knobs documented in a central place somewhere (e.g. the rustc user guide). I think it would be worth it to open an issue in rust-lang/rust about this. Once that happens, this and future RFCs can just reference to those docs and mention the additions.
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.
Sure, that also works.
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.
Elaborate re. what that might look like?
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.
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 believe this is true but enumerate some examples nonetheless?
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.
Can you provide a minimal example of how C (e.g. using clang) handles this? Do C compilers offer compiler extensions to make this simpler ?
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 we have
#[entry]
onunsafe ... fn foobar(...)
do we then also need#![no_entry]
?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.
FWIW this is an elaboration of https://github.com/rust-lang/rfcs/pull/2735/files/e4ad78dd444961bbc268f4f4a46189999750a5ca#r308998642
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.
@Centril Yes, we do.
entry
could be used in a library, for instance, with a binary crate usingno_entry
and using that library. I'll add a note that it would make sense to have a lint if you useentry
in a binary crate without usingno_entry
, though.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.
@joshtriplett Ah I see; so this is akin to "needs / provides" of
#![requires_allocator]
(because every program requires an entry point) and#[global_allocator]
. -- Please mention this similarity explicitly as well as the use-case for library/binary division in the text also. :)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.
What do you mean by
requires_allocator
? I don't see any references to that or similar names anywhere on the web.The RFC already mentions the use case of library/binary division, in the rationale and alternatives section: "However, this would make it difficult to flexibly provide the entry point from a library or other mechanism."
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.
Ooops; It's called
#![needs_allocator]
in https://github.com/rust-lang/rust/blob/master/src/liballoc/lib.rs#L65 apparently.Yes, but connecting this to
entry
andno_entry
is another matter, it would be helpful to clarify that this is what is referred to by that sentence.