vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.81k stars 2.17k forks source link

cant compile free standing type well can it #21934

Open trab0cch3tt0 opened 3 months ago

trab0cch3tt0 commented 3 months ago

V doctor:

V full version: V 0.4.6 f24abd7.736067d
OS: linux, "Artix Linux"
Processor: 12 cpus, 64bit, little endian, AMD Ryzen 5 5600H with Radeon Graphics

getwd: /backup/projects/vnostd
vexe: /usr/lib/vlang/v
vexe mtime: 2024-07-26 00:45:59

vroot: NOT writable, value: /usr/lib/vlang
VMODULES: OK, value: /home/user/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.45.2
Git vroot status: Error: fatal: not a git repository (or any of the parent directories): .git
.git/config present: false

CC version: cc (GCC) 14.1.1 20240720
thirdparty/tcc: N/A

What did you do? v -g -o vdbg cmd/v && vdbg main.v

@[export: '_start']
fn start() {
    message := 'Hello, World!\n'
    syscall_write(1, message.str, message.len)
    syscall_exit(0)
}

fn syscall_write(fd int, buf &char, count int) int {
    mut ret := 0
    asm x86_64 {
        mov rax, 1 // syscall number for sys_write
        mov rdi, fd
        mov rsi, buf
        mov rdx, count
        syscall
        mov ret, rax
    }
    return ret
}

fn syscall_exit(status int) {
    asm x86_64 {
        mov rax, 60
        mov rdi, status
        syscall
    }
}

What did you expect to see?

like some crazy 300b binary wuith no errors simple

What did you see instead?

==================
/tmp/v_1000/main.01J3P8DN6Z9NTZDXEZVPA2GEH5.tmp.c:13118: error: '_start' defined twice
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

trab0cch3tt0 commented 3 months ago

here more

/backup/projects/vnostd$ v -freestanding -o hello main.v -cg
/usr/lib/vlang/vlib/dlmalloc/dlmalloc.v:463:68: notice: ambiguous expression. use `()` to ensure correct order of operations
  461 |     } else {
  462 |         k := sizeof(usize) * 8 - 1 - usize_leading_zeros(x)
  463 |         return u32((k << 1) + (size >> (k + dlmalloc.tree_bin_shift - 1) & 1))
      |                                                                          ^
  464 |     }
  465 | }
/tmp/v_1000/hello.01J3P8CF66CKRREXQZ3KQC5P5G.tmp.c:7399: warning: pointer/integer mismatch in comparison
/tmp/v_1000/hello.01J3P8CF66CKRREXQZ3KQC5P5G.tmp.c:14741: error: asm constraint 7 ('r') could not be satisfied
trab0cch3tt0 commented 3 months ago

this seems like the output at which error


VV_LOCAL_SYMBOL u64 sys_call6(u64 scn, u64 arg1, u64 arg2, u64 arg3, u64 arg4, i64 arg5, u64 arg6) {
    u64 res = ((u64)(0U));
    __asm__ (
        "mov %[arg4], %%r10;"
        "mov %[arg5], %%r8;"
        "mov %[arg6], %%r9;"
        "syscall ;"
        : [res] "=a" (res)
        : [scn] "a" (scn),
        [arg1] "D" (arg1),
        [arg2] "S" (arg2),
        [arg3] "d" (arg3),
        [arg4] "r" (arg4),
        [arg5] "r" (arg5),
        [arg6] "r" (arg6)
        : "r10",
        "r8",
        "r9"
    );
    return res;
}```
felipensp commented 3 months ago

Error message related to asm inline are C compiler related. Try -cc gcc to use GCC whichs has better support for such.