-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for global-asm support (RFC 1548) #35119
Comments
Don't take away naked functions!!!!!!!!!!!!!!!!!!! They are a crucial component of building operating systems in Rust. Without naked functions, it is impossible to do context switching without moving huge amounts of code into assembler. Converting such code to global_asm! is unnecessary, insecure, difficult to read and modify, and requires repeating code for each target. |
@jackpot51 more detailed examples would be great :) |
@jackpot51 but rest easy, I don't think we're in any hurry to make firm decisions here. :) |
@nikomatsakis They're used in anything from interrupt handler to context switches. I would cry for 10 years straight if you removed them. |
To make this concrete, here is a PR where I went from regular old All that setup code in |
Thanks @steveklabnik for showing the potential of |
Regarding having compile time constants and unmangled labels in it, would it possible to have separate procedural macro that did this? Something like If a general way like that wouldn't work then something like the way |
I do not see how any naked function is not trivially convertible to a Otherwise, I agree with Niko, that nobody is making any decisions anytime soon, but would like to add that seeing quality of naked function implementation, its future looks bleak. |
@nagisa: I agree with you on naked-functions-on-top-of- In particular, it relies on doing awful Duff's Device-like tricks, where asm that's syntactically inside a function is treated semantically as if it was global. If Rust ever grows a principled handling of inline asm, that sounds like an immense obstacle and/or footgun. |
On Fri, Jul 29, 2016 at 03:49:10PM -0700, eternaleye wrote:
To clarify: do you mean "simulating global asm using a dummy naked function is a hack"? |
In essence, yes - I feel using naked functions to simulate global asm is a hack, and one that could easily be broken by non-rustc parts of the compilation process to boot. |
I am in favor of this feature. My problem is that I need to use ARM EHABI directives inside assembly, however LLVM does not support them inside Of course, this is just one particular bug in LLVM (that I'm not going to fix, personally, I have better things to do). Even if it was fixed, however, I am sure there are other instances where assembly within a naked function does not behave in the same way as module-level assembly, and it would be unwise to assume that all problems related to those can be worked around. If they have to be fixed upstream, then there is at least a year of delay before the fix trickles down and the crate becomes usable on crates.io. |
btw, visitors from the future, I'm working on this. |
Implement global_asm!() (RFC 1548) This is a first attempt. ~~One (potential) problem I haven't solved is how to handle multiple usages of `global_asm!` in a module/crate. It looks like `LLVMSetModuleInlineAsm` overwrites module asm, and `LLVMAppendModuleInlineAsm` is not provided in LLVM C headers 😦~~ I can provide more detail as needed, but honestly, there's not a lot going on here. r? @eddyb CC @Amanieu @jackpot51 Tracking issue: rust-lang#35119
Implement global_asm!() (RFC 1548) This is a first attempt. ~~One (potential) problem I haven't solved is how to handle multiple usages of `global_asm!` in a module/crate. It looks like `LLVMSetModuleInlineAsm` overwrites module asm, and `LLVMAppendModuleInlineAsm` is not provided in LLVM C headers 😦~~ I can provide more detail as needed, but honestly, there's not a lot going on here. r? @eddyb CC @Amanieu @jackpot51 Tracking issue: rust-lang#35119
Implement global_asm!() (RFC 1548) This is a first attempt. ~~One (potential) problem I haven't solved is how to handle multiple usages of `global_asm!` in a module/crate. It looks like `LLVMSetModuleInlineAsm` overwrites module asm, and `LLVMAppendModuleInlineAsm` is not provided in LLVM C headers 😦~~ I can provide more detail as needed, but honestly, there's not a lot going on here. r? @eddyb CC @Amanieu @jackpot51 Tracking issue: rust-lang#35119
Implement global_asm!() (RFC 1548) This is a first attempt. ~~One (potential) problem I haven't solved is how to handle multiple usages of `global_asm!` in a module/crate. It looks like `LLVMSetModuleInlineAsm` overwrites module asm, and `LLVMAppendModuleInlineAsm` is not provided in LLVM C headers 😦~~ I can provide more detail as needed, but honestly, there's not a lot going on here. r? @eddyb CC @Amanieu @jackpot51 Tracking issue: rust-lang#35119
One other data point: I find myself still using a .S file and manually invoking the assembler and linker because I want to position certain sections of the binary at certain locations. This gives me the idea of turning global asm into a new attribute: #[cfg(target-arch=“x86-64”)]
#[asm(“arch/entry.S”, linker-args=“...”)] |
FWIW passing .S files to rustc seems like a good way to go about it, without introducing language features/complexity for such (arguably niche) situations. |
Is there any difference between having global_asm! and having rustc able to eat .S files. I think the issues with either one are the same, and that supporting either or both is probably the same work. (But I may be mistaken). Consequently why not support both. |
How (if at all) does this interact with inline ASM? |
It seems pretty orthogonal to me. IIUC, it uses a different LLVM feature altogether. I suppose one could define labels in a global asm and reference them from inline asm, though... |
This is very useful in operating system development. I may define global entry in producal macros: #[proc_macro]
pub fn boot_page_sv39(item: TokenStream) -> TokenStream {
println!("{:?}", item);
quote!(
#[repr(align(4096))]
#[repr(C)]
struct __BootPage([usize; 512]);
#[export_name = "_boot_page"]
static __BOOT_PAGE: __BootPage = __BootPage([0; 512]);
global_asm!("..."); // <- entry assembly code
).into()
} Which could be more convenient. |
Is it possible to generate position independent code with I tried #[cfg(target_arch = "x86_64")]
global_asm! {r#"
.global _start
_start:
mov %rdi, %rsp
call main
"#} However the #[no_mangle]
#[naked]
pub unsafe fn _start() {
// call here is pic
#[cfg(target_arch = "x86_64")]
asm!("mov rdi, rsp", "call main");
} |
Never mind. my actual issue was is that inline asm is using intel syntax, while #[cfg(target_arch = "x86_64")]
global_asm! {r#"
.intel_syntax noprefix
.global _start
_start:
mov rdi, rsp
call main
"#} |
It would be nice if |
Noticed the error reporting was suboptimal and filed #81751 (but there might not be anything to be done without changing LLVM). |
|
@dancrossnyc I've added a |
Thank you so much! |
I am trying to convert my att asm to intel (for use with .att_syntax
ljmp $0x8, $start_high So far i tried: Any ideas? PS: This is very x86 os specific and it could be an llvm problem. So this discussion may be the wrong place for that, sry if that's the case. |
Note: this doesn't address the question about Intel syntax for a long jmp, but if it's easier, |
I think the syntax is |
Well I like the intel syntax more, but I am considering it. Currently I'm switching syntax only for this instruction with
Unfortunately this also fails with an
|
Currently I am using |
Is there any documentation available on what assembler-flavor I think there should be better documentation of what assembler flavor is used and a link to additional documentation should be provided. So far I don't know if |
It always uses a GAS-like syntax with intel syntax on x86. This is done using LLVM's internal assembler and not by actually invoking GAS. The documentation is in the process of being added to the reference here. |
@Amanieu Is this the tracking issue being used for the current If the latter, we should close this in favor of wherever that's being tracked. |
|
Tracking issue for
global_asm!
macro rust-lang/rfcs#1548:Note that this is intended as a (particularly) experimental feature.
Feedback on its design is required, as well as comparisons with naked fns.
The text was updated successfully, but these errors were encountered: