pull/2760/head
parent
1d460c4d49
commit
8d4ef822b6
|
@ -957,9 +957,9 @@ pub fn new_v(args[]string) &V {
|
|||
out_name_c = out_name.all_after(os.path_separator) + '_shared_lib.c'
|
||||
}
|
||||
$if !linux {
|
||||
if pref.is_bare {
|
||||
verror('-bare only works on Linux for now')
|
||||
}
|
||||
if pref.is_bare && !out_name.ends_with('.c') {
|
||||
verror('-bare only works on Linux for now')
|
||||
}
|
||||
}
|
||||
return &V{
|
||||
os: _os
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
.intel_syntax noprefix
|
||||
.text
|
||||
.globl _start, syscall5
|
||||
|
||||
_start:
|
||||
xor rbp,rbp
|
||||
pop rdi
|
||||
mov rsi,rsp
|
||||
and rsp,-16
|
||||
call main
|
||||
|
||||
mov rdi,rax /* syscall param 1 = rax (ret value of main) */
|
||||
mov rax,60 /* SYS_exit */
|
||||
syscall
|
||||
|
||||
ret /* should never be reached, but if the OS somehow fails
|
||||
to kill us, it will cause a segmentation fault */
|
||||
|
||||
syscall5:
|
||||
mov rax,rdi
|
||||
mov rdi,rsi
|
||||
mov rsi,rdx
|
||||
mov rdx,rcx
|
||||
mov r10,r8
|
||||
mov r8,r9
|
||||
syscall
|
||||
ret
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
fn syscall5(number, arg1, arg2, arg3, arg4, arg5 voidptr) voidptr
|
||||
|
||||
fn write(fd int, data voidptr, nbytes u64) int {
|
||||
return syscall5(
|
||||
1, // SYS_write
|
||||
fd,
|
||||
data,
|
||||
nbytes,
|
||||
0, // ignored
|
||||
0 // ignored
|
||||
)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
C.write(1, "hallo\n", 6)
|
||||
}
|
Loading…
Reference in New Issue