Skip to content
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

Use freestanding mode, but encounter incompatible size_t redefinition error by C #23228

Open
PegasusPlusUS opened this issue Dec 21, 2024 · 6 comments
Labels
Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture.

Comments

@PegasusPlusUS
Copy link

PegasusPlusUS commented Dec 21, 2024

V doctor:

V full version: V 0.4.8 2ab1523
OS: windows, Microsoft Windows Server 2022 Standard v20348 64-bit
Processor: 8 cpus, 64bit, little endian, 

getwd: E:\Export\tinyos\ch01_bootsector\v
vexe: C:\Users\ping\scoop\apps\v\0.4.8\v.exe
vexe mtime: 2024-09-28 16:45:40

vroot: OK, value: C:\Users\ping\scoop\apps\v\0.4.8
VMODULES: OK, value: C:\Users\ping\.vmodules
VTMP: OK, value: C:\Users\ping\AppData\Local\Temp\2\v_0

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

CC version: Error: 'cc' is not recognized as an internal or external command,

operable program or batch file.


thirdparty/tcc: N/A

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

fn main() {
    message := "Hello, World!"

    for ch in message {
        asm x86 {
            mov ah, 0x0e
            mov al, ch
            int 0x10
        }
    }

    // Infinite loop to keep the program running
    for {}
}

What did you expect to see?

Compile OK

What did you see instead?

bootsector.v:4:9: warning: unused variable: `ch`
    2 |     message := "Hello, World!"
    3 | 
    4 |     for ch in message {
      |         ~~
    5 |         asm x86 {
    6 |             mov ah, 0x0e
C:/Users/ping/AppData/Local/Temp/2/v_0/bootsector.01JFM5TKDDTX2P0VENQFFRDHXB.tmp.c:7059: at print_backtrace_skipping_top_frames_tcc: Backtrace
C:/Users/ping/AppData/Local/Temp/2/v_0/bootsector.01JFM5TKDDTX2P0VENQFFRDHXB.tmp.c:7026: by print_backtrace_skipping_top_frames
C:/Users/ping/AppData/Local/Temp/2/v_0/bootsector.01JFM5TKDDTX2P0VENQFFRDHXB.tmp.c:7927: by unhandled_exception_handler
7ffe189fbfc2 : by ???
C:/Users/ping/AppData/Local/Temp/2/v_0/bootsector.01JFM5TKDDTX2P0VENQFFRDHXB.tmp.c:13479: at main__main: RUNTIME ERROR: invalid memory access
C:/Users/ping/AppData/Local/Temp/2/v_0/bootsector.01JFM5TKDDTX2P0VENQFFRDHXB.tmp.c:13523: by wmain
00467040 : by ???
004671a3 : by ???
7ffe18304cb0 : by ???

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.

Huly®: V_0.6-21662

@kbkpbot
Copy link
Contributor

kbkpbot commented Dec 21, 2024

fn main() {
    message := "Hello, World!"

    for ch in message {
        asm x86 {
            mov ah, 0x0e
            mov al, ch                     // ch is a x86 register, cx high part. not the var ch
            int 0x10
        }
    }

    // Infinite loop to keep the program running
    for {}
}

maybe fix to :

fn main() {
    message := "Hello, World!"

    for c in message {
        asm x86 {
            mov ah, 0x0e
            mov al, c
            int 0x10
           ; r (c) as c
        }
    }

    // Infinite loop to keep the program running
    for {}
}

BTW:

.text:0000000000417AEF                 int     10h             ; - VIDEO - WRITE CHARACTER AND ADVANCE CURSOR (TTY WRITE)
.text:0000000000417AEF                                         ; AL = character, BH = display page (alpha modes)
.text:0000000000417AEF                                         ; BL = foreground color (graphics modes)

@PegasusPlusUS
Copy link
Author

Now first warning is eliminated, the bug reported still occurs, I check the generated C, it seems if compile as -freestanding will cause incompatible size_t error.

@PegasusPlusUS
Copy link
Author

PegasusPlusUS commented Dec 21, 2024

v -gc none -freestanding -cg -o bootsector.asm bootsector.v
C:/Users/ping/AppData/Local/Temp/2/v_0/bootsector.asm.01JFNH47KAPKZYSHXHPWBW80GK.tmp.c:468: error: incompatible redefinition of 'size_t'
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 .
make: *** [Makefile:4: bootsector.asm] Error 1

@felipensp
Copy link
Member

image

I see no redifinition error.

@felipensp felipensp added Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture. labels Dec 21, 2024
@kbkpbot
Copy link
Contributor

kbkpbot commented Dec 22, 2024

   -freestanding
      Build the executable without dependency on libc.
      Supported only on `linux` targets currently.

V does not support -freestanding mode under windows yet.
Even remove the size_t definition from the cgen, it will cause other errors, because it try to use builtin/linux_bare, maybe someone can provide builtin/windows_bare ....

For test:
fix vlib/v/gen/c/cheaders.v,
comment out the line typedef long unsigned int size_t;

v self

then you can compile.

@PegasusPlusUS
Copy link
Author

PegasusPlusUS commented Dec 22, 2024

I see, thanks! I'll try to test on Linux to generate bare-metal code (As I already installed tinyc, i686-elf-gcc, I guess they can help cross-compile to bare-metal code on Windows also).

BTW, though -freestanding is not supported on Windows, I finally got my bootsector running on logic implemented in V at Windows, with the help of generating C code from V compiler, :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture.
Projects
None yet
Development

No branches or pull requests

3 participants