-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
r? @Amanieu |
// CHECK: call _RNvCsiubXh4Yz005_10global_asm6foobar | ||
global_asm!("call {}", sym foobar); | ||
// CHECK: _RNvCsiubXh4Yz005_10global_asm6foobar: | ||
fn foobar() { loop {} } |
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
and foobar
had been merged together by mergefunc
pass, invalidating the reference from global asm. Probably mergefunc
shouldn't touch symbols from llvm.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 removing unnamed_addr
from any symbols referenced by llvm.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.
This is different from
llvm.compiler.used
, which only marks the function to be used, not the symbol.
I see, but I think this is incorrect. Both llvm.used
and llvm.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.
The constants used in SymFn operands have FnDef type, so the type of the constant identifies the function.
@bors r+ |
📌 Commit e626634 has been approved by |
Collect function instance used in `global_asm!` sym operand The constants used in SymFn operands have FnDef type, so the type of the constant identifies the function. Fixes rust-lang#96623.
Collect function instance used in `global_asm!` sym operand The constants used in SymFn operands have FnDef type, so the type of the constant identifies the function. Fixes rust-lang#96623.
…laumeGomez Rollup of 10 pull requests Successful merges: - rust-lang#96557 (Allow inline consts to reference generic params) - rust-lang#96590 (rustdoc: when running a function-signature search, tweak the tab bar) - rust-lang#96650 (Collect function instance used in `global_asm!` sym operand) - rust-lang#96733 (turn `append_place_to_string` from recursion into iteration) - rust-lang#96748 (Fixes reexports in search) - rust-lang#96752 (Put the incompatible_closure_captures lint messages in alphabetical order) - rust-lang#96754 (rustdoc: ensure HTML/JS side implementors don't have dups) - rust-lang#96772 (Suggest fully qualified path with appropriate params) - rust-lang#96776 (Fix two minor issues in hir.rs) - rust-lang#96782 (a small `mirror_expr` cleanup) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The constants used in SymFn operands have FnDef type,
so the type of the constant identifies the function.
Fixes #96623.