-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Collect function instance used in global_asm!
sym operand
#96650
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
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 started with an empty function here, and noticed an issue where
my_func
andfoobar
had been merged together bymergefunc
pass, invalidating the reference from global asm. Probablymergefunc
shouldn't touch symbols fromllvm.compiler.used
?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.
No, mergefunc is perfectly valid here. In general Rust doesn't guarantee that two functions will have separate addresses.
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 mean, one of the functions is removed completely, and reference from the global asm is left unresolved.
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.
Oh right, that does seem like a bug. If something is in
llvm.compiler.used
then it's likely that it is being referenced using its symbol name, in which case mergefuncs shouldn't rename it. I think we can work around this by removingunnamed_addr
from any symbols referenced byllvm.compiler.used
in a pass after all values are generated.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 is might be related to symbol export.
Functions that are referenced from inline asm in text form should be listed in
exported_symbols
. We currently don't have any special treatment of asm_sym there.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.
Could you give an example of what you have in mind?
As far as I know, for an inline assembly we do consider this aspect. For example, if a function with an inline assembly block might be code generated in a different crate (because it is marked inline or generic) and it references a non-generic function, the referenced function will be exported as necessary, etc. In what situation would it be necessary in the case of global asm?
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.
asm_sym is injected into the assembly as text, so when doing LTO/ThinLTO, LLVM would consider the symbol to be unused. This is different from
llvm.compiler.used
, which only marks the function to be used, not the symbol.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 see, but I think this is incorrect. Both
llvm.used
andllvm.compiler.used
are about symbols, not function per se. The LLVM reference seems quite clear about that. Those lists are also limited to named values for that reason.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 reread LLVM doc, you are correct about that. Some further digging shows that the issue is actually we generate an LLVM IR that marks the function as
internal
: https://godbolt.org/z/c4jPajT48 -- removing the internal linkage will make codegen correct. The symbol export actually doesn't affect the outcome directly -- but it is used indirectly from rustc_monomorphize to determine the linkage.